Page 1 of 1

retrieving R G B values from an image

Posted: 2019-09-20T06:20:14-07:00
by vasan.shrini
I am using ImageMagick++ 6.9.10. I am trying to read an image and get the R, G, B values. In whichever way I try, I always get the same values for the green and blue channels. Below is a sample code that illustrates the problem:

Magick::Image img_one('test.jpg');
Magick::ColorRGB img_one_px(img_one.pixelColor(10, 10)); // can be any pixel location in the image
cout << img_one_px.red() << " " << img_one_px.green() << " " << img_one_px.blue() << endl;

Irrespective of the pixel we choose in the second line above, the code always prints the same value for green() and blue(). I feel this is a bug that needs fixing. Please correct me if I am going wrong somewhere.

Re: retrieving R G B values from an image

Posted: 2019-09-20T06:41:21-07:00
by snibgo
You have already asked this question, so I have deleted the other one. Please don't multipost. You can always bump threads if you feel the need.

It might help if you showed a complete reproducible example: a full but minimal program, and the input image.

Re: retrieving R G B values from an image

Posted: 2019-09-20T07:08:21-07:00
by vasan.shrini
Thanks for your response and appologies for reposting. I posted here because in the other forum I found all other posts to be related to command line tool. I found this place more relavant to Magick++.

The problem happens for any image. We can reproduce the problem by simply reading an image as part of any program. First, read any image by providing its absolute path such as below:

Magick::Image img_one; img_one('~/Desktop/test.png');

And then choose a pixel say at x and y locations (5,5) as:

Magick::ColorRGB img_one_px(img_one.pixelColor(5, 5));

Finally, retrieve the R,G,B values for that pixel and print it:

cout << img_one_px.red() << " " << img_one_px.green() << " " << img_one_px.blue() << endl;

You will notice that the G and B values are always the same indicating that Magick++ is returning the intensities of the same channel for both instead of the respective channel intensities.

Hope that clarifies. Thanks again for looking into it.

Re: retrieving R G B values from an image

Posted: 2019-09-20T07:45:08-07:00
by snibgo
That is not a complete but minimal program. I can't paste it into a file, compile and run it.