DICOM Pixel values

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
matteo
Posts: 10
Joined: Thu, 2014-09-18, 10:54

DICOM Pixel values

#1 Post by matteo »

Hi All,
I would want to read a DICOM image and to save the matrix of raw pixel intensities in a txt file. Running the following code everything works fine with DICOM images that have a pixel representation = EPR_Uint16 (so I think it corresponds to BitsAllocated = 16):

Code: Select all

  string fin="mydicom.dcm"
    DicomImage *image = new DicomImage(fIn.c_str());
    int width = (int)image->getWidth();
    int height = (int)image->getHeight();

    if (image->getStatus() == EIS_Normal){
        const DiPixel *pixeldata = image->getInterData();
        Uint16 *pd = (Uint16*)pixeldata->getData();
        if (pixeldata != NULL){
            /*create the ASCII file*/
            fstream rawData;
            string rawDataFielName = "out.txt";
            rawData.open(rawDataFielName.c_str(), ios::out);
            
            for (int i=0; i< width*height;i++) {
                rawData << pd[i] << "    " ;

                if (i % width == 0 && i != 0) {
                    rawData << endl;
                }
            } 
        }
    } else
        CERR << "cannot load file: " << fIn << endl;
The problem arises whit DICOM images that have a representation = EPR_Uint8. In this case I would aspect to obtain pixel values that range between 0-255, but I get also values greater than 255. Is it correct?
If in the above code I replace:

Code: Select all

        Uint16 *pd = (Uint16*)pixeldata->getData();
with

Code: Select all

        Uint8 *pd = (Uint8*)pixeldata->getData();
I didn't obtain pixel values but .

Any help?

Thanks,

regards.

Matteo

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

Re: DICOM Pixel values

#2 Post by Michael Onken »

Hi Matteo,

from all what I know you always receive 8 bit data when you have an internal representation like EPR_Uint8.

Best,
Michael

Post Reply

Who is online

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