Reputation: 105
I am writing a simple code to read dicom images, But it gives me an error when i try to displaying it whith matplotlib here is my code :
import pydicom
import matplotlib.pyplot as plt
ds = pydicom.dcmread("C:/Users/A763194/Desktop/Cone beam/IMG.dcm") # plan dataset
print(ds.PatientName)
print(ds.Rows)
print(ds.Columns)
plt.imshow(ds.pixel_array)
I expect the output of Images dicom, but it gives the error below :
TypeError: Invalid shape (601, 601, 601) for image data
Upvotes: 1
Views: 487
Reputation: 125
Just change last line to:
plt.imshow(ds.pixel_array.mean(axis=0))
Upvotes: 4