Python Forum

Full Version: Dicom image reading
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi all

I am trying to read a dicom image. The image has 49 frames. The PixelData has some bytes in the array. But the pixel_array is not working. Please guide me on how to display the multiple frames from .dcm image?
import matplotlib.pyplot as plt
import pydicom

dataset = pydicom.dcmread('bscan.dcm')
print("Storage type.....:", dataset.SOPClassUID)
print()

if 'PixelData' in dataset:
    rows = int(dataset.Rows)
    cols = int(dataset.Columns)
    print("Image size.......: {rows:d} x {cols:d}, {size:d} bytes".format(
        rows=rows, cols=cols, size=len(dataset.PixelData)))
    if 'PixelSpacing' in dataset:
        print("Pixel spacing....:", dataset.PixelSpacing)

plt.imshow(dataset.pixel_array)
plt.show()
The above code gives the following output and error
Output:
Image size.......: 496 x 512, 24887296 bytes Pixel spacing....: [0.011606, 0.003872]
Error:
AttributeError: Unable to convert the pixel data as the following required elements are missing from the dataset: SamplesPerPixel
Thank you in advance for the help
Thank you for formatting my question on forum. I am using this forum for first time. I will ensure the same next time. I will check the entire error and edit it soon. Apologies.
No need for apologies. This was just a friendly reminder.