ImagingDataCommons / highdicom

High-level DICOM abstractions for the Python programming language
https://highdicom.readthedocs.io
MIT License
176 stars 37 forks source link

Is it possible to create a dicomseg for a DX? #99

Closed a-parida12 closed 3 years ago

a-parida12 commented 3 years ago

I am trying to save the segmentation of a CXR as a dicomseg.

seg_dataset = Segmentation(
            source_images=[source_image],
            pixel_array=np.uint16(seg_img),
            segmentation_type=SegmentationTypeValues.FRACTIONAL,
            segment_descriptions=description_segments,
            series_instance_uid=generate_uid(),
            sop_instance_uid=generate_uid(),
            instance_number=instance_number,
            manufacturer="deepc",
            manufacturer_model_name=config["NAME"],
            software_versions="v"+config["VERSION"],
            device_serial_number="Device XYZ",
            series_number=2,
            fractional_type="OCCUPANCY",
        )

Even though I am using a proper DX dcm. I am getting errors where it says some fields like StudyID, SliceThickness and PixelSpacing are missing in the source_image. Is it possible to skip the missing fields? or is there a better way to handle such scenarios?

hackermd commented 3 years ago

Thanks @a-parida12 for your interest in the library and for reporting the issue.

The Slice Thickness and Pixel Spacing attributes are required for creation of a Segmentation instance (see Pixel Measures Macro Attributes).

Interestingly, the Pixel Spacing attribute has type 1C in case of a Diagnostic X-Ray Image (see Basic Pixel Spacing Calibration Macro Attributes) and I am not sure whether Slice Thickness may be present.

You can provide this information to the constructor of highdicom.seg.Segmentation using the pixel_measures parameter (see highdicom.seg.Segmentation).

The Study ID attribute is type 2, so it should be present in the source image even if it does not have a value. You could just patch the source_image prior to passing it to highdicom.seg.Segmentation:

source_image.StudyID = None
pixel_measures = PixelMeasuresSequence(
    pixel_spacing=...,
    slice_thickness=...,
)

seg_dataset = Segmentation(
    source_images=[source_image],
    pixel_array=np.uint16(seg_img),
    segmentation_type=SegmentationTypeValues.FRACTIONAL,
    segment_descriptions=description_segments,
    series_instance_uid=generate_uid(),
    sop_instance_uid=generate_uid(),
    instance_number=instance_number,
    manufacturer="deepc",
    manufacturer_model_name=config["NAME"],
    software_versions="v"+config["VERSION"],
    device_serial_number="Device XYZ",
    series_number=2,
    fractional_type="OCCUPANCY",
    pixel_measures=pixel_measures
)
hackermd commented 3 years ago

Closing the issue due to inactivity.