Project

General

Profile

Actions

Basics of displaying DICOM images

I won't go into too much detail, however I will point you in the directions you will need to understand how DICOM pixel data can be represented as a grey scaleimage. This assumes you know the basics of the structure of a DICOM file.

The first thing you should familiarise yourself with is the Pydicom library. It's fairly straightforward. You can read in a DICOM file from a given filepath, and the library will create an object used to represent the DICOM file. In terms of imaging, the most important data element is the Pixel Data. The pixel array doesn't contain colour information, it actually stores the raw Hounsfield unit of each point on the imaged plane. Each of these units represents the density of the point, where -1000 units represents the density of air, and 0 units represents the density of water.

In order to convert an dataset made up entirely of Hounsfield into an image viewable on a computer (which has a grey scale represented by a number from 0-255), you will need to understand two very important numbers: Window and Level . These two numbers control what you can and can't see in the resulting grey scale image. Useful videos to assist in understanding these numbers are:
https://www.youtube.com/watch?v=KEqI3SytlTc
https://www.youtube.com/watch?v=A5aqQwipju8

With this information, given a DICOM image and a window/level, you should be able to convert a DICOM image's pixel data into a grey scale image using a small amount of maths.

You can take a look at how OnkoDICOM approaches this for an example of how it can be done. Note that OnkoDICOM works with multiple DICOM images and therefore some functions are not replicable one-to-one for displaying just a single DICOM image.
https://github.com/didymo/OnkoDICOM/blob/master/src/Model/InitialModel.py#L65 - the starting line of where the pixel images are created from the given DICOM datasets.
https://github.com/didymo/OnkoDICOM/blob/cfab3aefb1427ab251a5de3df1b04d729ecd4b5d/src/Model/CalculateImages.py#L5 - conversion of the Pydicom Dataset.pixel_data into a numpy array.
https://github.com/didymo/OnkoDICOM/blob/cfab3aefb1427ab251a5de3df1b04d729ecd4b5d/src/Model/CalculateImages.py#L74 - conversion of numpy array into a PyQt Pixmap using the set window and level.

Updated by Peter Qian about 4 years ago · 1 revisions