razorx89 / pydicom-seg

Python package for DICOM-SEG medical segmentation file reading and writing
MIT License
76 stars 14 forks source link

Segment Identification Sequence is required in Shared Functional Groups Sequence #30

Closed vsaase closed 3 years ago

vsaase commented 3 years ago

Hi,

this is the same issue as https://github.com/QIICR/dcmqi/issues/428

I just tried to view a DICOM Segmentation I created with pydicom-seg in OHIF viewer with DICOM-segmentation extension. It tells me that SharedFunctionalGroupsSequence.SegmentIdentificationSequence is undefined, and indeed it is missing in the produced DICOM file. The standard says that this field is required: http://dicom.nema.org/medical/Dicom/2018d/output/chtml/part03/sect_C.8.20.3.html

A quick and dirty solution for a single segmentation is:

rsn = pydicom.Dataset()
rsn.ReferencedSegmentNumber = 1
dcm.SharedFunctionalGroupsSequence[0].SegmentIdentificationSequence = pydicom.Sequence()
dcm.SharedFunctionalGroupsSequence[0].SegmentIdentificationSequence.append(rsn)

Thanks, Victor

razorx89 commented 3 years ago

Thank you for reporting. However, I don't think that the currently generated DICOM is invalid. Attributes in the SharedFunctionalGroupsSequence must be applicable to all encoded frames. However as soon as you have more than a single segment defined and encoded, the ReferencedSegmentNumber must be stored in the PerFrameFunctionalGroupsSequence. Lookups should always respect both FunctionalGroupsSequences, from Shared and PerFrame.

https://github.com/razorx89/pydicom-seg/blob/33a130b077aeb29a761501945f0b9e4703522108/pydicom_seg/segmentation_dataset.py#L279

razorx89 commented 3 years ago

Closing for now. The underlying issue is being handled at https://github.com/OHIF/Viewers/issues/2280