Page 1 of 1

Loading a 24 bit RGB image using Q16 will change pixel value

Posted: 2008-07-28T08:33:53-07:00
by LiloLilo
Hi,

If I load a 24 bit RGB image (suppose a PNG) using the Q16 library, how will be mapped the values [0-255] of each pixel in memory? For example, suppose Pixel(0,0) is RGB(10,10,20). Once loaded in memory using Q16, I'll found again (10,10,20) or other values?

I tryied to print on screen a pixel value using cout << pSourceImage->red and I got a value > 34000!

Thank you.

Re: Loading a 24 bit RGB image using Q16 will change pixel value

Posted: 2008-07-28T09:06:46-07:00
by magick
8-bit pixels are mapped to 16 by multiplying by 257.

Re: Loading a 24 bit RGB image using Q16 will change pixel value

Posted: 2008-07-29T00:24:18-07:00
by LiloLilo
magick wrote:8-bit pixels are mapped to 16 by multiplying by 257.
Thank you. Why this conversion take place? Isn't it more simple to copy the values as is? So, as I'll need to use also the HDR library, what conversion will be done in that case?

Thank you!

Re: Loading a 24 bit RGB image using Q16 will change pixel value

Posted: 2008-07-29T00:53:07-07:00
by anthony
A Q16 compiled IM defines the internal data structure used to hold and process the image. All images being read in will need to map to this data structure and thus that internal quality standard. Many operations need the extra quality provided by 16 bit values. For some operations you need to use HDRI floating point quality for internal storage.

of course if you are just converting images (as many Window users do) a Q8 version of IM will be faster, and then the input will be represented in memory as 8 bit values, but some operators may show 'quantum rounding effects', especially when multiple operations and color enhancements are being applied to the same in-memory image.

See IM Examples, Basics section on Quality and Depth.

Re: Loading a 24 bit RGB image using Q16 will change pixel value

Posted: 2008-07-29T01:38:29-07:00
by LiloLilo
anthony wrote:A Q16 compiled IM defines the internal data structure used to hold and process the image. All images being read in will need to map to this data structure and thus that internal quality standard. Many operations need the extra quality provided by 16 bit values. For some operations you need to use HDRI floating point quality for internal storage.

of course if you are just converting images (as many Window users do) a Q8 version of IM will be faster, and then the input will be represented in memory as 8 bit values, but some operators may show 'quantum rounding effects', especially when multiple operations and color enhancements are being applied to the same in-memory image.

See IM Examples, Basics section on Quality and Depth.
Is there any method or setting in the library that will revert back manually or automatically every pixel to the original value (/257) without having to do in manually one by one? I don't need to do any modification on loaded images, but only to read pixel to do some calculations. As I'll use 8bit and 16bit images, I need Q16, but it would be userful to have 8 bit images loaded with pixel values "as is" using Q16.

Thank you

Re: Loading a 24 bit RGB image using Q16 will change pixel value

Posted: 2008-07-29T16:04:56-07:00
by el_supremo
magick wrote:8-bit pixels are mapped to 16 by multiplying by 257.
Why 257? I would have expected it was 256.

Pete

Re: Loading a 24 bit RGB image using Q16 will change pixel value

Posted: 2008-07-29T19:32:19-07:00
by anthony
It is 257 because you do not have a value of 256, QuantumRange (or MaxRGB) is 255.

As such to map an 8-bit 255 to 16-bit 65355 is multiply by 257.
In HEX this is #FF -> #FFFF and NOT #FF -> #FF00

If you only multiplied by 256 your white will become off-white!

Re: Loading a 24 bit RGB image using Q16 will change pixel value

Posted: 2008-07-29T20:38:21-07:00
by el_supremo
AHA. So instead of having an 8-bit intensity mapped from hex AB to a 16-bit AB00 (which is what I thought would be done), it maps to ABAB and this does indeed map to the right 16-bit intensity. Cool.

Pete

Re: Loading a 24 bit RGB image using Q16 will change pixel value

Posted: 2008-07-30T02:22:35-07:00
by LiloLilo
So, I'll need to manually divide by 257 each pixel of the image to get back the original values?

Re: Loading a 24 bit RGB image using Q16 will change pixel value

Posted: 2008-07-30T11:11:11-07:00
by fmw42
when processing your image, you can force it to 8-bits by adding -depth 8