Access uncompressed pixel data

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
karatystas
Posts: 20
Joined: Fri, 2016-02-19, 08:51

Access uncompressed pixel data

#1 Post by karatystas »

I want to read raw (uncompressed) pixel data. I have a DICOM image and try this:

Code: Select all

DcmFileFormat dfile;
	dfile.loadFile("test.dcm");
	DcmDataset * data = dfile.getDataset();
	const Uint16 * element = NULL;
	data->findAndGetUint16Array(DCM_PixelData, element);
However, the values extracted from the element are much lower than it should be (I've checked with other software the pixel values). Does it give me compressed data?

Michael Onken
DCMTK Developer
Posts: 2048
Joined: Fri, 2004-11-05, 13:47
Location: Oldenburg, Germany
Contact:

Re: Access uncompressed pixel data

#2 Post by Michael Onken »

Hi,

check the transfer syntax of the file to see whether it is compressed (e.g. using dcmdump).

Note that Pixel Data usually not contains the pixel values ready for display, instead the DICOM rendering pipeline has to be applied to each of them. This includes the so-called "Modality LUT" and Windowing; look for typical attributes like Rescale Slope and Rescale Intercept, and/or Window Level and Window Width (list not complete)

In DCMTK, the DicomImage class performs this task. Call getOutputData() on DicomImage in order to get rendered pixel data values with applied rendering pipeline.

The tool dcm2pnm also uses DicomImage to convert DICOM pixel data to general-purpose image formats like BMP which may also be helpful to check the image.

Best,
Michael

karatystas
Posts: 20
Joined: Fri, 2016-02-19, 08:51

Re: Access uncompressed pixel data

#3 Post by karatystas »

The transfer syntax is: Little Endian Explit. Does it mean it is compressed? I have also tried to load with DicomImage and use getOutputData() but the values were too high in this case.

Michael Onken
DCMTK Developer
Posts: 2048
Joined: Fri, 2004-11-05, 13:47
Location: Oldenburg, Germany
Contact:

Re: Access uncompressed pixel data

#4 Post by Michael Onken »

Hi,

Little Endian Explicit is uncompressed.

It is very unlikely that DicomImage's getOutputData() is wrong (since it is heavily used for a long time). Note that the Windowing step in the rendering pipeline can be influenced by the user, e.g. try "setMinMaxWindow()" on DicomImage() before calling getOutputData().

Also, maybe consider your expectations are wrong...

Best,
Michael

karatystas
Posts: 20
Joined: Fri, 2016-02-19, 08:51

Re: Access uncompressed pixel data

#5 Post by karatystas »

Tried what you said and got even higher pixel values, over 40k in intensity. The problem is that if I load the image with Sante Dicom viewer and I check the pixel values they are different from what I get here. I have also tried another software to check the pixel values and was same as with Sante Dicom viewer. If the maximum pixel intensity value according to those softwares is 1991, here, with DCMTK I get only 332.

Michael Onken
DCMTK Developer
Posts: 2048
Joined: Fri, 2004-11-05, 13:47
Location: Oldenburg, Germany
Contact:

Re: Access uncompressed pixel data

#6 Post by Michael Onken »

Hi,

you should look into part 3 of the standard and check the details about what is actually stored in your DICOM file (check SOP Class in dcmdump and look for the related IOD in part 3).

Without, you (and I) don't know whether the values you are looking for are raw values, rendered values, or something else.

Best,
Michael

karatystas
Posts: 20
Joined: Fri, 2016-02-19, 08:51

Re: Access uncompressed pixel data

#7 Post by karatystas »

But if use getMinMaxValues() it gives me the right values - min = 0 and max = 1991.

Michael Onken
DCMTK Developer
Posts: 2048
Joined: Fri, 2004-11-05, 13:47
Location: Oldenburg, Germany
Contact:

Re: Access uncompressed pixel data

#8 Post by Michael Onken »

You can also try setNoVoiTransformation().

But again, you must find out how the object (type of image) you are interested in works and then you can decide how to get the data you are interested in. Lookup the IOD in part 3 and read through the modules listet. Otherwise it's just guessing in the dark.

Best,
Michael

J. Riesmeier
DCMTK Developer
Posts: 2501
Joined: Tue, 2011-05-03, 14:38
Location: Oldenburg, Germany
Contact:

Re: Access uncompressed pixel data

#9 Post by J. Riesmeier »

Calling setNoVoiTransformation() is usually not needed since this is the default. I would rather call setMinMaxWindow() if you are interested in an automatically "windowed" version of the stored pixel data... this is also what getMinMaxValues() returns by default (see documentation). Of course, the output pixel range also depends on the bit depth that is passed to getOutputData().

I can only suggest: read the DICOM standard (in order to understand what "VOI windowing" and the like is) and read the DCMTK documentation (to understand which methods need to be called).

karatystas
Posts: 20
Joined: Fri, 2016-02-19, 08:51

Re: Access uncompressed pixel data

#10 Post by karatystas »

I think I have found the solution:

Code: Select all

DicomImage * image = new DicomImage("test.dcm");
const DiPixel * pix = (image->getInterData());
EP_Representation rep = pix->getRepresentation();
if (rep == EPR_Uint16) {
     Uint16 * pixelData = (Uint16 *)pix->getData();
}
It gives me the right values of pixel data as all other software. However, I'm not sure if I use getRepresentation() correctly for type casting. Is it the only way to type cast it using if/switch statements as I did?

Michael Onken
DCMTK Developer
Posts: 2048
Joined: Fri, 2004-11-05, 13:47
Location: Oldenburg, Germany
Contact:

Re: Access uncompressed pixel data

#11 Post by Michael Onken »

Hi,

The typecast is fine.

Best
Michael

P.S: Btw, getInterData() returns the pixel data with Modality but no Windowing transformations applied.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 1 guest