RGB pixel value

All other questions regarding DCMTK

Moderator: Moderator Team

Message
Author
paolom
Posts: 169
Joined: Tue, 2008-09-16, 15:02

RGB pixel value

#1 Post by paolom »

Hi,

I need to obtain the RGB value of a RGB DICOM Image pixel.

I've my DicomImage and I create my Canvas Image with getOuputData() function. The problem is that I lost the original pixel data when I scale my Canvas Image.

With MONOCHROME DICOM image I can get the original pixel value with getInterData().

How can I obtain the original RGB pixel data from my DicomImage ?

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

#2 Post by J. Riesmeier »

I'm sorry but I don't understand the background of your question. Basically, getInterData() also allows for accessing color (RGB) images. However, I'm not sure that I would recommend that depending on your use case.

paolom
Posts: 169
Joined: Tue, 2008-09-16, 15:02

#3 Post by paolom »

Sorry, but the getInterData() return the first array of RGB value.

I think that for RGB Dicom Image I need to get the getInterDataArray() but I can't use this function.

Is it correct ?

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

#4 Post by J. Riesmeier »

No, getInterData() returns a pointer to an DiPixel object which has various get methods. For color images, you get direct access to the internal pixel data array:

Code: Select all

    /// pointer to pixel data (3 components)
    T *Data[3];
I know that I already wrote that many times in other similar postings: getInterData() is not the preferred way of accessing the pixel data. This "hack" has only been introduced because many people asked for direct access to "raw data" of CT images (i.e. Hounsfield Units). I don't see any use case for color images (unless you convince me).

paolom
Posts: 169
Joined: Tue, 2008-09-16, 15:02

#5 Post by paolom »

Yes, I'm sorry....

the getInterDat() returns a DiPixel * which has:

getData() to retrieve a pointer to pixel data.

I've seen that for RGB images this pixelData has the size of ( image->width() * image->height()), so I've seen that this pixelData is not the complete array of all RGB pixel data ( but only the first plane).

The getDataArrayPtr() get pointer to array of pixel data. The number of planes in the returned array can be determined using 'getPlanes()'.

I think this is the correct array of all three RGB planes....but I can't use the getDataArrayPtr().

I use the getInterData() to get the value of Monochrome DICOM Images, but I can't for RGB images.

So my question is....to get the RGB value of the nth pixel of a RGB Dicom image...which is the correct procedure ?

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

#6 Post by J. Riesmeier »

Why don't you use getOutputData()? This is what the DicomImage is for: rendering of DICOM images.

paolom
Posts: 169
Joined: Tue, 2008-09-16, 15:02

#7 Post by paolom »

I use the getOutputData to obtain the pixelData of the DICOM Image.

I use this pixel data to create my canvas image.

I make some operation to this canvas image ( for instance, I zoom the canvas and I apply some smoothing to it), so I lost the original pixel data.

The problem is that If I get the nth RGB pixel value to the smoothed canvas image, I don't obtain the same value to the original RGB Image.

So, If I want to know the original RGB pixel data, I've only the DicomImage reference and I don't want to use getOutputData() ( I want to avoid the memory allocation of another pixel data).

The DicomImage internally has a reference of its pixel data...so I want to obtain this...

I'm very sorry for my bad English...I hope you can understand my problem!

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

#8 Post by J. Riesmeier »

Why don't you then store a copy of the original getOutputData() result and delete the DicomImage?

You wrote in a previous posting:
I think this is the correct array of all three RGB planes....but I can't use the getDataArrayPtr().
Why can't you do that?

paolom
Posts: 169
Joined: Tue, 2008-09-16, 15:02

#9 Post by paolom »

In your opinion,

can I take the same pixel data from DicomImage to Canvas Image?

I need to not duplicate the pixel data to render a DicomImage with Canvas...

Is it possible with

inline const void getOutputData() ???

Many thanks

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

#10 Post by J. Riesmeier »

Unfortunately, I don't know what the requirements for your "Canvas Image" are because you never told us. I'm sorry but I still have no idea what you are talking about. What about providing more background information?

paolom
Posts: 169
Joined: Tue, 2008-09-16, 15:02

#11 Post by paolom »

Ok,

I'm using Qt, and to display an image to screen I use a Qt class, named QImage.

To create a QImage I used the pixel data ( void buffer * )get from a DicomImage:

Code: Select all

    inline int getOutputData(void *buffer,
                             const unsigned long size,
                             const int bits = 0,
                             const unsigned long frame = 0,
                             const int planar = 0)
but in this mode I've two pixel data ( one of the DicomImage and one of the QImage ) . I want to have only a pixel data, but maintain both DicomImage and QImage.

Do you think is it possible?

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

#12 Post by J. Riesmeier »

Why don't you use the getOutputData() method where you can provide an externally allocated and managed memory buffer?

paolom
Posts: 169
Joined: Tue, 2008-09-16, 15:02

#13 Post by paolom »

I use this function ( as you can see from my previous post )....

but the buffer that I need to allocate must be valid for all the QImage life.

So, to display my QImage in this mode, I've two pixel data array, one of the DicomImage and one of the QImage ( the buffer that I allocate).

I want to have only one pixel data and maintain both DicomImage and QImage.

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

#14 Post by J. Riesmeier »

but the buffer that I need to allocate must be valid for all the QImage life.
Ok, but you do not need to re-allocate the memory buffer each time you call getOutputData(). This only has to be done once for each image (of a particular size).

I'm not sure about the Qt-related part of your question because I didn't use Qt in the last couple of years.

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

#15 Post by Roadrunner »

@paolom: if you would use the search function in this forum and search for QImage you would find some code snips. ;-)

Frank

Post Reply

Who is online

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