Skip to content

Commit

Permalink
fix for images where flip -> unflip does not return to original space
Browse files Browse the repository at this point in the history
- this was happening with some hippb500 images, but fixed it for any
modality, in case it happens again..
- the fix is to copy the transform from the original (unflipped) header
after unflipping. we just use `get_nnunet_input` for this..
  • Loading branch information
akhanf committed Mar 27, 2023
1 parent 2a80f37 commit 358e6ff
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
8 changes: 6 additions & 2 deletions hippunfold/workflow/rules/autotop.smk
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ rule unflip_coords:
hemi="{hemi}flip",
**config["subj_wildcards"]
),
unflip_ref=get_nnunet_input,
output:
nii=bids(
root=work,
Expand All @@ -248,7 +249,8 @@ rule unflip_coords:
group:
"subj"
shell:
"c3d {input} -flip x {output}"
"c3d {input.nii} -flip x -popas FLIPPED "
" {input.unflip_ref} -push FLIPPED -copy-transform -o {output.nii} "


rule unflip_coords_equivol:
Expand All @@ -264,6 +266,7 @@ rule unflip_coords_equivol:
hemi="{hemi}flip",
**config["subj_wildcards"]
),
unflip_ref=get_nnunet_input,
output:
nii=bids(
root=work,
Expand All @@ -281,4 +284,5 @@ rule unflip_coords_equivol:
group:
"subj"
shell:
"c3d {input} -flip x {output}"
"c3d {input.nii} -flip x -popas FLIPPED "
" {input.unflip_ref} -push FLIPPED -copy-transform -o {output.nii} "
4 changes: 3 additions & 1 deletion hippunfold/workflow/rules/nnunet.smk
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ rule unflip_nnunet_nii:
space="corobl",
hemi="{hemi}flip"
),
unflip_ref=get_nnunet_input,
output:
nnunet_seg=bids(
root=work,
Expand All @@ -173,7 +174,8 @@ rule unflip_nnunet_nii:
group:
"subj"
shell:
"c3d {input} -flip x {output}"
"c3d {input.nnunet_seg} -flip x -popas FLIPPED "
" {input.unflip_ref} -push FLIPPED -copy-transform -o {output.nnunet_seg} "


def get_f3d_ref(wildcards):
Expand Down
4 changes: 3 additions & 1 deletion hippunfold/workflow/rules/shape_inject.smk
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ rule unflip_postproc:
hemi="{hemi}flip",
**config["subj_wildcards"]
),
unflip_ref=get_nnunet_input,
output:
nii=bids(
root=work,
Expand All @@ -401,4 +402,5 @@ rule unflip_postproc:
group:
"subj"
shell:
"c3d {input} -flip x {output}"
"c3d {input.nii} -flip x -popas FLIPPED "
" {input.unflip_ref} -push FLIPPED -copy-transform -o {output.nii} "

0 comments on commit 358e6ff

Please sign in to comment.