Linearizing RGB after conversion from YCbCr rec709 transfer

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?".
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: Linearizing RGB after conversion from YCbCr rec709 trans

Post by glennrp »

anthony wrote:WARNING: IM will automatically convert from a linear RGB image marked sRGB to non-liear form when saving to some file formats like PNG This can confuse things.
The IM PNG encoder doesn't do any colorspace conversion. If you have a linear RGB image incorrectly marked sRGB, then the PNG encoder will write the linear RGB image, but will also write the sRGB chunk. Then any viewer or decoder that understands the sRGB chunk will do the conversion (actually will not do any conversion when it thinks the image and screen are both sRGB) and the display will be wrong. If you have such an incorrectly marked PNG, you can simply replace the sRGB chunk with a "gAMA 100000" chunk using "convert +gamma 1.0" to inform decoders that the image is linear RGB and needs to be converted for display.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Linearizing RGB after conversion from YCbCr rec709 trans

Post by anthony »

I would generate a linear greyscale, (in the linear sRGB (sic) colorspace of IM), and convert that to rec709 and see how it turns out. It quickly becomes pretty obvious if the grayscale is being display in a linear or non linear fashion.

For example the right way of generate a linear greyscale, whcih is stored in sRGB colorspace is...

Code: Select all

   convert -size 100x100 gradient: -set colorspace sRGB -colorspace RGB sRGB_gradient.gif
Image
The resulting image has a gradient that, has much brighter mid-tones and much more linear appearance (equal amonts of white and black) than you would get if the sRGB colorspace conversion was not done.

In contrast a directly saved linear gradient has much more black than white colors. for example

Code: Select all

  convert  -size 100x100 gradient:  gradient.jpg
Image
See Gradients of Color
http://www.imagemagick.org/Usage/canvas/#gradient

In fact this makes a very good example for IM examples on just what colorspace actually does, and I probably should write it up in the 'Color Basics' area.


ASIDE: running that sRGB image though the builtin -auto-gamma (no yet documented in IM Examples :-( ) operator removes the gamma effect, generating (roughly) linear values again! The operator performs a gamma modification so as to set the average value to 50%, effectively removing general gamma-effects from an image, though it does not change 'colorspace'.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply