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

BUG: Fix incorrect reading of MINC2 files, convert RAS coordinates to LPS #4864

Merged
merged 5 commits into from
Feb 22, 2025

Conversation

gdevenyi
Copy link
Contributor

@gdevenyi gdevenyi commented Sep 27, 2024

Replaces #147

PR Checklist

  • No API changes were made (or the changes have been approved)
  • No major design changes were made (or the changes have been approved)
  • Added test (or behavior not changed)
  • Updated API documentation (or API not changed)
  • Added license to new files (if any)
  • Added Python wrapping to new files (if any) as described in ITK Software Guide Section 9.5
  • Added ITK examples for all new major features (if any)

Refer to the ITK Software Guide for
further development details if necessary.

@github-actions github-actions bot added type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances area:IO Issues affecting the IO module labels Sep 27, 2024
@gdevenyi
Copy link
Contributor Author

gdevenyi commented Sep 27, 2024

TODO:

  • port TransformMINC fixes
  • add tests
    • read in MINC file, read in NIFTI file, confirm identical with internal representation
  • wrap in some kind of ITK legacy warning

@seanm
Copy link
Contributor

seanm commented Oct 8, 2024

I'd be interested to try this in our app when you think it's in shape...

@vfonov
Copy link
Contributor

vfonov commented Oct 9, 2024

I'll try to make changes....

@vfonov
Copy link
Contributor

vfonov commented Oct 18, 2024

TODO:

  • port TransformMINC fixes

  • add tests

    • read in MINC file, read in NIFTI file, confirm identical with internal representation
  • wrap in some kind of ITK legacy warning

https://github.com/vfonov/ITK/commits/MINC_IMAGE_RAS_LPS_VF/ - here is my work in progress, i am going to add tests for all the new cases...

@blowekamp
Copy link
Member

Would any of the enums enums for the AnatomicalOrientaion PR be useful here?

I am seeing a lot of LPS and RAS terms in this PR which can be little ambiguous. At lease the public interface of "RAS_to_LPS" the setter getter could be clarified and be make unambiguous.

@vfonov
Copy link
Contributor

vfonov commented Oct 21, 2024

At lease the public interface of "RAS_to_LPS" the setter getter could be clarified and be make unambiguous.

What would make it less ambiguous?

@vfonov
Copy link
Contributor

vfonov commented Oct 22, 2024

OK, How do i push my changes here from https://github.com/vfonov/ITK/tree/MINC_IMAGE_RAS_LPS ?

@jhlegarreta
Copy link
Member

Pushing to Gabriel's branch should work:

git push gdevenyi MINC_IMAGE_RAS_LPS

The above assumes that the you have created your MINC_IMAGE_RAS_LPS branch from gdevenyi's branch. If not, I believe

git remote add gdevenyi https://github.com/gdevenyi/ITK.git
git fetch gdevenyi
git checkout MINC_IMAGE_RAS_LPS
git branch -u gdevenyi/MINC_IMAGE_RAS_LPS
git push gdevenyi MINC_IMAGE_RAS_LPS

should have the desired effect. If you run into trouble, you can start a fresh branch (assuming you rename your local MINC_IMAGE_RAS_LPS to something else to avoid issues) and cherry-pick your commit:

git remote add gdevenyi https://github.com/gdevenyi/ITK.git
git fetch gdevenyi
git checkout -b gdevenyi MINC_IMAGE_RAS_LPS
git cherry-pick 7688f522b685eb4ace0b9753f0bbf145fd6389bb
git push gdevenyi MINC_IMAGE_RAS_LPS

@vfonov
Copy link
Contributor

vfonov commented Oct 22, 2024

git push gdevenyi MINC_IMAGE_RAS_LPS

ERROR: Permission to gdevenyi/ITK.git denied to vfonov.

@jhlegarreta
Copy link
Member

ERROR: Permission to gdevenyi/ITK.git denied to vfonov.

@gdevenyi should be able to grant permissions to push to his ITK fork on GitHub, which should fix the issue.

@gdevenyi
Copy link
Contributor Author

I have invited @vfonov

@github-actions github-actions bot added type:Infrastructure Infrastructure/ecosystem related changes, such as CMake or buildbots type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct labels Oct 22, 2024
@vfonov
Copy link
Contributor

vfonov commented Oct 23, 2024

So itkSPSAOptimizerTest fails on Windows, do we need to do anything about that?

@blowekamp
Copy link
Member

