Skip to content

Conver metadata types to native and assign metadata to in-mem output image #186

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

Merged

Conversation

MMelQin
Copy link
Collaborator

@MMelQin MMelQin commented Oct 15, 2021

This is to address issue Attach meta data to the image object which is output by the segmentation operator

Please note, this PR also implements a function to convert the data type of a few known metadata attributes of the input Image object, as a workaround for the newly raised issue Represent DICOM metadata attribute with built-in or App SDK types

Example output of the converted metadata dict within the inference operator log:

Executing operator LiverTumorSegOperator (Process ID: 31824, Operator ID: 7beb6929-5a19-462e-9896-4072c7baf217)
Operator output folder path: /home/mqin/src/monai-app-sdk/examples/apps/.monai_workdir/operators/7beb6929-5a19-462e-9896-4072c7baf217/0/output/saved_images_folder
Converted Image object metadata:
series_instance_uid: 1.2.826.0.1.3680043.2.1125.1.68102559796966796813942775094416763, type <class 'str'>
modality: CT, type <class 'str'>
series_description: No series description, type <class 'str'>
row_pixel_spacing: 1.0, type <class 'float'>
col_pixel_spacing: 1.0, type <class 'float'>
depth_pixel_spacing: 1.0, type <class 'float'>
row_direction_cosine: [-1.0, 0.0, 0.0], type <class 'list'>
col_direction_cosine: [0.0, -1.0, 0.0], type <class 'list'>
depth_direction_cosine: [0.0, 0.0, 1.0], type <class 'list'>
dicom_affine_transform: [[-1.  0.  0.  0.]
 [ 0. -1.  0.  0.]
 [ 0.  0.  1.  0.]
 [ 0.  0.  0.  1.]], type <class 'numpy.ndarray'>
nifti_affine_transform: [[ 1. -0. -0. -0.]
 [-0.  1. -0. -0.]
 [ 0.  0.  1.  0.]
 [ 0.  0.  0.  1.]], type <class 'numpy.ndarray'>
file written: /home/mqin/src/monai-app-sdk/examples/apps/.monai_workdir/operators/7beb6929-5a19-462e-9896-4072c7baf217/0/output/saved_images_folder/1.2.826.0.1.3680043.2.1125.1/1.2.826.0.1.3680043.2.1125.1_seg.nii.gz.
file written: /home/mqin/src/monai-app-sdk/examples/apps/.monai_workdir/operators/7beb6929-5a19-462e-9896-4072c7baf217/0/output/saved_images_folder/1.2.826.0.1.3680043.2.1125.1/1.2.826.0.1.3680043.2.1125.1.nii.gz.
Output Seg image numpy array shaped: (515, 440, 440)
Output Seg image pixel max value: 2

@MMelQin MMelQin force-pushed the mqin/attach_metadata_to_in-mem_image_from_inference_operator branch from 7702ad4 to a01f327 Compare October 15, 2021 05:31
…image obj

Signed-off-by: mmelqin <mingmelvinq@nvidia.com>
@codecov
Copy link

codecov bot commented Oct 15, 2021

Codecov Report

Merging #186 (a01f327) into main (9006298) will decrease coverage by 0.18%.
The diff coverage is 4.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #186      +/-   ##
==========================================
- Coverage   35.29%   35.10%   -0.19%     
==========================================
  Files          64       64              
  Lines        3077     3096      +19     
==========================================
+ Hits         1086     1087       +1     
- Misses       1991     2009      +18     
Impacted Files Coverage Δ
...i/deploy/operators/monai_seg_inference_operator.py 28.17% <4.00%> (-2.69%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9006298...a01f327. Read the comment docs.

Copy link
Collaborator

@AndreasHeumann AndreasHeumann left a comment

Choose a reason for hiding this comment

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

Looks good to me, just a minor issue.

# Need to try to convert the data type of a few metadata attributes.
input_img_metadata = self._convert_dicom_metadata_datatype(input_image.metadata())
# Need to give a name to the image as in-mem Image obj has no name.
img_name = str(input_img_metadata.get("series_instance_uid", "Img_in_context"))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need this str() cast here since when the uid had already been converted to str?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

True, unnecessary, I left it there just for double safety and be explicit.

@MMelQin MMelQin merged commit c6b9ab1 into main Oct 15, 2021
@gigony gigony mentioned this pull request Oct 25, 2021
@MMelQin MMelQin deleted the mqin/attach_metadata_to_in-mem_image_from_inference_operator branch February 3, 2025 23:11
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.

2 participants