Skip to content

Commit

Permalink
manualseg resampling in-place without transformation (#346)
Browse files Browse the repository at this point in the history
* add option to resample in-place, without transforming to template corobl or assuming any kind of registration already
* add cropping tight (with 5 vox pad) to dseg
  • Loading branch information
akhanf authored Jan 28, 2025
1 parent 552420f commit 56fbe80
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
6 changes: 6 additions & 0 deletions hippunfold/config/snakebids.yml
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ parse_args:
help: 'Sets the bounding box size for the crop native (e.g. cropT1w space). Make this larger if your hippocampi in crop{T1w,T2w} space are getting cut-off. This must be in voxels (vox) not millimeters (mm). (default: %(default)s)'
default: '256x256x256vox'

--resample_manualseg:
help: 'Resample the manual segmentation (for --modality manualseg), keeping the bounding box the same, but changing the number of voxels in the image. This can be specified as voxels ("300x300x300"), or a percentage ("20%%") or percentage in each direction ("20x20x40%%"). Note: the segmentation will always be subsequently cropped around the segmentation, with a padding of 5 voxels. (default: %(default)s)'
default: null


--atlas:
choices:
- 'multihist7'
Expand Down Expand Up @@ -688,3 +693,4 @@ root: results
workdir: null
use_template_seg: False
template_seg_smoothing_factor: 2
resample_manualseg: null
16 changes: 6 additions & 10 deletions hippunfold/workflow/rules/preproc_manualseg.smk
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@

rule import_manualseg_to_corobl:
rule import_manualseg_with_resample:
input:
in_img=partial(get_single_bids_input, component="manualseg"),
template_dir=Path(download_dir) / "template" / config["template"],
params:
std_to_cor=lambda wildcards, input: Path(input.template_dir)
/ config["template_files"][config["template"]]["xfm_corobl"].format(
**wildcards
),
ref=lambda wildcards, input: Path(input.template_dir)
/ config["template_files"][config["template"]]["crop_ref"].format(**wildcards),
resample_cmd=""
if config["resample_manualseg"] == None
else "-resample {res}".format(res=config["resample_manualseg"]),
crop_cmd="-trim 5vox", #leave 5 voxel padding
output:
nii=bids(
root=work,
Expand All @@ -24,5 +21,4 @@ rule import_manualseg_to_corobl:
group:
"subj"
shell:
"ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADS={threads} "
"antsApplyTransforms -d 3 --interpolation MultiLabel -i {input.in_img} -o {output.nii} -r {params.ref} -t {params.std_to_cor}"
"c3d {input} -int 0 {params.resample_cmd} {params.crop_cmd} -o {output}"

0 comments on commit 56fbe80

Please sign in to comment.