[Proposed docs for "-intensity" now in thread for approval.] When converting a grayscale image to color...
Posted: 2017-08-21T20:56:35-07:00
I'm not sure whether this is by design (perhaps undocumented?) or a bug.
The documentation for "-intensity" says that it determines how a grayscale image is calculated from a color image, and in some other cases when a single intensity needs to be calculated internally from three channel intensities.
But it seems that the result of converting a grayscale image to a color image (using -colorspace ...) can be different depending on the "-intensity" setting that happens to be in effect at the time of this conversion.
Just for example, here's a grayscale test image:
== myrosesgray.jpg
Now I'm reading it in, converting it to RGB, and then making a nearly-unnoticeable change to the blue channel:
== {rec709luma}myrosesgray.jpg_RGB_Bx0.99.jpg .
The result above looks essentially unchanged, as expected. (The result is the same for both rec601luma and rec709luma.)
Now doing the same thing except while a different intensity setting is in effect:
== {rec709luminance}myrosesgray.jpg_RGB_Bx0.99.jpg .
This time the result is lighter. This unexpected change to the image is the same for for both -intensity rec601luminance as well as rec709luminance settings.. The same result also occurs if I move the "-intensity ......luminance" from before the input filename to just after the input filename.
The above can be repeated with essentially the same results if we replace "-colorspace RGB" by "-colorspace sRGB", or even "-colorspace cielab":
Notice that the avg (nonlinear) value increases from 43% to 67%, corresponding to the incorrect (lighter) appearance.
This is approximately the ratio that would be expected from a transformation of the original grayscale image from gamma=.454545 to gamma=1.
One might describe the result this way: rec*luma and rec*luminance act as if they were two different colorspaces for grayscale images, quietly affecting whether the grayscale values are interpreted as linear vs nonlinear and thus the transformation that IM uses when transforming it to any other colorspace. Like a regular colorspace, the intensity setting is stored as a property of the image rather than merely a general session preference. With this intensity property, just as with a regular colorspace, intermediate colorspace transformations (like RGB or CIELab above) don't necessarily have an effect so long as in any case they all end up getting converted to sRGB in order to write the JPG file.
Is this a bug?
Or is this the expected behavior, and why?
The documentation for "-intensity" says that it determines how a grayscale image is calculated from a color image, and in some other cases when a single intensity needs to be calculated internally from three channel intensities.
But it seems that the result of converting a grayscale image to a color image (using -colorspace ...) can be different depending on the "-intensity" setting that happens to be in effect at the time of this conversion.
Just for example, here's a grayscale test image:
== myrosesgray.jpg
Now I'm reading it in, converting it to RGB, and then making a nearly-unnoticeable change to the blue channel:
Code: Select all
magick -intensity rec709luma myrosesgray.jpg -colorspace RGB -channel B -evaluate multiply 0.99 {rec709luma}myrosesgray.jpg_RGB_Bx0.99.jpg
The result above looks essentially unchanged, as expected. (The result is the same for both rec601luma and rec709luma.)
Now doing the same thing except while a different intensity setting is in effect:
Code: Select all
magick -intensity rec709luminance myrosesgray.jpg -colorspace RGB -channel B -evaluate multiply 0.99 {rec709luminance}myrosesgray.jpg_RGB_Bx0.99.jpg
This time the result is lighter. This unexpected change to the image is the same for for both -intensity rec601luminance as well as rec709luminance settings.. The same result also occurs if I move the "-intensity ......luminance" from before the input filename to just after the input filename.
The above can be repeated with essentially the same results if we replace "-colorspace RGB" by "-colorspace sRGB", or even "-colorspace cielab":
Code: Select all
Geom CSpc A Dep Gam Fmt Siz Min Mx Avg Name
70x46 Gray - 8 .454545 JPEG 1495B .137255 1 .429729 myrosesgray.jpg
70x46 sRGB - 8 .454545 JPEG 1669B .137255 1 .428359 {rec709luma}myrosesgray.jpg_RGB_Bx0.99.jpg
70x46 sRGB - 8 .454545 JPEG 1664B .137255 1 .427216 {rec709luma}myrosesgray.jpg_sRGB_Bx0.99.jpg
70x46 sRGB - 8 .454545 JPEG 1522B .403922 1 .668556 {rec709luminance}myrosesgray.jpg_RGB_Bx0.99.jpg
70x46 sRGB - 8 .454545 JPEG 1524B .403922 1 .668341 {rec709luminance}myrosesgray.jpg_sRGB_Bx0.99.jpg
70x46 sRGB - 8 .454545 JPEG 1522B .407843 1 .672689 {rec709luminance}myrosesgray.jpg_cielab_Bx0.99.jpg
This is approximately the ratio that would be expected from a transformation of the original grayscale image from gamma=.454545 to gamma=1.
One might describe the result this way: rec*luma and rec*luminance act as if they were two different colorspaces for grayscale images, quietly affecting whether the grayscale values are interpreted as linear vs nonlinear and thus the transformation that IM uses when transforming it to any other colorspace. Like a regular colorspace, the intensity setting is stored as a property of the image rather than merely a general session preference. With this intensity property, just as with a regular colorspace, intermediate colorspace transformations (like RGB or CIELab above) don't necessarily have an effect so long as in any case they all end up getting converted to sRGB in order to write the JPG file.
Is this a bug?
Or is this the expected behavior, and why?