retrieving R G B values from an image

Magick++ is an object-oriented C++ interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick++.
Post Reply
vasan.shrini
Posts: 2
Joined: 2019-09-12T08:35:12-07:00
Authentication code: 1152

retrieving R G B values from an image

Post by vasan.shrini » 2019-09-20T06:20:14-07:00

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.

snibgo
Posts: 12152
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: retrieving R G B values from an image

Post by snibgo » 2019-09-20T06:41:21-07:00

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.
snibgo's IM pages: im.snibgo.com

vasan.shrini
Posts: 2
Joined: 2019-09-12T08:35:12-07:00
Authentication code: 1152

Re: retrieving R G B values from an image

Post by vasan.shrini » 2019-09-20T07:08:21-07:00

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.

snibgo
Posts: 12152
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: retrieving R G B values from an image

Post by snibgo » 2019-09-20T07:45:08-07:00

That is not a complete but minimal program. I can't paste it into a file, compile and run it.
snibgo's IM pages: im.snibgo.com

Post Reply