PDA

View Full Version : QImage - Get the RGB component of a certain pixel



fabietto
1st July 2011, 15:44
Hi everyone,

I'm stuck with an issue that looks quite stupid to me. Nonetheless I don't seem to be smart enough to solve it... :/

What I'm trying to do is simply to read the RGB values of a pixel contained in a QImage. To do so I'm using the following instructions:


X = rand() % originalImage.width();
Y = rand() % originalImage.height();

QRgb tempColorRgb = originalImage.pixel(QPoint(X,Y));
QColor tempColor(tempColorRgb);

printf("RGB components of the pixel selected: %d %d %d\n", tempColor.red(), tempColor.green(), tempColor.blue());


What I get is that all the values look the same, whatever pixel I select. For example:

RGB components of the pixel selected: 0 0 0
RGB components of the pixel selected: 241 241 241
RGB components of the pixel selected: 27 27 27

OriginalImage is a QImage declared and initialised elsewhere in the code. It actually contains a jpeg picture loaded from the disk. I'm confident there's nothing wrong with it, as it is visible (it's displayed on my GUI) and accessible from the code above (I tried to save it with an instruction in the portion of the code below and everything went fine).

Am I doing something obviously and terribly wrong which I can't notice? :mad:

mcosta
1st July 2011, 15:57
Can you send your image??

fabietto
1st July 2011, 16:22
Sure. Didn't think that was an issue concerning the image, but in case that might help... here we go:
http://www.fabioruini.eu/Plymouth/downloads/censorship.jpg

It is loaded into a QImage just using the function:


originalImage.load(picturePath);

where picturePath is a QString that I get from a lineEdit on the GUI. Its format (as returned by originalImage.format()) is RGB32.

Added after 14 minutes:

The problem was the image indeed! Thanks for the hint!

mcosta
1st July 2011, 16:40
Your image use only gray scale colors, so its normal that RGB components have the same values.

I changed your image to colored

6621

and the result is

6622

PS. Are you Italian??