Hello,
I’ve created a DICOM file using a Python script that processes a pixel array. This file opens without any issues in applications like Fiji and ezDICOM, indicating that the data is intact and correctly formatted according to the DICOM standard.
However, when I attempt to open this same file in 3D Slicer, I encounter an unspecified error, which prevents me from viewing or working with the file in that environment. This issue seems to be specific to 3D Slicer, as other DICOM-compatible software can read the file without any problems.
I’m seeking assistance or insights from anyone who might have faced similar challenges or has expertise in DICOM file compatibility with 3D Slicer. While I’m unable to attach the file here directly, I’m willing to share it privately if that helps in diagnosing the issue.
Python script:
import pydicom
from pydicom.dataset import Dataset, FileMetaDataset
from pydicom import uid
def save_dicom(image_dens, patName, patId):
file_meta = FileMetaDataset()
file_meta.MediaStorageSOPClassUID = uid.PYDICOM_IMPLEMENTATION_UID
file_meta.MediaStorageSOPInstanceUID = uid.generate_uid()
file_meta.ImplementationClassUID = uid.PYDICOM_IMPLEMENTATION_UID
ds = Dataset()
ds.file_meta = file_meta
ds.is_little_endian = True
ds.is_implicit_VR = True
ds.PatientName = patName
ds.PatientID = str(patId)
ds.Modality = 'CT'
ds.SeriesInstanceUID = uid.generate_uid()
ds.StudyInstanceUID = uid.generate_uid()
ds.FrameOfReferenceUID = uid.generate_uid()
ds.StudyDate = '20240101'
ds.StudyTime = '120000'
ds.Rows = image_dens.shape[0]
ds.Columns = image_dens.shape[1]
ds.PixelRepresentation = 1
ds.BitsStored = 16
ds.BitsAllocated = 16
ds.SamplesPerPixel = 1
ds.HighBit = 15
ds.PhotometricInterpretation = "MONOCHROME2"
ds.PixelData = image_dens.tobytes()
ds.save_as("output.dcm")
Thank you very much for your time and help.