This newly merged class should provide some documentation to better describe the coordinate changes in an unambiguous fashion: https://github.com/InsightSoftwareConsortium/ITK/blob/master/Modules/Core/Common/include/itkAnatomicalOrientation.h

@vfonov
Copy link
Contributor

vfonov commented Oct 23, 2024

so, where does this new class apply in the proposed change?

@blowekamp
Copy link
Member

so, where does this new class apply in the proposed change?

Please document what you mean by RAS in the unambiguous terminology described in that class.

@vfonov
Copy link
Contributor

vfonov commented Oct 23, 2024

so, where does this new class apply in the proposed change?

Please document what you mean by RAS in the unambiguous terminology described in that class.

So, it's a documentation question - i.e I should updated documentation of the MINC reader Module?

@vfonov
Copy link
Contributor

vfonov commented Oct 23, 2024

@gdevenyi - can you make changes requested by @blowekamp ? I do not understand what's required here.

Copy link
Member

@jhlegarreta jhlegarreta left a comment

Choose a reason for hiding this comment

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

Thanks for doing this @gdevenyi. An in-line style comment.

@gdevenyi gdevenyi marked this pull request as ready for review December 2, 2024 19:39
Copy link
Member

@jhlegarreta jhlegarreta left a comment

Choose a reason for hiding this comment

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

Left some style-related comments. There is a conflict that needs to be resolved since the code base has undergone some extensive style-related changes in the meantime.

While at it, stick to the commit message conventions: use sentence case (capitalize first letter), finish commit message BODY explanation with a period.

@blowekamp
Copy link
Member

@vfonov @gdevenyi It is my understanding that this PR has conflicts due to all the recent activity. Thank you for the contribution and maintaining MINC for ITK.

Can I help updating the PR, and trying to address some of these style issues?

Also, I think we should do this change in 2 steps. This first is adding the LPS as an option preserving compatibility. And is a second PR, change the default? Maybe introduce an environment variable for this setting too?

Let me know if I can help make changes to get this PR through.

@gdevenyi
Copy link
Contributor Author

Can I help updating the PR, and trying to address some of these style issues?

Yes please. I would very much appreciate the help.

This contribution to ITK has been 6 years in the making with the original technical solution remaining unchanged. I'm a generalist and ITK is a C++-expert level codebase, I'm a monkey at a typewriter here trying to keep up with the high churn and level of abstraction that this codebase demands. The complexity along with the serial reviews have made it very difficult.

I would very much appreciate any help you can offer.

@vfonov
Copy link
Contributor

vfonov commented Dec 16, 2024

