Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix for warps hemi-L #180

Merged
merged 3 commits into from
Apr 13, 2022
Merged

bugfix for warps hemi-L #180

merged 3 commits into from
Apr 13, 2022

Conversation

jordandekraker
Copy link
Collaborator

I noticed there were still some issues with the warps from-unfold_to-native. I think this can be solved and the code simplified by simply running create_warps AFTER unflipping.

For the record, i think there is a difference between concatenating desc-flipLR_type-itk_xfm.txt onto existing transforms and flipping with c3d -flip x. I think one of these applies to the header only, while the other applied to the actual image. These should be equivalent, but i don't think that ANTs reads them the same way. Either way, this circumvents the issue entirely.

I tested once for a standard T1w modality and once for a cropseg modality (where output space is corobl) and both seem to work.

@jordandekraker jordandekraker added the bug Something isn't working label Apr 11, 2022
@jordandekraker jordandekraker requested a review from akhanf April 11, 2022 16:20
@akhanf
Copy link
Member

akhanf commented Apr 11, 2022

But does this then mean you would have manually flip before applying the warp?
I'm occupied with a grant deadline right now but should be able to look at it later this week..

@jordandekraker
Copy link
Collaborator Author

nope, no manual flip required. the warp is now created with the coords already flipped back to their original orientation. thus, we don't need to flip again manually and we don't need to (as we previously did) have a step that concatenated a flipping transform

@jordandekraker
Copy link
Collaborator Author

Some rules in gifti.smk were still causing warps with hemi-Lflip to be generated, and surfaces then had to be flipped from Lflip to L. This can be skipped now. Tested and working with T1w data.

Overall this PR cleans up the code a fair bit too, removing a few rules.

@akhanf
Copy link
Member

akhanf commented Apr 12, 2022

ok just about to try running the new updates -- but wanted to first just see what bug you are referring to. I transformed data from native to unfold and back again, both with left and right, and didn't come across any issues (aside from funny things at the boundary likely related to inverse inconsistency) -- what issues were you having?

antsApplyTransforms -t hippunfold/sub-000/warps/sub-000_hemi-R_label-hipp_from-T2w_to-unfold_mode-image_xfm.nii.gz -i hippunfold/sub-000/anat/sub-000_hemi-R_space-T2w_desc-subfields_dseg.nii.gz -o test_hemi-R_native_to_unfold.nii.gz -r hippunfold/sub-000/warps/sub-000_space-unfold_label-hipp_refvol.nii.gz  -v -n NearestNeighbor

antsApplyTransforms -t hippunfold/sub-000/warps/sub-000_hemi-R_label-hipp_from-unfold_to-T2w_mode-image_xfm.nii.gz -i test_hemi-R_native_to_unfold.nii.gz  -o test_hemi-R_native_to_unfold_to_native.nii.gz  -r hippunfold/sub-000/anat/sub-000_hemi-R_space-T2w_desc-subfields_dseg.nii.gz  -v -n NearestNeighbor

antsApplyTransforms -t hippunfold/sub-000/warps/sub-000_hemi-L_label-hipp_from-T2w_to-unfold_mode-image_xfm.nii.gz -i hippunfold/sub-000/anat/sub-000_hemi-L_space-T2w_desc-subfields_dseg.nii.gz -o test_hemi-L_native_to_unfold.nii.gz -r hippunfold/sub-000/warps/sub-000_space-unfold_label-hipp_refvol.nii.gz  -v -n NearestNeighbor

antsApplyTransforms -t hippunfold/sub-000/warps/sub-000_hemi-L_label-hipp_from-unfold_to-T2w_mode-image_xfm.nii.gz -i test_hemi-L_native_to_unfold.nii.gz  -o test_hemi-L_native_to_unfold_to_native.nii.gz  -r hippunfold/sub-000/anat/sub-000_hemi-L_space-T2w_desc-subfields_dseg.nii.gz  -v -n NearestNeighbor

native hemi-L subfields:
image

native -> unfold -> native hemi-L subfields
image

@@ -251,7 +251,7 @@ rule create_warps_dentate:
dir="AP",
label="dentate",
suffix="coords.nii.gz",
desc="init",
desc="laplace",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't this change the behaviour to now use laplace instead of shape-injection initialized fields for the dentate?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, they're the same thing actually (see rule linked below)
However, if we do end up refining the Laplace fields in the dentate in the future, then this is the filename we will want to use.

rule laplace_coords_dentate:

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah ok, I'm guessing we added that cp rule to avoid changing later rules.. I would prefer actually removing that cp rule to avoid confusion, but can perhaps can clean that up in another PR..

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we actually still use it to populate the coords folder in the output directory as well

@jordandekraker
Copy link
Collaborator Author

I'm actually wondering if my issue was specific to v1.0.0. I don't see any changes that seem relevant since then, but maybe I missed some.

The issue is that in hemi-L, if you unfold and then refold (or unfold the right hemisphere and refold it to the left hemisphere space), the image is the right orientation and so it loads as a subfield overlay in ITKSNAP, but the header affine still places it on the opposite side of the brain.

I came across the issue while trying to set up 2D registrations in unfolded space, and it will become a bigger issue if we want to concatenate unfold-2dregister-refold transforms all together.

@akhanf
Copy link
Member

akhanf commented Apr 12, 2022

yes, the workflow was considering unfolded L and Lflip to be distinct, so I guess the main change here is just to use the same unfolded space for L and R (ie not have a Lflip space).

That certainly does simplify things, I would just want to make sure we aren't breaking anything along the way. I can't recall why we had the distinction between Lflip and L in the unfolded space in the first place.. Only thing I can think of is if we wanted to allow for different physical unfolded coordinates for left and right (e.g. side-by-side) - they are identical right now, which is why I think it just works to remove the L and Lflip distinction, but it would mean we couldn't do that in the future I guess?

@jordandekraker
Copy link
Collaborator Author

By all means, I was hoping you'd help me make sure we're not breaking something with this change.

By my understanding, the actual unfolded space is always the same even before we eliminate hemi-Lflip. The thing that mainly changes is that create_warps.py now finds an interpolation from unfolded to xyz in hemi-L instead of unfolded to xyz in hemi-Lflip.

As far as I know, nnunet.smk, shape_inject.smk, and the Laplace initialization for autotop.smk (that comes from shape_inject.smk) must be done in hemi-Lflip. Laplace coords then need to be flipped back to hemi-L to populate the output coords folder, and once that is done I don't think there are any other steps that need to be in hemi-Lflip

@akhanf
Copy link
Member

akhanf commented Apr 12, 2022

Yep I don't see a major downside to eliminating Lflip in unfolded space, since we aren't setting L and R to be different there, and it does simplify things alot!

I'll run it through end-to-end and make sure the surfs and vols get warped properly.

Copy link
Member

@akhanf akhanf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tested end to end transforming vols and surfs and all looks good!
nice catch to eliminate extra complexity! I'll merge this in

@akhanf akhanf merged commit 3b6c162 into master Apr 13, 2022
@akhanf akhanf deleted the Lflip_createwarps branch April 13, 2022 15:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants