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

DICOM-SEG only displayed when I load it first #563

Open
inikishev opened this issue Jun 20, 2024 · 7 comments
Open

DICOM-SEG only displayed when I load it first #563

inikishev opened this issue Jun 20, 2024 · 7 comments

Comments

@inikishev
Copy link

Describe the bug. What happened?

When I drag DICOM-SEG file into Weasis, and THEN drag the linked images, the segmentation panel works.

However when I first open an image, and then open the segmentation for it, nothing happens, no segmentation appears. The only change is an orange circle that appears on the linked image thumbnail:
image

What version of Weasis are you running?

4.4.0

On which system the problem occurs?

Windows

Relevant log output

No response

Additional contextual elements

No response

@nroduit
Copy link
Owner

nroduit commented Jun 20, 2024

There are several enhancements for reading SEG files in the next version.
Please send me an example to see if it is OK.

@nroduit
Copy link
Owner

nroduit commented Jan 23, 2025

Can you confirm whether this problem has been fixed?

@inikishev
Copy link
Author

Can you confirm whether this problem has been fixed?

In the last version I am not able to load my segmentation at all. When I load DICOM-SEG first, then DICOMs, it doesn't display anything and seems to break the UI a little bit - some tabs have not text.

Image

when I load DICOMs first, and then DICOM-SEG, it just doesn't display segmentation

Image

here is the log https://gist.github.com/inikishev/9732660c0df14530da4327526a1688a1

I downloaded the DICOMs here https://github.com/datalad/example-dicom-structural, and saved some bogus segmentation, which should look like this

Image

example DICOM-SEG.zip here is a DICOM-SEG file (I zipped it because github doesnt accept .dcm).

@nroduit
Copy link
Owner

nroduit commented Feb 6, 2025

Your SEG file is not consistent. The SEG object must be a distinct series and therefore needs a new series instance UID. The same series can only have one modality type (MR and SEG is not possible).

@inikishev
Copy link
Author

Your SEG file is not consistent. The SEG object must be a distinct series and therefore needs a new series instance UID. The same series can only have one modality type (MR and SEG is not possible).

thank you for the information. I was using highdicom and I set series_instance_uid = source_images[0].SeriesInstanceUID,, and that must have caused the issue. I will try this method now https://razorx89.github.io/pydicom-seg/guides/write.html

@inikishev
Copy link
Author

inikishev commented Feb 7, 2025

Your SEG file is not consistent. The SEG object must be a distinct series and therefore needs a new series instance UID. The same series can only have one modality type (MR and SEG is not possible).

Unfortunately I am not able to get it working. I followed https://razorx89.github.io/pydicom-seg/guides/write.html, this is my code

import numpy as np
import pydicom
import pydicom_seg
import SimpleITK as sitk

template = pydicom_seg.template.from_dcmqi_metainfo('metainfo.json')

writer = pydicom_seg.MultiClassWriter(
    template=template,
    # inplane_cropping=True,  # Crop image slices to the minimum bounding box on
    #                         # x and y axes
    # skip_empty_slices=True,  # Don't encode slices with only zeros
    # skip_missing_segment=False,  # If a segment definition is missing in the
    #                              # template, then raise an error instead of
    #                              # skipping it.
)

reader = sitk.ImageSeriesReader()

# https://github.com/datalad/example-dicom-structural
series_instance_uid = pydicom.dcmread('/var/mnt/hdd/Datasets/Example DICOMs/dicoms/N2D_0001.dcm').SeriesInstanceUID

dcm_files = reader.GetGDCMSeriesFileNames('/var/mnt/hdd/Datasets/Example DICOMs/dicoms', series_instance_uid)
reader.SetFileNames(dcm_files)
image = reader.Execute()
image_data = sitk.GetArrayFromImage(image)

def process_image(arr):
    arr = np.random.randint(size = arr.shape, low = 0, high = 2, dtype = np.uint8)
    assert arr.min() == 0
    assert arr.max() == 1
    return arr


segmentation_data = process_image(image_data)

segmentation = sitk.GetImageFromArray(segmentation_data)
segmentation.CopyInformation(image)

source_images = [
    pydicom.dcmread(x, stop_before_pixels=True)
    for x in dcm_files
]
dcm = writer.write(segmentation, source_images)
dcm.save_as('segmentation.dcm')

and this is metainfo.json

{
  "ContentCreatorName": "Reader1",
  "ClinicalTrialSeriesID": "Session1",
  "ClinicalTrialTimePointID": "1",
  "SeriesDescription": "Segmentation",
  "SeriesNumber": "300",
  "InstanceNumber": "1",
  "segmentAttributes": [
    [
      {
        "labelID": 1,
        "SegmentDescription": "Meningioma",
        "SegmentAlgorithmType": "AUTOMATIC",
        "SegmentAlgorithmName": "bogus",
        "SegmentedPropertyCategoryCodeSequence": {
          "CodeValue": "49755003",
          "CodingSchemeDesignator": "SCT",
          "CodeMeaning": "Morphologically Altered Structure"
        },
        "SegmentedPropertyTypeCodeSequence": {
          "CodeValue": "4147007",
          "CodingSchemeDesignator": "SCT",
          "CodeMeaning": "Mass"
        },
        "recommendedDisplayRGBValue": [
          144,
          238,
          144
        ]
      }
    ]
  ],
  "ContentLabel": "SEGMENTATION",
  "ContentDescription": "Image segmentation",
  "ClinicalTrialCoordinatingCenterName": "dcmqi",
  "BodyPartExamined": "Brain"
}

the SEG file itself is OK, I can open it with AlizaMS

segmentation.zip

However nothing seems to happen when I open it in weasis.

@nroduit
Copy link
Owner

nroduit commented Feb 7, 2025

There are always problems with this file. It lacks mandatory fields like SegmentLabel, which is used as a key by Weasis.
Please start by 'using a DICOM validation tool if you want to create data, see the Innolitics validator:

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants