difference open image with pydicom or sitk

Hello everybody,
I tried to open a DICOM image with sitk.ReadImage. I don’t have any error message, so I can see the image with plt.imshow, but all the pixels of the image are equal to 0.

If I try to open the same image with pydicom, I don’t have any problem to visualize the image, and the pixel values are different from 0.

I don’t know why I can’t read this image with sitk.ReadImage.

Have you ever experienced this problem? Do you have a solution, so I can read my DICOM image with sitk. ReadImage ?

Thank you in advance for your answers.

It is hard to give any advice without the image in question, or at least its description (key tags). The exact code snippet you used for reading would be helpful too.

PT000073.dcm (314.7 KB)

You can find attach my image and the code below:

SITK:
filename1=‘PT000073.dcm’
image = sitk.ReadImage(filename1)
image_cast = sitk.Cast(image[:,:,0], sitk.sitkInt32)
img_arr = sitk.GetArrayFromImage(image_cast)
plt.imshow(img_arr)

pydicom:
filename=‘PT000073.dcm’
ds = dcm.read_file(filename)
img_arr = ds.pixel_array[100:300,100:300]
plt.imshow(img_arr)

Having looked at your image the result is not surprising. The original image is floating point (float64) with values in [0,1]. You cast it to int32, so all pixel values go to zero.

Try it without the cast (I’d also set the visualization colormap to gray as the default is viridis):

image = sitk.ReadImage(filename1) 
img_arr = sitk.GetArrayFromImage(image[:,:,0]) 
plt.imshow(img_arr) 
2 Likes