User Tools

Site Tools


neuroimagen:notas_corregistro

Notas sobre corregistro de DTI

MNI → T1

[osotolongo@detritus facehbi]$ ANTS 3 -m CC[working/smc0177_t1_reoriented.nii.gz, ${FSLDIR}/data/standard/MNI152_T1_1mm.nii.gz, 1, 4] -r Gauss[0,3] -t Elast[1.5] -i 30x20x10 -o working/.tmp_smc0177/smc0177_dti_mni_t1.nii.gz
[osotolongo@detritus facehbi]$ WarpImageMultiTransform 3 /usr/local/fsl/data/standard/MNI152_T1_1mm.nii.gz working/.tmp_smc0177/mni_warped_tmp.nii.gz -R working/smc0177_t1_reoriented.nii.gz working/.tmp_smc0177/smc0177_dti_mni_t1Warp.nii.gz working/.tmp_smc0177/smc0177_dti_mni_t1Affine.txt

T1 → DTI

Sacar el B0,

[osotolongo@detritus facehbi]$ fslroi dti/smc0177s0020.nii.gz working/.tmp_smc0177/smc0177_b0.nii.gz 0 1 

Transformacion,

[osotolongo@detritus facehbi]$ ANTS 3 -m CC[working/.tmp_smc0177/smc0177_b0.nii.gz, working/smc0177_t1_reoriented.nii.gz, 1, 4] -r Gauss[0,3] -t Elast[1.5] -i 30x20x10 -o working/smc0177_dti_t1_b0.nii.gz
[osotolongo@detritus facehbi]$ WarpImageMultiTransform 3 working/smc0177_t1_reoriented.nii.gz working/.tmp_smc0177/smc0177_t1_to_b0.nii.gz -R working/.tmp_smc0177/smc0177_b0.nii.gz working/.tmp_smc0177/smc0177_dti_t1_b0Warp.nii.gz working/.tmp_smc0177/smc0177_dti_t1_b0Affine.txt

Aqui esta el problema , el T1 no se puede transformar correctamente al B0. Hay que dar una vuelta mas aqui.

Vamos a intentar registrar el DTI a T1 con epi_reg e invertir la transformación, 1)

[osotolongo@detritus facehbi]$ ${FSLDIR}/bin/epi_reg --epi=working/smc0177_data.nii.gz --t1=working/smc0177_t1_reoriented --t1brain=working/smc0177_t1_reoriented_brain --out=working/smc0177_tmp_diff2std
[osotolongo@detritus facehbi]$ convert_xfm -omat working/smc0177_tmp_std2diff.mat -inverse working/smc0177_tmp_diff2std.mat
[osotolongo@detritus facehbi]$ flirt -in working/smc0177_t1_reoriented.nii.gz -ref working/.tmp_smc0177/smc0177_b0.nii.gz -out working/smc0177_t12b0 -init working/smc0177_tmp_std2diff.mat -applyxfm

EH! esto queda mucho mejor. A ver si se puede mejorar mas,

[osotolongo@detritus facehbi]$ ANTS 3 -m CC[working/.tmp_smc0177/smc0177_b0.nii.gz, working/smc0177_t12b0.nii.gz, 1, 4] -r Gauss[0,3] -t Elast[1.5] -i 30x20x10 -o working/smc0177_dti_t1_b0.nii.gz
[osotolongo@detritus facehbi]$ WarpImageMultiTransform 3 working/smc0177_t12b0.nii.gz working/.tmp_smc0177/smc0177_t1_to_b0.nii.gz -R working/.tmp_smc0177/smc0177_b0.nii.gz working/.tmp_smc0177/smc0177_dti_t1_b0Warp.nii.gz working/.tmp_smc0177/smc0177_dti_t1_b0Affine.txt

AArrgH! ANTs falla al hacer la transformacion. La alternativa puede ser mover todo al T1 que es la imagen con mas informacion y calcular los valores de FA en el espacio nativo del T1

A ver que pasa si hago el warp al reves, del DTI al T1,

