ImagingDataCommons / highdicom

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

Problem writing x-ray angiography data (2D+ time) #200

Open ChristianEschen opened 2 years ago

ChristianEschen commented 2 years ago

Hi.

I try to use the software to write a DICOM SEG file for x-ray angiography images (2D+time).

The files can be found here: http://www.rubomedical.com/dicom_files/dicom_viewer_0002.zip

However, I get the following error: ########################## Exception has occurred: ValueError (note: full exception trace is shown but execution is paused at: _run_module_as_main) Only a single frame is supported when the source image has no Frame of Reference UID. #########################

I use the hidicom installed from source.

The code I use is the following: `from pathlib import Path

import highdicom as hd import numpy as np from pydicom.sr.codedict import codes from pydicom.filereader import dcmread

series_path = "/home/alatar/miacag/data/angio/sample_data/2/0002.dcm"

Read XA angiography data

image_dataset = dcmread(series_path)

Create a binary segmentation mask

mask = np.zeros( shape=( image_dataset.pixel_array.shape[0], image_dataset.Rows, image_dataset.Columns ), dtype=np.bool ) mask[0:20, 0:20,0:20] = 1

Describe the algorithm that created the segmentation

algorithm_identification = hd.AlgorithmIdentificationSequence( name='test', version='v1.0', family=codes.cid7162.ArtificialIntelligence )

Describe the segment

description_segment_1 = hd.seg.SegmentDescription( segment_number=1, segment_label='first segment', segmented_property_category=codes.cid7150.Tissue, segmented_property_type=codes.cid7166.ConnectiveTissue, algorithm_type=hd.seg.SegmentAlgorithmTypeValues.AUTOMATIC, algorithm_identification=algorithm_identification, tracking_uid=hd.UID(), tracking_id='test segmentation of slide microscopy image' )

Create the Segmentation instance

seg_dataset = hd.seg.Segmentation( source_images=[image_dataset], pixel_array=mask, segmentation_type=hd.seg.SegmentationTypeValues.BINARY, segment_descriptions=[description_segment_1], series_instance_uid=hd.UID(), series_number=2, sop_instance_uid=hd.UID(), instance_number=1, manufacturer='Manufacturer', manufacturer_model_name='Model', software_versions='v1', device_serial_number='Device XYZ' )

print(seg_dataset) seg_dataset.save_as("/home/alatar/seg.dcm") `

I hope you can help me out.

CPBridge commented 2 years ago

Hi @ChristianEschen, thanks for using the library and reporting this issue.

Unfortunately, what you are reporting is currently the expected behaviour of the library in this situation, i.e. an error message that what you are trying to do is not supported. There are a very large number of possible DICOM objects for which users may wish to create segmentations, which often require tailored methods to index the frames in the created segmentation in order to be compliant to the standard, and supporting many of them is therefore a considerable challenge. We have tried to support those inputs that we think are most likely to be useful, and unfortunately we have not yet implemented a solution for the 2D + T angiography case (or indeed any input image or series with multiple frames and no frame of reference UID to describe the frames in 3D space).

I hope that we will be able to support this at some point, although I have to say that it is unlikely to be soon I'm afraid. Your example file will be very helpful to us for this purpose so we do appreciate you filing the issue. I will leave this issue open.

A note for when we work on this: we will need to create a new indexing scheme based on the FrameTime attribute, which gives the time in ms between consecutive frames.

CPBridge commented 2 years ago

Note that #174 is a related issue