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

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
LiloLilo

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

Post 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.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

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

Post by magick »

8-bit pixels are mapped to 16 by multiplying by 257.
LiloLilo

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

Post 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!
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

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

Post 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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
LiloLilo

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

Post 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
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

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

Post 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
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

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

Post 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!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

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

Post 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
LiloLilo

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

Post by LiloLilo »

So, I'll need to manually divide by 257 each pixel of the image to get back the original values?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post by fmw42 »

when processing your image, you can force it to 8-bits by adding -depth 8
Post Reply