Skip to content

Commit

Permalink
Merge pull request #105 from khanlab/cropseg_patch
Browse files Browse the repository at this point in the history
Cropseg patch
  • Loading branch information
jordandekraker authored Sep 13, 2021
2 parents cde2b5c + 8881178 commit efea3e0
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 7 deletions.
8 changes: 4 additions & 4 deletions docs/tutorials/specializedScans.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Specialized scans
=====================
This tutorial will cover how HippUnfold can be applied to nonstandard data including ex-vivo scans, super high resolution data (eg. <0.3mm isotropic), non-MRI 3D imaging data, or scans where a corresponding whole-brain T1w image is not available.
This tutorial will cover how HippUnfold can be applied to non-standard data including ex-vivo scans, super-high resolution data (eg. <0.3mm isotropic), non-MRI 3D imaging data, or scans where a corresponding whole-brain T1w image is not available.

We will show how the available flags can be adapted for these use-cases with several worked examples.

Expand All @@ -13,16 +13,16 @@ This will require manual segmentation of hippocampal grey matter, SRLM, and neig

Here is an example of what the input directory might look like::

PATH_TO_EXVIVO_DIR/
exvivo/
└── sub-001/
├── sub-001_hemi-R_desc-hippo_T2w.nii.gz
└── sub-001_hemi-R_desc-hippo_dseg.nii.gz

This can be unfolded with the command::

hippunfold PATH_TO_EXVIVO_DIR PATH_TO_OUTPUT_DIR participant --modality cropseg --hemi R --skip_inject_template_labels
hippunfold - PATH_TO_OUTPUT_DIR participant --modality cropseg --path_cropseg exvivo/sub-{subject}/sub-{subject}_hemi-{hemi}_desc-hippo_dseg.nii.gz --hemi R --skip_inject_template_labels
Explanation: ``--modality cropseg`` informs HippUnfold that the input manual segmentation should not be resampled and UNet does not need to be run. Output files will be named with ``space-corobl`` because HippUnfold is coded to effectively treat all files as already being in this space. We need the ``--hemi R`` to prevent HippUnfold looking for both hemispheres. Finally, because this segmentation was performed manually on very high resolution data, we can optionally consider skipping the template shape injection step with ``--skip_inject_template_labels``. Template shape injection can fix minor errors in segmentation from UNet or from an imperfect manual rater, at the cost of smoothing out some details of the hippocampus due to the fact that it uses deformable registration with inherent smoothness contraints.
Explanation: ``--modality cropseg`` informs HippUnfold that the input manual segmentation should not be resampled and UNet does not need to be run. Because of a limitation in bids parsing for the `hemi` entity, we need to use the generic path input, `--path_cropseg` in this case, making sure we use the `{subject}` and `{hemi}` wildcards in the filename. Output files will be named with ``space-corobl`` because HippUnfold is coded to effectively treat all files as already being in this space. We need the ``--hemi R`` to prevent HippUnfold looking for both hemispheres. Finally, because this segmentation was performed manually on very high resolution data, we can optionally consider skipping the template shape injection step with ``--skip_inject_template_labels``. Template shape injection can fix minor errors in segmentation from UNet or from an imperfect manual rater, at the cost of smoothing out some details of the hippocampus due to the fact that it uses deformable registration with inherent smoothness contraints.

Note that because we are not resampling to the CITI168 template or using UNet, the T2w image in this example is effectively not being used at all. Instead, the provided manual segmentation makes up the basis for unfolding.

Expand Down
6 changes: 6 additions & 0 deletions hippunfold/tests/hippunfold_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,9 @@ def test_dry_runs(script_runner):
ret = script_runner.run('hippunfold', '-',output_dir,'participant','-np','--modality','cropseg','--path_cropseg','test_data/data_cropseg/sub-{subject}_hemi-{hemi}_dseg.nii.gz')
assert ret.success

#cropseg with single hemi -- requires user to specify --hemi
with tempfile.TemporaryDirectory() as output_dir:
ret = script_runner.run('hippunfold', '-',output_dir,'participant','-np','--modality','cropseg','--path_cropseg','test_data/data_cropseg_1hemi/sub-{subject}_hemi-{hemi}_dseg.nii.gz','--hemi','L')
assert ret.success


1 change: 1 addition & 0 deletions hippunfold/workflow/Snakefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ wildcard_constraints:
hemi='[a-zA-Z0-9]+',
surfname='[a-zA-Z0-9]+',
modality='[a-zA-Z0-9]+',
density='[a-zA-Z0-9]+',


include: 'rules/common.smk'
Expand Down
4 changes: 2 additions & 2 deletions hippunfold/workflow/rules/autotop.smk
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ rule prep_equivolume_coords:

rule equivolume_coords:
input:
outerbin = bids(root='work',datatype='seg_{modality}',dir='{dir}',desc='all',suffix='mask.nii.gz',space='corobl',hemi='{hemi,Lflip|R}', **config['subj_wildcards']),
innerbin = bids(root='work',datatype='seg_{modality}',dir='{dir}',desc='SRLM',suffix='mask.nii.gz',space='corobl',hemi='{hemi,Lflip|R}', **config['subj_wildcards']),
outerbin = bids(root='work',datatype='seg_{modality}',dir='{dir}',desc='all',suffix='mask.nii.gz',space='corobl',hemi='{hemi}', **config['subj_wildcards']),
innerbin = bids(root='work',datatype='seg_{modality}',dir='{dir}',desc='SRLM',suffix='mask.nii.gz',space='corobl',hemi='{hemi}', **config['subj_wildcards']),
params:
src_labels = lambda wildcards: config['laplace_labels'][wildcards.dir]['src'],
output:
Expand Down
2 changes: 1 addition & 1 deletion hippunfold/workflow/rules/preproc_cropseg.smk
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
rule import_cropseg:
input: config['input_path']['cropseg']
output:
nii = bids(root='work',datatype='anat',**config['subj_wildcards'],suffix='dseg.nii.gz',desc='cropped',space='corobl',hemi='{hemi}'),
nii = bids(root='work',datatype='anat',**config['subj_wildcards'],suffix='dseg.nii.gz',desc='cropped',space='corobl',hemi='{hemi,L|R}'),
group: 'subj'
shell: 'cp {input} {output}'

Expand Down
Empty file.

0 comments on commit efea3e0

Please sign in to comment.