Masrawy
Masrawy

Reputation: 33

Convert DICOM to TIFF

I'm new to Python so forgive my ignorance If I don't have all the info correct. I'm trying raster through a directory and convert all the DICOM files within to TIFF files. I have gotten the search functionality to work, but I am having a hard time saving the images as TIFFs. I'm using the pydicom libraries to read in the DICOM and manipulate the header information. Also, I have tried using the save_as function in pydicom to save to TIFF, but I would rather use the save function in PIL to properly set the compression of the TIFF. I think the problem is that I can't/don't understand how to extract the actual image data from a DICOM and place it in a new image.Any Help would be greatly appreciated ... Cheers

Python 2.7 PIL 1.1.7 Pydicom 0.9.6

Upvotes: 3

Views: 8488

Answers (2)

Revati Joshi
Revati Joshi

Reputation: 183

Found an answer online to the same query sometime back, although I don't remember the site but as I applied it to my code, sharing it here for others as well :

 import pylab
 import dicom
 ImageFile=dicom.read_file(<SourceFilePath>) #Path to "*.dcm" file
 pylab.imshow(ImageFile.pixel_array,cmap=pylab.cm.bone) #to view image

or if you want to save the image then instead use: pylab.imsave('<DestinationFilePath>',ImageFile.pixel_array,cmap=pylab.cm.bone)

The imsave will by default save the image in .png format though. You can specify the desired format in the imsave() if it is supported.

Hope it is useful.

Upvotes: 4

Misha Akovantsev
Misha Akovantsev

Reputation: 1825

If you know how to use PIL to save image data as .tiff, this example should help you to pass image data from pydicom to PIL (there is more here in the comments).

Upvotes: 0

Related Questions