-
Notifications
You must be signed in to change notification settings - Fork 47
[DAR-4924][External] Resolving issues with import & export of NifTI annotations
#979
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
Conversation
| The volume containing the affine and original affine | ||
| """ | ||
| if volume.original_affine is not None: | ||
| img_ax_codes = nib.orientations.aff2axcodes(volume.affine) |
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.
I don't think this is correct for pre MED_2D due to the volume.affine being (or expected to be at least) RAS
So this flow will try to go from RAS -> original orientation.
But really its meant to go from LPI -> original orientation. I think this is why dataobj=np.flip(volume.pixel_array, (0, 1, 2)).astype(np.int16) used to be invoked: to go from LPI to RAS, so that then this logic would make sense for pre MED_2D files
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.
Updated
darwin/importer/formats/nifti.py
Outdated
| ax_codes = nib.orientations.aff2axcodes(affine) | ||
| ornt = nib.orientations.axcodes2ornt(ax_codes) | ||
| if not is_dicom: | ||
| img = nib.Nifti1Image(np.flip(img.get_fdata(), (0, 1, 2)), affine) |
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.
I think it might be more robust to do as_closest_canonical on img to get it to RAS, since this will only work if the Nifti annotation file is in LPI right
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.
Updated
|
Having some comments on why we need these transforms for pre MED_2D would be helpful for future ref I think |
dorfmanrobert
left a comment
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.
nice work!
Problem
This PR tackles 3 issues related to importing & exporting annotations in the
NifTIformat. Issue 1 is major, issues 2 & 3 are minorNifTIannotations are being incorrectly oriented upon import and export in some situationsNifTIannotations to items in dataset foldersNifTIannotations as polygons, the last frame is always omittedSolution
To tackle these problems:
NifTIannotations incorrectly, and in places we didn't need to be. This PR changes the logic to be the following:When importing
NifTIannotations: If importing to a postMED_2D_VIEWERfile, re-orient toLPIaccording tonibabel. This is the exact same logic we apply to medical file processing in the backend. Otherwise, if importing to a preMED_2D_VIEWERfile:NifTIdataset item: Re-orient toLPI, since all preMED_2D_VIEWERNifTIfiles were re-oriented this wayWhen exporting
NifTIannotations: Always re-orient the exportedNifTIfile based on the original affine of the dataset item it came fromNifTIannotations to items in dataset foldersNifTIpolygon annotationsIMPORTANT NOTE: Due to what I believe were some issues in the pre
MED_2D_VIEWERbackend processing pipeline, we may have incorrectly stored affines and original affines for some preMED_2D_VIEWERfiles. Since this is all we have to go off when re-orientingNifTIannotations, there may be issues in these cases, and we should keep an eye out for themChangelog
Resolved issues with automatic scaling & orientation of
NifTIannotations