Solved: Python convert dcm to png

The main problem with converting DICOM images to PNG is that the DICOM image format is not a standard image format. Many programs that can convert DICOM images to other formats cannot do so with PNGs.

import pydicom
import matplotlib.pyplot as plt

ds = pydicom.dcmread('filename.dcm') # read dicom image
image = ds.pixel_array # get image array
plt.imshow(image, # plot image using matplotlib

This code imports the pydicom and matplotlib.pyplot libraries, reads in a dicom image from a file, and displays the image using matplotlib.


DCM is a library for working with Digital Cinema Metadata. It provides a convenient way to access and manipulate the metadata of digital cinema files.

png and images

In Python, images are represented by the image module. Images can be read from files or loaded from memory.

To create an image in Python, you can use the Image() function. This function takes two arguments: the width and height of the image in pixels, and a file name or memory address where the image data is stored.

The following code creates an image named myimage with dimensions 512×512 pixels and stores the image data in memory at address 0x100000:

import Image myimage = Image(512, 512)“myimage.png”)

Related posts:

Leave a Comment