Skip to content

Commit

Permalink
REF: compute fov_mask in eddy_postproc rather than Diffusion2Structural
Browse files Browse the repository at this point in the history
  • Loading branch information
Michiel Cottaar authored and glasserm committed Oct 29, 2019
1 parent 89e941b commit 43b290a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
10 changes: 4 additions & 6 deletions DiffusionPreprocessing/scripts/DiffusionToStructural.sh
Original file line number Diff line number Diff line change
Expand Up @@ -107,21 +107,19 @@ if [ ${GdcorrectionFlag} -eq 1 ]; then
${CARET7DIR}/wb_command -volume-dilate $DataDirectory/warped/data_warped.nii.gz $DilateDistance NEAREST $DataDirectory/warped/data_warped_dilated.nii.gz
${FSLDIR}/bin/applywarp --rel -i "$DataDirectory"/warped/data_warped_dilated -r "$T1wRestoreImage"_${DiffRes} -w "$WorkingDirectory"/grad_unwarp_diff2str --interp=spline -o "$T1wOutputDirectory"/data

#Create a mask representing voxels within the field of view for all volumes prior to dilation
${FSLDIR}/bin/fslmaths "$DataDirectory"/warped/data_warped -abs -Tmin -bin -fillh "$DataDirectory"/warped/fov_mask
# Transforms field of view mask to T1-weighted space
${FSLDIR}/bin/applywarp --rel -i "$DataDirectory"/warped/fov_mask -r "$T1wRestoreImage"_${DiffRes} -w "$WorkingDirectory"/grad_unwarp_diff2str --interp=trilinear -o "$T1wOutputDirectory"/fov_mask

#Now register the grad_dev tensor
# Now register the grad_dev tensor
${FSLDIR}/bin/vecreg -i "$DataDirectory"/grad_dev -o "$T1wOutputDirectory"/grad_dev -r "$T1wRestoreImage"_${DiffRes} -t "$WorkingDirectory"/diff2str.mat --interp=spline
${FSLDIR}/bin/fslmaths "$T1wOutputDirectory"/grad_dev -mas "$T1wOutputDirectory"/nodif_brain_mask_temp "$T1wOutputDirectory"/grad_dev #Mask-out values outside the brain
else
# Dilation outside of the field of view to minimise the effect of the hard field of view edge on the interpolation
${CARET7DIR}/wb_command -volume-dilate $DataDirectory/data.nii.gz $DilateDistance NEAREST $DataDirectory/data_dilated.nii.gz
#Register diffusion data to T1w space without considering gradient nonlinearities
# Register diffusion data to T1w space without considering gradient nonlinearities
${FSLDIR}/bin/flirt -in "$DataDirectory"/data_dilated -ref "$T1wRestoreImage"_${DiffRes} -applyxfm -init "$WorkingDirectory"/diff2str.mat -interp spline -out "$T1wOutputDirectory"/data

#Create a mask representing voxels within the field of view for all volumes prior to dilation
${FSLDIR}/bin/fslmaths "$DataDirectory"/data -abs -Tmin -bin -fillh "$DataDirectory"/fov_mask
# Transforms field of view mask to T1-weighted space
${FSLDIR}/bin/flirt -in "$DataDirectory"/fov_mask -ref "$T1wRestoreImage"_${DiffRes} -applyxfm -init "$WorkingDirectory"/diff2str.mat -interp trilinear -out "$T1wOutputDirectory"/fov_mask
fi

Expand Down
24 changes: 22 additions & 2 deletions DiffusionPreprocessing/scripts/eddy_postproc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,31 @@ else
fi
#fi


#Create a mask representing voxels within the field of view for all volumes prior to dilation
${FSLDIR}/bin/fslmaths ${datadir}/data -abs -Tmin -bin -fillh ${datadir}/fov_mask


if [ ! $GdCoeffs = "NONE" ] ; then
echo "Correcting for gradient nonlinearities"
# Note: "data_warped" is eddy-current and suspectibility distortion corrected (via 'eddy'), but prior to gradient distortion correction
# i.e., "data_posteddy_preGDC" would be another way to think of it
${FSLDIR}/bin/immv ${datadir}/data ${datadir}/data_warped
${globalscriptsdir}/GradientDistortionUnwarp.sh --workingdir="${datadir}" --coeffs="${GdCoeffs}" --in="${datadir}/data_warped" --out="${datadir}/data" --owarp="${datadir}/fullWarp"

# Dilation outside of the field of view to minimise the effect of the hard field of view edge on the interpolation
DiffRes=`${FSLDIR}/bin/fslval ${datadir}/data pixdim1`
DilateDistance=`echo "$DiffRes * 4" | bc` # Extrapolates the diffusion data up to 4 voxels outside of the FOV
${CARET7DIR}/wb_command -volume-dilate ${datadir}/warped/data_warped.nii.gz $DilateDistance NEAREST ${datadir}/warped/data_warped_dilated.nii.gz

# apply gradient distortion correction
${globalscriptsdir}/GradientDistortionUnwarp.sh --workingdir="${datadir}" --coeffs="${GdCoeffs}" --in="${datadir}/data_warped_dilated" --out="${datadir}/data" --owarp="${datadir}/fullWarp"

# Transform field of view mask (using conservative trilinear interolation with high threshold)
${FSLDIR}/bin/immv ${datadir}/fov_mask ${datadir}/fov_mask_warped
${FSLDIR}/bin/applywarp --rel --interp=trilinear -i ${datadir}/fov_mask_warped -r ${datadir}/fov_mask_warped -w ${datadir}/fullWarp -o ${datadir}/fov_mask
${FSLDIR}/bin/fslmaths ${datadir}/fov_mask -thr 0.999 -bin ${datadir}/fov_mask
# mask out any data outside the field of view
${FSLDIR}/bin/fslmaths ${datadir}/data -mas ${datadir}/fov_mask ${datadir}/data

echo "Computing gradient coil tensor to correct for gradient nonlinearities"
${FSLDIR}/bin/calc_grad_perc_dev --fullwarp=${datadir}/fullWarp -o ${datadir}/grad_dev
Expand All @@ -102,10 +120,12 @@ if [ ! $GdCoeffs = "NONE" ] ; then
${FSLDIR}/bin/imrm ${datadir}/grad_dev_?
${FSLDIR}/bin/imrm ${datadir}/trilinear
${FSLDIR}/bin/imrm ${datadir}/data_warped_vol1

${FSLDIR}/bin/imrm ${datadir}/data_warped_dilated

#Keep the original warped data and warp fields
mkdir -p ${datadir}/warped
${FSLDIR}/bin/immv ${datadir}/data_warped ${datadir}/warped
${FSLDIR}/bin/immv ${datadir}/fov_mask_warped ${datadir}/warped
${FSLDIR}/bin/immv ${datadir}/fullWarp ${datadir}/warped
${FSLDIR}/bin/immv ${datadir}/fullWarp_abs ${datadir}/warped
fi
Expand Down

0 comments on commit 43b290a

Please sign in to comment.