Problem displaying a monochrome image

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
echizen
Posts: 4
Joined: Thu, 2012-03-01, 15:44

Problem displaying a monochrome image

#1 Post by echizen »

Hi all.

I'm trying to display a monochrome image from it's pixel data value. I use both functions getOutputData() and findAndGetUint8Array to get pixels of the image, but when I display the image, I obtain a noisy and colored image that doesn't match with the original image as seen with a professional DICOM images viewer. The image that I get with getOutputData looks more like the original although it has a lot of noise and colors, but the second one doesn't look like the original at all. Do I need to do something like applying some LUT to the image to see the image in gray? I use Qt Framework. This is a fragment of code that can be useful. I will appreciate any help.

DicomImage *m_dicomImage;
unsigned long m_imageSize, size2;
DcmFileFormat fileFormat;
DcmDataset *dataset;
Uint8 *m_pixelData;
const Uint8 *char_pixelData;

OFCondition error = fileFormat.loadFile(fileName.toLatin1());
if (error == EC_Normal)
{
// load with default parameters
dataset = fileFormat.getDataset();

dataset->loadAllDataIntoMemory();
dataset->chooseRepresentation(EXS_LittleEndianExplicit, NULL);

E_TransferSyntax xfer = dataset->getOriginalXfer();
dataset->chooseRepresentation(xfer, 0);

// creating DICOM image
m_dicomImage = new DicomImage(dataset, xfer, 0);

if(m_dicomImage != NULL)
{
if(m_dicomImage->getStatus() == EIS_Normal)
{
m_imageSize = m_dicomImage->getWidth() * m_dicomImage->getHeight() * 4;
m_dicomImage->setMinMaxWindow();
}
}

m_dicomImage->getOutputData(m_pixelData, m_imageSize, 8);

if (dataset->findAndGetUint8Array(DCM_PixelData, char_pixelData, &size2).good())
{
// do something with pixels
}

QImage *image1 = new QImage(m_pixelData, m_dicomImage->width(), m_dicomImage->height(), QImage::Format_Indexed8);
QImage *image2 = new QImage(char_pixelData, m_dicomImage->width(), m_dicomImage->height(), QImage::Format_Indexed8);
}

Roadrunner
Posts: 56
Joined: Mon, 2010-06-14, 16:41

#2 Post by Roadrunner »

You forgot to use the search function of this forum. ;-)

viewtopic.php?t=799&highlight=qimage

The 4th post shows a way for creating a qimage - colored and gray scaled. All you nedd is a bit knowledge of C++ but if you develop with qt you have one. :-)

Hope this will help.

Frank

echizen
Posts: 4
Joined: Thu, 2012-03-01, 15:44

#3 Post by echizen »

Thanks very much for your fast answer Frank. Actually I did something like this before I send my post, but this only works fine for pixels obtained with getOutputData function. This image looks good, but the second not, even if I do the same. The closest image to the original that I could obtain using findAndGetUint8Array function was changing the original line:

QImage *image3 = new QImage(pixels2, image->width(), image->height(), QImage::Format_Indexed8);
by
QImage *image3 = new QImage(pixels2, image->width(), image->height(), QImage::Format_RGB16);

In this case, I obtain a RGB image that match with the original, but with colors. In this case, neither using setColorTable function I could obtain the image in gray. My objective is to create an image from its pixel data, then modify the image including different annotations (texts, ROIs, etc.) and finally save the modified data in the DICOM image. I don't know if the way I'm using is the best for this. I think to use the function findAndGetUint8Array to get the pixels and putAndInsertUint8Array to save the new data in the dicom image. That's the reason for which I'm interested in display the image using findAndGetUint8Array function instead of getOutputData function, because I'm not sure that saving data obtained with getOutputData works fine. Tell me if you have a better idea. Thanks again.

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

#4 Post by J. Riesmeier »

First of all, you should check whether the created output of dcm2pnm/dcmj2pnm for this particular image is as expected.

Btw, the following lines from your code are probably not very useful for large multi-frame images:

Code: Select all

dataset->loadAllDataIntoMemory(); 
dataset->chooseRepresentation(EXS_LittleEndianExplicit, NULL);
And, the decompression in the second line is only necessary for the DcmItem::findAndGetUint8Array() approach but not for DicomImage::getOutputData().

Finally, your use of findAndGetUint8Array() is oversimplified. You cannot just put the OB values into an a QImage and "hope" that everything works well. This can/will only work for a very limited number of images (depending on their characteristics).

echizen
Posts: 4
Joined: Thu, 2012-03-01, 15:44

#5 Post by echizen »

Thanks very much, J. Riesmer for your answer. I checked the output for the image I want in BMP, PNG and TIFF formats using dcm2pnm just like you say. In all cases the output of the image is what I expect. The image is in gray like the original image seen with a professional dicom viewer.

The problem is when I display the image from the pixel data obtained with findAndGetUint8Array function. It is like the pixel data from getOutputData function aren't the same as the pixel data from findAndGetUint8Array function. In this case I obtain a blurred image with colors that doesn't look like the original.

Probably I've been something wrong to create the image or I'm missing some detail, but I don't know what it is. I'm new using DCMTK toolkit. I saw some examples in the forum and I tried to do something like that, but I don't get it what I want.

Thanks, anyway

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

#6 Post by J. Riesmeier »

Of course, using the PixelData value directly or feeding the image into the DicomImage class is not the same. The DicomImage class performs the whole rendering task that is required to display an image while findAndGetUint8Array() just gives you the OB values.
I checked the output for the image I want in BMP, PNG and TIFF formats using dcm2pnm just like you say. In all cases the output of the image is what I expect.
So, the problem is neither with the image nor with the DCMTK implementation, but with your code, right? Seems like your question/problem is more related to the correct use of Qt than to DCMTK.

Btw, regarding the palette color image (256 entries), the following note from the QImage (Qt) documentation might be interesting: "Note: Drawing into a QImage with QImage::Format_Indexed8 is not supported."

echizen
Posts: 4
Joined: Thu, 2012-03-01, 15:44

#7 Post by echizen »

Yes, you're right. I see that pixels of both functions are not the same. I was using QImage::Format_Indexed8 because with getOutputData it worked fine. I have to fix or modify my code to create the image. At least now, I have a hint to work.

Thanks very much for your help. If I do what I want, I post again with the final solution. It might help other people like me.

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 0 guests