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

[MED-23][external] Support for export from Raster Layer to NifTI #750

Merged
merged 2 commits into from Feb 19, 2024

Conversation

tomvars
Copy link
Contributor

@tomvars tomvars commented Dec 13, 2023

Problem

Users of Darwin can currently annotate as masks but not export these results to NifTI

Solution

We create a new code path within the same NifTI export logic. This means that for darwin JSON that contains polygons we will still parse these as before and output a NifTI volume. If the user has K mask classes they will receive K output files called SeriesInstanceUID_classname_m.nii.gz (NOTE: for nifti uploads SeriesInstanceUID is the filename)

Changelog

Introduced initial support for NifTI export from Masks

Copy link

linear bot commented Dec 13, 2023

frames[frame_idx].annotation_class.name
im_mask = convert_polygons_to_mask(polygons, height=height, width=width)
volume = output_volumes[series_instance_uid]
if view_idx == 0:
Copy link
Contributor

Choose a reason for hiding this comment

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

is there a reason you use '0' here but XYPLANE above? Are these totally different or is the magic number here meant to be XYPLANE? Same for below

Copy link
Contributor

Choose a reason for hiding this comment

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

Implemented in the new commit

frames = annotation.frames

# define the different planes
XYPLANE = 0
Copy link
Contributor

Choose a reason for hiding this comment

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

Are these intrinsinc to nifti and potentially used by other functions? If so can we make this a type

Something like

class Plane(Enum):
    XY = 0
    XZ = 1
    YZ = 2

if view_idx == Plane.XY.value

Copy link
Contributor

Choose a reason for hiding this comment

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

Implemented in the new commit

im_mask = convert_polygons_to_mask(polygons, height=height, width=width)
volume = output_volumes[series_instance_uid]
if view_idx == 0:
volume[annotation.annotation_class.name].pixel_array[
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be great to generalize this function, if only so that it's named and has a docstring. I can't actually tell by inspection what it's meant to be doing too easily

def transform_plane(plane, volume, ...): #or some other more relevant name
    """ docstrings explaining high level so that numpy logic is easier to reason about """
    if plane == XYZ:
        transform_indexes = [np.s_[:], frame_idx, np.s[:]]
    ...
    volume[annotation.annotation_class.name].pixel_array[transform_indexes] = np.logical_or(...)

Copy link
Contributor

Choose a reason for hiding this comment

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

and I know this is probably some nifti format specific thing but jumping into the code for these specific data formats from the outside is a lot easier if these sorts of transforms are easier to reason about, with names and descriptions

@shernshiou shernshiou force-pushed the med-23-export-raster_layer-annotations-to-nifti branch from b6b187f to eb71db3 Compare January 24, 2024 15:33
@shernshiou shernshiou marked this pull request as draft January 24, 2024 15:35
@shernshiou shernshiou force-pushed the med-23-export-raster_layer-annotations-to-nifti branch 3 times, most recently from 11971af to 0ec1426 Compare February 1, 2024 09:45
@shernshiou shernshiou self-assigned this Feb 1, 2024
@shernshiou shernshiou force-pushed the med-23-export-raster_layer-annotations-to-nifti branch 3 times, most recently from 5d7b086 to 0e18043 Compare February 5, 2024 14:59
@shernshiou shernshiou marked this pull request as ready for review February 5, 2024 14:59
@shernshiou shernshiou force-pushed the med-23-export-raster_layer-annotations-to-nifti branch from 0e18043 to 68ff24b Compare February 19, 2024 10:35
Copy link
Contributor

@JBWilkie JBWilkie left a comment

Choose a reason for hiding this comment

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

LGTM - Tested this commit in a deploybot to ensure we can export multiple mask & polygon classes as NifTI volumes

@shernshiou shernshiou merged commit 6e678bc into master Feb 19, 2024
16 checks passed
@saurbhc saurbhc deleted the med-23-export-raster_layer-annotations-to-nifti branch February 19, 2024 19:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants