Skip to content

Cannot open custom highdicom derived SC DICOM in ITK-Snap #247

@tomaroberts

Description

@tomaroberts

Hi – I'm not super familiar with highdicom; this seems like a fairly straightforward problem but I've not managed to find solution to my issue in the docs or existing Issues, so apologies if I've missed it.

I'm basically trying to write a 3D singleframe .dcm dataset following the second code block in the tutorial here. I have no segmentation overlay, so I've removed those parts.

My adapted code snippet is below:

import highdicom as hd
import nibabel as nib
import numpy as np
import os

input_nii_path = r'/path/to/niifile.nii/gz.nii.gz'
output_dcm_path = r'/path/to/output_dcm_folder'
os.mkdir(output_dcm_path)

nii = nib.load(input_nii_path)

# get pixel data from NIfTI
nii_img = nii.get_fdata()
nii_img = nii_img.astype("uint16")  # match DICOM datatype

pixel_spacing = [1.0, 1.0]
sz = nii_img.shape[2]
print(f'nii_img sz: {sz}')

series_instance_uid = hd.UID()
study_instance_uid = hd.UID()

patient_orientation=['L', 'P']

for iz in range(sz):
    this_slice = nii_img[:, :, iz]

    pixel_array = this_slice

    # Create the secondary capture image
    sc_image = hd.sc.SCImage(
        pixel_array=pixel_array.astype(np.uint16),  #originally uint8 in tutorial
        photometric_interpretation=hd.PhotometricInterpretationValues.MONOCHROME2,
        bits_allocated=16,  # originally 8 in tutorial
        coordinate_system=hd.CoordinateSystemNames.PATIENT,
        study_instance_uid=study_instance_uid,
        series_instance_uid=series_instance_uid,
        sop_instance_uid=hd.UID(),
        series_number=100,
        instance_number=iz + 1,
        manufacturer='Manufacturer',
        pixel_spacing=pixel_spacing,
        patient_orientation=patient_orientation,
    )

    sc_image.save_as(os.path.join(output_dcm_path, 'sc_output_' + str(iz) + '.dcm'))

When I try to open this in ITK-Snap, it errors with the following:

image

My input NIFTI dataset is derived from MRI data, hence MONOCHROME2 and BitsAllocation = 16. When I opened the DICOMs in MITKWorkbench, it also failed and indicated an orientation problem, so I tried manually adding ImageOrientationPatient = (e.g.) ['1', '0', '0', '0', '1', '0'] but that has not helped.

Here's a dump of the DICOM metadata:

Dataset.file_meta -------------------------------
(0002, 0000) File Meta Information Group Length  UL: 210
(0002, 0001) File Meta Information Version       OB: b'\x00\x01'
(0002, 0002) Media Storage SOP Class UID         UI: Secondary Capture Image Storage
(0002, 0003) Media Storage SOP Instance UID      UI: 1.2.826.0.1.3680043.10.511.3.40792569118819711334400295680320982
(0002, 0010) Transfer Syntax UID                 UI: Explicit VR Little Endian
(0002, 0012) Implementation Class UID            UI: 1.2.826.0.1.3680043.9.7433.1.1
(0002, 0013) Implementation Version Name         SH: 'highdicom0.21.1'
-------------------------------------------------
(0008, 0008) Image Type                          CS: ['DERIVED', 'SECONDARY', 'OTHER']
(0008, 0016) SOP Class UID                       UI: Secondary Capture Image Storage
(0008, 0018) SOP Instance UID                    UI: 1.2.826.0.1.3680043.10.511.3.40792569118819711334400295680320982
(0008, 0020) Study Date                          DA: None
(0008, 0023) Content Date                        DA: "20230807"
(0008, 0030) Study Time                          TM: None
(0008, 0033) Content Time                        TM: "131553.080334"
(0008, 0050) Accession Number                    SH: None
(0008, 0060) Modality                            CS: 'OT'
(0008, 0064) Conversion Type                     CS: 'DI'
(0008, 0070) Manufacturer                        LO: 'Manufacturer'
(0008, 0090) Referring Physician's Name          PN: None
(0010, 0010) Patient's Name                      PN: None
(0010, 0020) Patient ID                          LO: None
(0010, 0030) Patient's Birth Date                DA: None
(0010, 0040) Patient's Sex                       CS: None
(0018, 1012) Date of Secondary Capture           DA: "20230807"
(0018, 1014) Time of Secondary Capture           TM: "131553.080376"
(0020, 000d) Study Instance UID                  UI: 1.2.826.0.1.3680043.10.511.3.47134193835689979621889364632875485
(0020, 000e) Series Instance UID                 UI: 1.2.826.0.1.3680043.10.511.3.30353553887687175567028695251528949
(0020, 0010) Study ID                            SH: None
(0020, 0011) Series Number                       IS: '100'
(0020, 0013) Instance Number                     IS: '129'
(0020, 0020) Patient Orientation                 CS: ['L', 'P']
(0020, 0035) Image Orientation                   DS: [1, 0, 0, 0, 1, 0]
(0028, 0002) Samples per Pixel                   US: 1
(0028, 0004) Photometric Interpretation          CS: 'MONOCHROME2'
(0028, 0010) Rows                                US: 146
(0028, 0011) Columns                             US: 146
(0028, 0030) Pixel Spacing                       DS: [1.0, 1.0]
(0028, 0100) Bits Allocated                      US: 16
(0028, 0101) Bits Stored                         US: 16
(0028, 0102) High Bit                            US: 15
(0028, 0103) Pixel Representation                US: 0
(7fe0, 0010) Pixel Data                          OW: Array of 42632 elements

Thanks in advance.

Metadata

Metadata

Assignees

Labels

questionFurther information is requested

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions