Page 1 of 1

Trouble setting RGB color depth

Posted: 2011-01-19T19:52:43-07:00
by bmesich
Hello and good evening,

Relatively new to using the Magick++ API and I'm running into problem setting the RGB color depth of an image I'm reading in. The image is 24 bit encoded RGB, but the Magick++ API is returning pixel values that are 48 bit encoded. Below is an example of what I doing;

Code: Select all

image.read("image.jpeg");
pix = image.pixelColor(10,10);
red = pix.redQuantum();
im_depth=image.depth();
fprintf(stdout,"Color depth: %u\n",im_depth);
fprintf(stdout,"Red value: %u\n",red);


In this case, red has a value of 65,536 and depth is 8. I would like the values to be 24 bit encoded (i.e. values 0 - 256), but can't seem to find a way to do this. Reading through the documentation it seems Magick might store the RGB values in memory differently than what the image is saved in. I've seen mention of QuantumDepth that is defined at compile time and am guessing this is what is causing the difference.

Any help would be appreciated.

Bryan

Re: Trouble setting RGB color depth

Posted: 2011-01-19T19:57:20-07:00
by fmw42
I know little about Magic ++, but if you are on Q16 IM, then the max value you can have for any channel is 65,535 and not 65,536. If you have an RGB color image (not RGBA) and want it to be 24-bits (8-bits per channel), use the equivalent of -type truecolor and -depth 8.

What version of IM are you using and with what Quantumlevel compilation (Q8, Q16, Q32, HDRI)

In command line, you can get that info using

convert -version

or

identify -version

Re: Trouble setting RGB color depth

Posted: 2011-01-19T21:03:13-07:00
by bmesich
Hello,

The output of "convert -version" was:

Version: ImageMagick 6.5.1-2 2010-01-06 Q16 OpenMP http://www.imagemagick.org
Copyright: Copyright (C) 1999-2009 ImageMagick Studio LLC

I didn't compile IM myself, just using the RPM(s) that Fedora 11 ships with. Is there anyway to find the Quantumlevel at run time (the Q16 in the above output seems indicate this). If not I'll have to grab the source RPMs to get that info. FWIW, I'm running a 64-bit kernel/user space. As for the max channel value, you're absolutely correct. The value is 65,535. I'm guessing the corresponding 24 bit value would be 255?

I tried using the following based off your suggestion:

Code: Select all

image.read("image.jpeg");
image.type( TrueColorType );
image.depth(8);
But that didn't change the channel values. Valid image types can found here:

http://www.imagemagick.org/Magick++/Enu ... #ImageType

Maybe I'm using the wrong one?


Thanks for the quick reply,

Bryan

Re: Trouble setting RGB color depth

Posted: 2011-01-19T21:15:08-07:00
by anthony
The compile time quality level is what all image program in performed in. That is it.

Depth is only used for contolling the output (and for raw images input) file format. It does not change the proceesing of image values. If unset it defaults to the Q level or best depth available for that image file format. A Image read in will save its 'depth' as part of the image meta-data, so reading a 24 bit image (8 depth) will generally save a 24 bit image, unless the depth is reset (set to 0 or unknown depth)

Image processing functions that need to know what the value range is, and that is most image processing functions, should use the special constants QuantumRange ( a value of 2^Q-1, which is the value that should mean 'white') and QuantumScale whcih is a floating point number that is multiplied with a color value to normalize it into a 0.0 to 1.0 floating point range.

If you need values in 255 range, you need to divide by the appropriate amount. Which is QuantumScale*255. Note that this is a floating point value, it is not just a simple integer division of 256!

Note that image values are only stored in integers, and must be stored in QuantumRange scale. the only exception is a HDRI compiled IM, which stores values as floating point numbers but still retains the Q-level QuantumRange (typically 16 bit). In HDRI you can also have values that exceed 0 and Quantum Range (beyond normal black and white). When saving to HDRI complient image file formats an special flag may be needed and depth can control whether float or doubles are saved into the file.

See IM Examples, Basics, Quality and Depth of Images
http://www.imagemagick.org/Usage/basics/#depth

Re: Trouble setting RGB color depth

Posted: 2011-01-20T08:21:03-07:00
by bmesich
Thanks for the detailed replay. I understood everything up to where you mention QuantumScale. I don't see a way to get this floating point value. QuantumRange is defined in magick-type.h, but I couldn't find mention of it in the documentation or looking through the includes. I did however come across a function that is part of the Magick C API called ScaleQuantumToChar(). I was able to use this to covert my 16 bit digits to 8 bit (or so it seems to anyway).

How do I get the QuantumScale value for a particular color?

Re: Trouble setting RGB color depth

Posted: 2011-01-20T12:07:01-07:00
by fmw42
How do I get the QuantumScale value for a particular color?
Quantumscale has no bearing on any pixel color. It is a system constant defined according to the Q level. For Q16, the three constants: Qlevel Quantumrange and Quantumscale (which I believe is just the inverse of quantumrange) can be found in command line mode as

convert xc: -format %q info:
16

convert xc: -format "%[fx:quantumrange]" info:
65535

convert xc: -format "%[fx:quantumscale]" info:
1.5259e-05