pnlbwh / pnlNipype

PNL pipeline for NIFTI images
Other
10 stars 15 forks source link

apply_topup on primaryMask and secondaryMask #58

Closed tashrifbillah closed 4 years ago

tashrifbillah commented 4 years ago

https://github.com/pnlbwh/pnlNipype/blob/master/scripts/fsl_topup_epi_eddy.py#L381

if both provided:
  applytopup[both]
else:
  bet[topupOutputMean]
tashrifbillah commented 4 years ago

WIP commit: https://github.com/pnlbwh/pnlNipype/commit/65c535aebb97c5ce8e2d98a84b75e51ee0756568

tashrifbillah commented 4 years ago

Omit applytopup entirely, introduce --iout with topup: https://github.com/pnlbwh/pnlNipype/blob/topup-mask/scripts/fsl_topup_epi_eddy.py#L361

tashrifbillah commented 4 years ago

When both masks are provided:

            if primaryMask and secondaryMask:
                # threshold the mean of corrected primary,secondary mask at 0.5 to obtain modified mask
                # use that mask for eddy_openmp
                primaryMaskCorrect = tmpdir / 'primary_mask_corrected.nii.gz'
                applytopup[f'--imain={primaryMask}',
                           f'--datain={self.acqparams_file}',
                           '--inindex=1',
                           f'--topup={topup_results}',
                           f'--out={primaryMaskCorrect}',
                           '--verbose',
                           '--method=jac',
                           '--interp=trilinear',
                           applytopup_params.split()] & FG

                secondaryMaskCorrect = tmpdir / 'secondary_mask_corrected.nii.gz'
                applytopup[f'--imain={secondaryMask}',
                           f'--datain={self.acqparams_file}',
                           '--inindex=2',
                           f'--topup={topup_results}',
                           f'--out={secondaryMaskCorrect}',
                           '--verbose',
                           '--method=jac',
                           '--interp=trilinear',
                           applytopup_params.split()] & FG

                fslmerge('-t', topupMask, primaryMaskCorrect, secondaryMaskCorrect)
                fslmaths[topupMask, '-Tmean', topupMask] & FG
                fslmaths[topupMask, '-thr', '0.5', topupMask, '-odt', 'char'] & FG

Otherwise,

                # apply bet on the mean of topup output to obtain modified mask
                # use that mask for eddy_openmp
                topupOutMean= tmpdir / 'topup_out_mean.nii.gz'
                fslmaths[--iout, '-Tmean', topupOutMean] & FG

                # toupOutMean is already masked, so -thr against 0
                fslmaths[topupOutMean, '-thr', '0', topupMask, '-odt', 'char'] & FG
tashrifbillah commented 4 years ago

QC outputs:

B0 PA corrected, primary_mask_corrected
B0 AP corrected, secondary_mask_corrected
topupOutMean, topupMask

Idea:

B0 PA corrected
B0 AP corrected

are in topupOut.

topupOutMean is always generated. primary_mask_corrected, secondary_mask_corrected are generated if both masks are provided.