-
-
Notifications
You must be signed in to change notification settings - Fork 667
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
WIP: Fix MINC read/write to convert from/to RAS coordinate system #147
Conversation
Originally discussed at https://insightsoftwareconsortium.atlassian.net/browse/ITK-3503?attachmentSortBy=fileName |
What about minc transform? |
@vfonov I have the code for converting the MINC affine to from RAS to LPS, I was going to do a seperate PR. Would you rather I roll that into this? |
@vfonov MINC vs ITK also defines its transforms in opposite directions, do you want that added to the reader, or leave that to the user? |
I have added the conversion for Affine transforms. I'm not quite sure where to add the switch to disable this conversion to support backwards compatibility. Can anyone give some guidance here? |
My transform work isn't right. It used to be combined with inverting the affines so that MINC and ITK transforms went in the same direction. I backed that part out and this needs some fixes as a result. |
one of the main reason for me to have minc interface for ITK is to be able to run ANTs & Elastix. I think we should run extensive checks to make sure that this conversion does not screw up their results. |
Totally agree. On the walk home I wrote up a bunch of tests in head to ensure this works properly. Will enumerate later. |
Given two files, in both MINC and NIFTI format:
mni_icbm152_t1_tal_nlin_asym_09c
Tests to do:
|
Sounds like a plan |
Additional tests:
|
nlfit <-> antsApplyTransforms probably will not work. |
c299516
to
2b0e595
Compare
All conversions and affine registrations now pass my listed tests. The following still don't work
ITK and MINC have opposite transform directions, and nlpfit doesn't produce an inverse warp field and doesn't handle the invert flag of an XFM grid transform properly (yet...) I think we have the issue that in grid-based transforms, the X and Y vector components point in opposite directions when produced in minc-land or ITK land. Questions
|
2b0e595
to
983052b
Compare
PR #194 addresses the issue with MINC NLIN transforms only being generated one-way and ITK not properly handling the invert flag on such transforms. Still remaining is I need to figure out an efficient method to voxel-wise multiply the incoming grid file by (-1,-1,1) to flip the RAS vector components to LPS vectors. |
Added patch now properly handles Grid transforms to/from MINC land. My local tests of
Now work properly. The question that remains is should ITK also invert all transforms it produces (and handle inversion on reading) so that the directionality of MINC vs ITK transforms is also transparently handled. This patch also works properly on top of/with #194 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I am not too familiar with MINC format, I only have minor remarks.
|
||
Matrix< double, 3,3 > RAS_affine_transform; | ||
Matrix< double, 3,3 > LPS_affine_transform; | ||
RAS_affine_transform.Fill(0.0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably not needed.
RAS_affine_transform.SetIdentity(); | ||
//MINC stores transforms in RAS, need to convert to LPS for ITK | ||
Matrix< double, 3,3 > RAS_tofrom_LPS; | ||
RAS_tofrom_LPS.Fill(0.0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be removed, I think.
Matrix< double, 3,3 > RAS_tofrom_LPS; | ||
Matrix< double, 3,3 > RAS_affine_transform; | ||
Matrix< double, 3,3 > LPS_affine_transform; | ||
RAS_tofrom_LPS.Fill(0.0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably redundant.
Thanks @dzenanz I have removed the extraneous Fills. |
@thewtex I think this change is breaking the current tests, is that correct? If so, any hints as to how to I would go about sorting that out? |
@gdevenyi there are 51 minc tests failing on all platforms. Do the tests all pass locally? |
@thewtex that's what I'm asking? how do I go about checking that locally :) |
@gdevenyi Is this PR still relavant? |
Yes, the MINC reader is still incorrect, and the coordinate system conversion fixes it. |
@gdevenyi Could you provide a roadmap for what you think needs to be done still? There may be students looking for projects this fall, and I'll see if I can convince one of them to look at this. |
Current state as I recall, fixed are
as I recall the blockers were
|
There is currently 4 different ways how Analyze file format can be handled, just make the same thing for MINC/XFM reader writer : https://github.com/InsightSoftwareConsortium/ITK/blob/master/Modules/IO/NIFTI/include/itkNiftiImageIO.h#L42 |
It looks like the origin is incorrect when RAS to LPS is needed |
Good catch @vfonov I'll take a look |
I am trying to make a new pull on the latest codebase: https://github.com/vfonov/ITK/tree/MINC_RAS_LPS_v2 (WIP) |
@vfonov The Origin Read/Write will need negative applied to the X and Y dimensions to go from R->L and A->P |
So, most things are fixed in https://github.com/vfonov/ITK/tree/MINC_RAS_LPS_v2 , we need to make more tests there. |
I already forgot what needs to be done. Do we want to, essentially make MINCs behave as if they were NIFTIs ? |
@gdeveny Can you rebase on master and fix the conflicts? I'd be interested to see how/if this breaks our app (Brainsight)... |
The core issue is MINC's internal coordinates are RAS = +X+Y+Z, but the ITK internal Image coordinate system is LPS = +X+Y+Z. MINC-IO in ITK loads the files not converting the coordinate system, making it impossible to mix MINC and any other image loaded by ITK IO. This is not "behave as if they were NIFTIs" but rather, "behave like every other image loaded by ITK ImageIO"
Will do. This will impact things if you were special casing anything about MINC, otherwise it should just make things load properly coordinate wise. |
Why not just document (via direction matrix) that the image is in RAS coordinate system? |
It's been forever since I touched our MINC reading code (via ITK), but maybe we are doing some flipping, because no one, internally or externally, has ever reported Brainsight loading any MINC files flipped. |
Is this a suggestion to address this in code somehow? I'm not deeply familiar with ITK internals, so I'll need some hints. My overall goal here was to bring MINC to first-class support in terms of it being treated equally and interchangeably with any other image loaded via ImageIO. Right now, I can't do this due to the misinterpreted coordinates. |
I did not take a close look at the code. If you are shuffling array elements to "conform to LPS" standard, you don't need to do that. I see that you are fiddling with orientation matrices, so this PR might already be doing what I suggested. |
As far as I remember now the issue is with transformations, in particular with non-linear |
Correct, this was the last outstanding thing that needs fixing in this PR in a performant way. |
Rebasing was too difficult so I manually ported the changes into the new PR #4864 |
Convert the coordinate system from RAS to LPS during MINC loading, and convert back on writing.
Also adds a setting to keep old configuration, so that MINC-based ITK tools (EZMinc) can maintain their original configuration and return sensible coordinate values in MINC-space.
Paging @vfonov