So, I don't understand - what needs to be done right now. Do we neeed:

  1. rebase to the current ITK master?
  2. address various style comments by @jhlegarreta regarding "ITK SWG"
  3. fix the "This branch has conflicts that must be resolved" message?
  4. fix just the "bool mRAStoLPS" variable (that's what shows up in "requested" changes .

@blowekamp
Copy link
Member

So, I don't understand - what needs to be done right now. Do we neeed:

  1. rebase to the current ITK master?
  2. address various style comments by @jhlegarreta regarding "ITK SWG"
  3. fix the "This branch has conflicts that must be resolved" message?
  4. fix just the "bool mRAStoLPS" variable (that's what shows up in "requested" changes .

Yes, I thin that is a summary of what needs to be done. I am also going to separate the change in behavior for another PR, to make review easier. I am going to start working on update the PR branch.

@seanm
Copy link
Contributor

seanm commented Dec 17, 2024

Glad to see this work. Again, when it's in better shape, I'll give it a try in our app, which has various tests of its own that might exercise some of this.

@blowekamp
Copy link
Member

I have updated the PR. For now I removed the CMake option, and have kept the behavior the same as it was. This can be changed in another PR.

Is it useful to still write with the the corrected coordinates? I am thinking that the correct cordinates should always be written no, and the flag is used then loading.

The "RAStoLPS" flag was not immediately clear to be what it did. Perhaps something line "ApplyCoordiateConversionForITK" would be more descriptive?

Also is there meta-data written in the transform to indicate that coordinates have been corrected?

@gdevenyi
Copy link
Contributor Author

Is it useful to still write with the the corrected coordinates? I am thinking that the correct cordinates should always be written no, and the flag is used then loading.

The correct coordinates for a MINC file are RAS on-disk. This dynamic conversion must happen during both read and write into ITK.

"ApplyCoordiateConversionForITK" would be more descriptive?

Yes, this rename is reasonable.

Also is there meta-data written in the transform to indicate that coordinates have been corrected?

Similar to the image format, there is only one right way for the coordinate to be represented in MINC-land so there's no need to note correction

Ref: https://en.wikibooks.org/wiki/MINC/SoftwareDevelopment/MINC2.0_File_Format_Reference

@seanm
Copy link
Contributor

seanm commented Jan 22, 2025

We will test this at the hackathon tomorrow.

If you have time to rebase it against master that'd be great.

@jhlegarreta
Copy link
Member

If you have time to rebase it against master that'd be great.

Done.

@seanm
Copy link
Contributor

seanm commented Jan 23, 2025

I can say that building our own app against this PR works, all our tests still pass too. That's a low bar mind you, we don't ourselves have extensive MINC testing (we mostly rely on upstream).

Are there sample files should should behave differently before and after this change?

@gdevenyi
Copy link
Contributor Author

I can say that building our own app against this PR works, all our tests still pass too. That's a low bar mind you, we don't ourselves have extensive MINC testing (we mostly rely on upstream).

Are there sample files should should behave differently before and after this change?

The PR includes the changes to the tests which show how things change.

Fundamentally, this fix allows MINC and non-minc files to be mixed together inside a ITK pipeline since they will now correctly have the same internal coordinate system representation. Before this PR, the MINC files would be flipped around such that they were self-consistently wrong in terms of input/output, but couldn't cross the boundary to another file format correctly.

@dzenanz
Copy link
Member

dzenanz commented Feb 13, 2025

Gabriel, Vladimir, and Brad, this PR seems close. What is left to do besides removing WIP from one of those commits? I would like this PR to be merged sooner rather than later.

@gdevenyi
Copy link
Contributor Author

What is left to do besides removing WIP from one of those commits? I would like this PR to be merged sooner rather than later.

@dzenanz if the developers who were asking for style changes are happy with the commits now I believe this is ready.

gdevenyi and others added 4 commits February 15, 2025 02:39
convert MINC PositiveCoordinateOrientation RAS coordinates to ITK PositiveCoordinateOrientation LPS coordinates
during reading and writing
convert MINC PositiveCoordinateOrientation RAS coordinate system to ITK PositiveCoordinateOrientation LPS
Remove MINC IO RAS to LPS CMake flag. Commits f97618b and 9eb1b70
address the contrasting internal image orientation conventions used by
ITK and MINC, making MINC follow the same convetion as ITK.

Thus, the corresponding conversion CMake flag is no longer necessary.

Set the ivar `m_RAStoLPS` default value to `false` following the change.
Adopt ITK style conventions in MINC module code: adopt the recommended
variable naming conventions.
@jhlegarreta
Copy link
Member

jhlegarreta commented Feb 15, 2025

I have removed the WIP prefix from the commit and provided some best guess context in the commit message as to the change of the commit. Please feel free to modify if required.

Edit: I now see that the commit (6e75f1f) at issue removes lines of code that were introduced in another commit (50f6526) in this PR. Those changes should be merged and the unnecessary commit be removed, but given the state of things, I would prefer to avoid further difficulties with this PR. So this is ready to go for me.

Remove empty end of file line in excess.

Fixes:
```
diff --git a/Documentation/docs/releases/5.4.2.md b/Documentation/docs/releases/5.4.2.md
index 64cb36c..78f5864 100644
--- a/Documentation/docs/releases/5.4.2.md
+++ b/Documentation/docs/releases/5.4.2.md
@@ -272,4 +272,3 @@ Remote Module Changes Since v5.4.0
 #### Bug Fixes

 - Bump Python package version for re-deploy ([9f6654d](InsightSoftwareConsortium/ITKTotalVariation@9f6654d))
-
```

raised for example in:
https://github.com/InsightSoftwareConsortium/ITK/actions/runs/13343048744/job/37270119146?pr=4864#step:5:133
@jhlegarreta jhlegarreta self-requested a review February 15, 2025 07:46
@github-actions github-actions bot added the area:Documentation Issues affecting the Documentation module label Feb 15, 2025
@dzenanz dzenanz merged commit 33d1031 into InsightSoftwareConsortium:master Feb 22, 2025
16 checks passed
@dzenanz
Copy link
Member

dzenanz commented Feb 22, 2025

Thank you all!

@gdevenyi
Copy link
Contributor Author

Thank you all 🎉🎉🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:Documentation Issues affecting the Documentation module area:IO Issues affecting the IO module type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances type:Infrastructure Infrastructure/ecosystem related changes, such as CMake or buildbots type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants