Kuni
Kuni

Reputation: 865

pydicom is not defined

I'm trying to learn how to use pydicom for reading and processing dicom images. I'm using Python 3.

import dicom 
import numpy
ds = pydicom.read_file(lstFilesDCM[0])
print(ds.pixel_array)`

I get an error NameError: name 'pydicom' is not defined. If I change

   ds = pydicom.read_file(lstFilesDCM[0])

to

   ds = dicom.read_file(lstFilesDCM[0])

(using dicom.read_file instead), I get the following error:

NotImplementedError: Pixel Data is compressed in a format 
pydicom does not yet handle. Cannot return array

I also verified that pydicom is properly installed and updated.

How do i fix this?

Upvotes: 0

Views: 2678

Answers (2)

Roland Smith
Roland Smith

Reputation: 43495

If you want to get your hands on the pixel data, I suggest to use the convert program from the ImageMagick suite. You can either call this program from Python using the subprocess module. (See this example, where I convert them to JPEG format), or you can use one of the Python bindings.

If you want to manipulate the images, using the bindings might be preferable. But note that not all the bindings have been converted to ImageMagick version 7.

Upvotes: -1

seralouk
seralouk

Reputation: 33127

You are trying to call a class that you have not imported before:

Use:

import pydicom
import numpy


ds = pydicom.read_file(lstFilesDCM[0])
print(ds.pixel_array)

or

import dicom
ds = dicom.read_file("the_name_of_file.dcm")

Documentation: http://pydicom.readthedocs.io/en/stable/pydicom_user_guide.html

Upvotes: 2

Related Questions