-
Notifications
You must be signed in to change notification settings - Fork 41
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
[DAR-4924][External] Resolving issues with import & export of NifTI
annotations
#979
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 |
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
NifTI
format. Issue 1 is major, issues 2 & 3 are minorNifTI
annotations are being incorrectly oriented upon import and export in some situationsNifTI
annotations to items in dataset foldersNifTI
annotations as polygons, the last frame is always omittedSolution
To tackle these problems:
NifTI
annotations incorrectly, and in places we didn't need to be. This PR changes the logic to be the following:When importing
NifTI
annotations: If importing to a postMED_2D_VIEWER
file, re-orient toLPI
according tonibabel
. This is the exact same logic we apply to medical file processing in the backend. Otherwise, if importing to a preMED_2D_VIEWER
file:NifTI
dataset item: Re-orient toLPI
, since all preMED_2D_VIEWER
NifTI
files were re-oriented this wayWhen exporting
NifTI
annotations: Always re-orient the exportedNifTI
file based on the original affine of the dataset item it came fromNifTI
annotations to items in dataset foldersNifTI
polygon annotationsIMPORTANT NOTE: Due to what I believe were some issues in the pre
MED_2D_VIEWER
backend processing pipeline, we may have incorrectly stored affines and original affines for some preMED_2D_VIEWER
files. Since this is all we have to go off when re-orientingNifTI
annotations, there may be issues in these cases, and we should keep an eye out for themChangelog
Resolved issues with automatic scaling & orientation of
NifTI
annotations