[osotolongo@detritus facehbi]$ ANTS 3 -m CC[working/smc0177_t1_reoriented.nii.gz, working/.tmp_smc0177/smc0177_b0.nii.gz, 1, 4] -r Gauss[0,3] -t Elast[1.5] -i 30x20x10 -o working/smc0177_t1_dti_warped_one.nii.gz
[osotolongo@detritus facehbi]$ WarpImageMultiTransform 3 working/.tmp_smc0177/smc0177_b0.nii.gz working/smc0177_t1_to_b0.nii.gz -R working/smc0177_t1_reoriented.nii.gz working/smc0177_t1_dti_warped_oneWarp.nii.gz working/smc0177_t1_dti_warped_oneAffine.txt

un desastre!

Vamos a intentar usando primero epi_reg,

[osotolongo@detritus facehbi]$ ${FSLDIR}/bin/epi_reg --epi=working/smc0177_data.nii.gz --t1=working/smc0177_t1_reoriented --t1brain=working/smc0177_t1_reoriented_brain --out=working/smc0177_tmp_diff2std
[osotolongo@detritus facehbi]$ flirt -in working/.tmp_smc0177/smc0177_b0.nii.gz -ref working/smc0177_t1_reoriented.nii.gz -out working/smc0177_tmp_diff2std.nii.gz -init working/smc0177_tmp_diff2std.mat -applyxfm

El B0 queda bastante bien para ser una transformacion lineal, cualquiera diria que con un empujocito mas ya queda OK.

[osotolongo@detritus facehbi]$ ANTS 3 -m CC[working/smc0177_t1_reoriented.nii.gz, working/smc0177_tmp_diff2std.nii.gz, 1, 4] -r Gauss[0,3] -t Elast[1.5] -i 30x20x10 -o working/smc0177_t1_dti_warped_two.nii.gz
[osotolongo@detritus facehbi]$ WarpImageMultiTransform 3 working/smc0177_tmp_diff2std.nii.gz working/smc0177_b0_to_t1.nii.gz -R working/smc0177_t1_reoriented.nii.gz working/smc0177_t1_dti_warped_twoWarp.nii.gz working/smc0177_t1_dti_warped_twoAffine.txt

Pero no!. ANTs no hace caso de la imagen inicial, solo intenta cualquier tipo de transformacion que encaje el B0 en el T1. Este approach es tan malo como el anterior.

A ver que pasa con un enfoque pure FSL.

[osotolongo@detritus facehbi]$ fnirt --in=working/.tmp_smc0177/smc0177_b0.nii.gz --aff=working/smc0177_tmp_diff2std.mat --cout=working/smc0177_tmp_nonlinear_diff2std --ref=working/smc0177_t1_reoriented.nii.gz
[osotolongo@detritus facehbi]$ applywarp -r working/smc0177_t1_reoriented.nii.gz -i working/.tmp_smc0177/smc0177_b0.nii.gz -w working/smc0177_tmp_nonlinear_diff2std -o working/smc0177_dif2std_warped

m( Desastrozo.

DTI → T1

La mejor opcion parece ser un corregstro lineal del DTi a espacio nativo T1, usando epi_reg, y medir en el espacio T1.

[osotolongo@detritus facehbi]$ flirt -ref working/smc0177_t1_reoriented.nii.gz -in working/.tmp_smc0177/smc0177_b0.nii.gz -out working/smc0177_b02t1 -init working/smc0177_tmp_diff2std.mat -applyxfm

Todas las transformaciones al espacio T1 parecen funcionar apropiadamente. Se pueden pasar los atlas a espacio T1 y la imagen FA a espacio T1.

No obstante, al hacer lo mismo con los atlas se puede ver que la cosa no funciona OK. Quedan demasiado desplazados.

DTI → MNI

La mejor opcion parece ser el protocolo antiguo,

[osotolongo@detritus facehbi]$ flirt -ref /usr/local/fsl/data/standard/FMRIB58_FA_1mm.nii.gz -in working/smc0177_dti_FA.nii.gz -omat working/smc0177_dti_affine.mat
[osotolongo@detritus facehbi]$ fnirt --in=working/smc0177_dti_FA.nii.gz --aff=working/smc0177_dti_affine.mat --cout=working/smc0177_dti_warp --config=FA_2_FMRIB58_1mm
[osotolongo@detritus facehbi]$ applywarp --ref=/usr/local/fsl/data/standard/FMRIB58_FA_1mm.nii.gz --in=working/smc0177_dti_FA.nii.gz --warp=working/smc0177_dti_warp --out=working/smc0177_fa_std

Lo que puedo hacer es llevar el B0 a espacio MNI con esta info, de ahi al T1 sin problemas,recortar el T1 segun el tamaño del B0 que me quede y registrar el B0 con ANTs a un T1 recortado,

[osotolongo@detritus facehbi]$ applywarp --ref=/usr/local/fsl/data/standard/MNI152_T1_1mm.nii.gz --in=working/smc0177_dti_b0 --warp=working/smc0177_dti_warp --out=working/smc0177_b0_std
[osotolongo@detritus facehbi]$ fslmaths working/smc0177_b0_std -bin working/smc0177_b0_std_mask
[osotolongo@detritus facehbi]$ fslmaths /usr/local/fsl/data/standard/MNI152_T1_1mm.nii.gz -mas working/smc0177_b0_std_mask.nii.gz working/smc0177_mni_masked
[osotolongo@detritus facehbi]$ WarpImageMultiTransform 3 working/smc0177_mni_masked.nii.gz working/.tmp_smc0177/mni_mask_warped_tmp.nii.gz -R working/smc0177_t1_reoriented.nii.gz working/.tmp_smc0177/smc0177_dti_mni_t1Warp.nii.gz working/.tmp_smc0177/smc0177_dti_mni_t1Affine.txt
[osotolongo@detritus facehbi]$ fslmaths working/smc0177_t1_reoriented.nii.gz -mas working/.tmp_smc0177/mni_mask_warped_tmp.nii.gz working/.tmp_smc0177/t1_mask_warped_tmp.nii.gz
[osotolongo@detritus facehbi]$ ANTS 3 -m CC[working/.tmp_smc0177/t1_mask_warped_tmp.nii.gz, working/.tmp_smc0177/smc0177_b0.nii.gz, 1, 4] -r Gauss[0,3] -t Elast[1.5] -i 30x20x10 -o working/smc0177_t1_dti_warped.nii.gz
[osotolongo@detritus facehbi]$ WarpImageMultiTransform 3 working/.tmp_smc0177/smc0177_b0.nii.gz working/smc0177_b0_to_t1.nii.gz -R working/smc0177_t1_reoriented.nii.gz working/smc0177_t1_dti_warpedWarp.nii.gz working/smc0177_t1_dti_warpedAffine.txt

intentando guardar la transformacion inversa

info aqui: https://github.com/ANTsX/ANTs/wiki/Forward-and-inverse-warps-for-warping-images,-pointsets-and-Jacobians

Hay un problema con el procesamientoen espacio T1. Aunque las metricas usuales de FA y/o MD pueden calcularse sin problemas, la tractografia ha de hacerse en espacio DTI. por lo que las mascaras han de llevarse de espacio MNI a espacio nativo T1 a espacio nativo DTI. Y aqui tenemos un problema pues no hemos logrado obtener esta transformatcion adecuadamente.

Voy a intentar cambiar la transformacion de ANTs, utilizando los scripts de ANTs. Intentare la mas sencilla primero.

[osotolongo@detritus facehbi]$ antsRegistrationSyNQuick.sh -d 3 -f working/.tmp_smc0177/t1_mask_warped_tmp.nii.gz -m working/.tmp_smc0177/smc0177_b0.nii.gz -o working/smc0177_t1_dti_warped_quick -t s
 
--------------------------------------------------------------------------------------
 Mapping parameters
--------------------------------------------------------------------------------------
 ANTSPATH is /nas/usr/local/opt/bin/ants/bin
 
 Dimensionality:           3
 Output name prefix:       working/smc0177_t1_dti_warped_quick
 Fixed images:             working/.tmp_smc0177/t1_mask_warped_tmp.nii.gz
 Moving images:            working/.tmp_smc0177/smc0177_b0.nii.gz
 Mask images:
 Initial transforms:
 Number of threads:        1
 Spline distance:          26
 Transform type:           s
 MI histogram bins:        32
 Precision:                d
 Use histogram matching    0
======================================================================================
 antsRegistration call:
--------------------------------------------------------------------------------------
/nas/usr/local/opt/bin/ants/bin/antsRegistration --verbose 1 --dimensionality 3 --float 0 --collapse-output-transforms 1 --output [ working/smc0177_t1_dti_warped_quick,working/smc0177_t1_dti_warped_quickWarped.nii.gz,working/smc0177_t1_dti_warped_quickInverseWarped.nii.gz ] --interpolation Linear --use-histogram-matching 0 --winsorize-image-intensities [ 0.005,0.995 ] --initial-moving-transform [ working/.tmp_smc0177/t1_mask_warped_tmp.nii.gz,working/.tmp_smc0177/smc0177_b0.nii.gz,1 ] --transform Rigid[ 0.1 ] --metric MI[ working/.tmp_smc0177/t1_mask_warped_tmp.nii.gz,working/.tmp_smc0177/smc0177_b0.nii.gz,1,32,Regular,0.25 ] --convergence [ 1000x500x250x0,1e-6,10 ] --shrink-factors 8x4x2x1 --smoothing-sigmas 3x2x1x0vox --transform Affine[ 0.1 ] --metric MI[ working/.tmp_smc0177/t1_mask_warped_tmp.nii.gz,working/.tmp_smc0177/smc0177_b0.nii.gz,1,32,Regular,0.25 ] --convergence [ 1000x500x250x0,1e-6,10 ] --shrink-factors 8x4x2x1 --smoothing-sigmas 3x2x1x0vox --transform SyN[ 0.1,3,0 ] --metric MI[ working/.tmp_smc0177/t1_mask_warped_tmp.nii.gz,working/.tmp_smc0177/smc0177_b0.nii.gz,1,32] --convergence [ 100x70x50x0,1e-6,10 ] --shrink-factors 8x4x2x1 --smoothing-sigmas 3x2x1x0vox
--------------------------------------------------------------------------------------
All_Command_lines_OK
 
.....

El script nos da unas opciones de input muy simples :-) y ademas muestra cual seria el call de antsRegistration apropiado 8-) . en caso de necesidad podria modificarse esta linea y ejecutarla directamente.

Los archivos de output contienen las transformaciones directas e inversas,

[osotolongo@detritus facehbi]$ ls working/smc0177_t1_dti_warped_quick*
working/smc0177_t1_dti_warped_quick0GenericAffine.mat   working/smc0177_t1_dti_warped_quick1Warp.nii.gz          working/smc0177_t1_dti_warped_quickWarped.nii.gz
working/smc0177_t1_dti_warped_quick1InverseWarp.nii.gz  working/smc0177_t1_dti_warped_quickInverseWarped.nii.gz

Para aplicar la transformacion directa,

[osotolongo@detritus facehbi]$ antsApplyTransforms -d 3 -i working/.tmp_smc0177/smc0177_b0.nii.gz -r working/.tmp_smc0177/t1_mask_warped_tmp.nii.gz -t working/smc0177_t1_dti_warped_quick1Warp.nii.gz -t working/smc0177_t1_dti_warped_quick0GenericAffine.mat -o working/smc0177_b0_to_t1_quick.nii.gz

o

[osotolongo@detritus facehbi]$ antsApplyTransforms -d 3 -i working/.tmp_smc0177/smc0177_b0.nii.gz -r working/smc0177_t1_reoriented.nii.gz -t working/smc0177_t1_dti_warped_quick1Warp.nii.gz -t working/smc0177_t1_dti_warped_quick0GenericAffine.mat -o working/smc0177_b0_to_t1_quick.nii.gz

que funcionan mas o menos igual. Existe una ligera deformacion en la parte superior por lo que hay que explorar las opciones del registro para mejorarlo. Voy a intentat quitar el quick y usar el histogram matching.

[osotolongo@detritus facehbi]$ antsRegistrationSyN.sh -d 3 -f working/.tmp_smc0177/t1_mask_warped_tmp.nii.gz -m working/.tmp_smc0177/smc0177_b0.nii.gz -o working/smc0177_t1_dti_warped_quick -t s -j 1
 
--------------------------------------------------------------------------------------
 Mapping parameters
--------------------------------------------------------------------------------------
 ANTSPATH is /nas/usr/local/opt/bin/ants/bin
 
 Dimensionality:           3
 Output name prefix:       working/smc0177_t1_dti_warped_quick
 Fixed images:             working/.tmp_smc0177/t1_mask_warped_tmp.nii.gz
 Moving images:            working/.tmp_smc0177/smc0177_b0.nii.gz
 Mask images:
 Initial transforms:
 Number of threads:        1
 Spline distance:          26
 Transform type:           s
 CC radius:                4
 Precision:                d
 Use histogram matching    1
======================================================================================
 antsRegistration call:
--------------------------------------------------------------------------------------
/nas/usr/local/opt/bin/ants/bin/antsRegistration --verbose 1 --dimensionality 3 --float 0 --collapse-output-transforms 1 --output [ working/smc0177_t1_dti_warped_quick,working/smc0177_t
--------------------------------------------------------------------------------------
 Mapping parameters
--------------------------------------------------------------------------------------
 ANTSPATH is /nas/usr/local/opt/bin/ants/bin
 
 Dimensionality:           3
 Output name prefix:       working/smc0177_t1_dti_warped_quick
 Fixed images:             working/.tmp_smc0177/t1_mask_warped_tmp.nii.gz
 Moving images:            working/.tmp_smc0177/smc0177_b0.nii.gz
 Mask images:
 Initial transforms:
 Number of threads:        1
 Spline distance:          26
 Transform type:           s
 CC radius:                4
 Precision:                d
 Use histogram matching    1
======================================================================================
 antsRegistration call:
--------------------------------------------------------------------------------------
/nas/usr/local/opt/bin/ants/bin/antsRegistration --verbose 1 --dimensionality 3 --float 0 --collapse-output-transforms 1 --output [ working/smc0177_t1_dti_warped_quick,working/smc0177_t1_dti_warped_quickWarped.nii.gz,working/smc0177_t1_dti_warped_quickInverseWarped.nii.gz ] --interpolation Linear --use-histogram-matching 1 --winsorize-image-intensities [ 0.005,0.995 ] --initial-moving-transform [ working/.tmp_smc0177/t1_mask_warped_tmp.nii.gz,working/.tmp_smc0177/smc0177_b0.nii.gz,1 ] --transform Rigid[ 0.1 ] --metric MI[ working/.tmp_smc0177/t1_mask_warped_tmp.nii.gz,working/.tmp_smc0177/smc0177_b0.nii.gz,1,32,Regular,0.25 ] --convergence [ 1000x500x250x100,1e-6,10 ] --shrink-factors 8x4x2x1 --smoothing-sigmas 3x2x1x0vox --transform Affine[ 0.1 ] --metric MI[ working/.tmp_smc0177/t1_mask_warped_tmp.nii.gz,working/.tmp_smc0177/smc0177_b0.nii.gz,1,32,Regular,0.25 ] --convergence [ 1000x500x250x100,1e-6,10 ] --shrink-factors 8x4x2x1 --smoothing-sigmas 3x2x1x0vox --transform SyN[ 0.1,3,0 ] --metric CC[ working/.tmp_smc0177/t1_mask_warped_tmp.nii.gz,working/.tmp_smc0177/smc0177_b0.nii.gz,1,4 ] --convergence [ 100x70x50x20,1e-6,10 ] --shrink-factors 8x4x2x1 --smoothing-sigmas 3x2x1x0vox
--------------------------------------------------------------------------------------
All_Command_lines_OK
1_dti_warped_quickWarped.nii.gz,working/smc0177_t1_dti_warped_quickInverseWarped.nii.gz ] --interpolation Linear --use-histogram-matching 1 --winsorize-image-intensities [ 0.005,0.995 ] --initial-moving-transform [ working/.tmp_smc0177/t1_mask_warped_tmp.nii.gz,working/.tmp_smc0177/smc0177_b0.nii.gz,1 ] --transform Rigid[ 0.1 ] --metric MI[ working/.tmp_smc0177/t1_mask_warped_tmp.nii.gz,working/.tmp_smc0177/smc0177_b0.nii.gz,1,32,Regular,0.25 ] --convergence [ 1000x500x250x100,1e-6,10 ] --shrink-factors 8x4x2x1 --smoothing-sigmas 3x2x1x0vox --transform Affine[ 0.1 ] --metric MI[ working/.tmp_smc0177/t1_mask_warped_tmp.nii.gz,working/.tmp_smc0177/smc0177_b0.nii.gz,1,32,Regular,0.25 ] --convergence [ 1000x500x250x100,1e-6,10 ] --shrink-factors 8x4x2x1 --smoothing-sigmas 3x2x1x0vox --transform SyN[ 0.1,3,0 ] --metric CC[ working/.tmp_smc0177/t1_mask_warped_tmp.nii.gz,working/.tmp_smc0177/smc0177_b0.nii.gz,1,4 ] --convergence [ 100x70x50x20,1e-6,10 ] --shrink-factors 8x4x2x1 --smoothing-sigmas 3x2x1x0vox
--------------------------------------------------------------------------------------
All_Command_lines_OK
 
 
[osotolongo@detritus facehbi]$ antsApplyTransforms -d 3 -i working/.tmp_smc0177/smc0177_b0.nii.gz -r working/smc0177_t1_reoriented.nii.gz -t working/smc0177_t1_dti_warped_quick1Warp.nii.gz -t working/smc0177_t1_dti_warped_quick0GenericAffine.mat -o working/smc0177_b0_to_t1_quick.nii.gz
[osotolongo@detritus facehbi]$ ls -l working/smc0177_t1_dti_warped_quick*
-rw-rw---- 1 osotolongo imagen       193 Aug 14 21:19 working/smc0177_t1_dti_warped_quick0GenericAffine.mat
-rw-rw---- 1 osotolongo imagen 235516784 Aug 14 21:20 working/smc0177_t1_dti_warped_quick1InverseWarp.nii.gz
-rw-rw---- 1 osotolongo imagen 234821906 Aug 14 21:20 working/smc0177_t1_dti_warped_quick1Warp.nii.gz
-rw-rw---- 1 osotolongo imagen   1718930 Aug 14 21:20 working/smc0177_t1_dti_warped_quickInverseWarped.nii.gz
-rw-rw---- 1 osotolongo imagen  37764628 Aug 14 21:20 working/smc0177_t1_dti_warped_quickWarped.nii.gz

Mucho mejor. Me voy a quear con esto. Ahora tengo que aplicar la inversa a ver que pasa.

[osotolongo@detritus facehbi]$ antsApplyTransforms -d 3 -i working/smc0177_t1_reoriented.nii.gz -r working/.tmp_smc0177/smc0177_b0.nii.gz -t [working/smc0177_t1_dti_warped_quick0GenericAffine.mat, 1] -t working/smc0177_t1_dti_warped_quick1InverseWarp.nii.gz -o working/smc0177_t1_to_b0_quick.nii.gz

Este es de lejos el mejor registro en espacio nativo DTI que hemos conseguido hasta ahora asi que me voy a quedar con este. Hay que cambiar todos los scripts para utilizar este metodo. m(

La posibilidad de deformacion en el ajuste no parece ser necesaria para transformar el espacio nativo DTI al espacio nativo T1. A fin de cuentas es el mismo cerebro por lo que con una transformacion mas sencilla deberia, no solo bastar, sino hacer bien.

[osotolongo@detritus facehbi]$ antsRegistrationSyN.sh -d 3 -f working/.tmp_smc0177/t1_mask_warped_tmp.nii.gz -m working/.tmp_smc0177/smc0177_b0.nii.gz -o working/smc0177_t1_dti_warped_quick -t a -j 1
[osotolongo@detritus facehbi]$ antsApplyTransforms -d 3 -i working/.tmp_smc0177/smc0177_b0.nii.gz -r working/smc0177_t1_reoriented.nii.gz -t working/smc0177_t1_dti_warped_quick0GenericAffine.mat -o working/smc0177_b0_to_t1_quick.nii.gz

y la inversa, (esta queda en working/smc0177_t1_dti_warped_quickInverseWarped.nii.gz)

Nota: solo cambia el parametro -t pero es mucho mas rapido ya que ahora la transformacion es a: rigid + affine (2 stages) en lugar de s: rigid + affine + deformable syn (3 stages). Ademas,la transformacion no tiene ningun Warp, solo la matriz de Affine.

1)
Se supone que antes hice algo asi,
$FSLDIR/bin/bet ${out}/${b_in}_t1_reoriented ${out}/${b_in}_t1_reoriented_brain
neuroimagen/notas_corregistro.txt · Last modified: 2020/08/04 10:58 (external edit)