问题
I'm using DCMTK for a C++ project and want to retrieve pixels from dicom files. I used thid basic example :
DicomImage *image = new DicomImage("test.dcm");
if (image != NULL)
{
if (image->getStatus() == EIS_Normal)
{
if (image->isMonochrome())
{
image->setMinMaxWindow();
Uint8 *pixelData = (Uint8 *)(image->getOutputData(8 /* bits */));
if (pixelData != NULL)
{
/* do something useful with the pixel data */
}
}
} else
cerr << "Error: cannot load DICOM image (" << DicomImage::getString(image->getStatus()) << ")" << endl;
}
delete image;
in "do something useful with the pixel data" section , how can I use pixelData variable to get pixels
回答1:
First of all: you already have the pixel data as an array of unsigned chars. You could - for example - transfer them to an 8-bit monochrome bitmap and display them on the screen. The height and width you need to construct the bitmap can be obtained from the DicomImage object
However, it strongly depends on what you consider "something useful" whether getOutputData() is the method of your choice. This is because getOutputData() is acually kind of a rendering method. Assumed, that you have a typical CT, MR or CR image, the grayscale range has alread been rescaled to 8-bit.
You might prefer to extract the pixel data in the full grayscale range and roll your own rendering and processing methods. In this case I would advise you to use getInterData() which returns the internally stored pixel data with the full grayscale range. The Modality LUT has been applied to the intermediate data so what you get is an encapsulation (class DiPixel) of an array of values each of which encodes the grayscale value measured by the device (e.g. Hounsfield Units in case of CT).
DiPixel returns these grayscales as a void pointer. To correctly handle the values, you need to determine their respresentation (e.g. Uint8, Sint16, ...).
Using this approach is obviously more effort, but for anything that goes beyond rendering the pixel data, it is the only approach that preserves the original gray values
来源:https://stackoverflow.com/questions/38258460/dcmtk-c-how-to-get-data-pixels-from-dicom-files