The -set colorspace RGB should no longer be needed once 6.8.7.1 is released... The gamma issue has been fixed.
I don't see that setting the gamma property in itself solves the problem within IM processing.
All I want to do is read in an sRGB photo, perform various operations on its linear luminance values and then save this luminance information in some form within an 8-bit (preferably single-channel) png file so that I can use it later.
I want the resulting PNG file to be nonlinear (via the usual sRGB gamma compression), just like most png files would be.
I think this is a pretty straightforward use case, so I'm not sure why it can't be done easily today.
(Why not linear coding? in most cases it isn't a good idea to store a visual image in linear encoding in low-resolution integers (especially 8-bit), since the loss of dynamic range and especially visible tonal resolution at the dark end could be extreme. Even saving in 16bit linear can lose an awful lot if you've been processing the image internally linearly but using floats as in im6hdri. Secondarily, some software will assume sRGB gamma compression regardless of whether there is a single channel or three, and not necessarily handle gamma=1.0 correctly, and of course some other formats may be presumed to be sRGB because they have no way to indicate otherwise.)
CIE Luminance--Y in the XYZ (linear tristimulus) colorspace--is pretty much the most basic building block in terms of which sRGB, most other colorspaces, and ICC profiles themselves are defined, so why would it be difficult to produce?
The only way I could find to do this transformation was to use "-grayscale Rec709Luminance"* and even then, the conversion back to sRGB gamma-compression for output to the png fails because -colorspace sRGB does nothing since it treats Gray as already being nonlinear like sRGB:
Code: Select all
convert mysrgb.png -grayscale Rec709Luminance ....other ops.... -colorspace sRGB mygray.png
Even with the new patch (setting gamma=1 from -grayscale Rec709Luminance) I don't think this will do what I want,
unless -colorspace sRGB looks at the image->gamma==1 and realizes that it does indeed need to transform the data values from linear to sRGB.
Can somebody tell me what effect image-> gamma has on internal processing within IM -- does anything different actually happen other than attempting to store the gamma value in the file when saving to a file format that supports this?
(P.S. -- The "-grayscale Rec601Luminance" operator in IM apparently applies the Rec601 nonlinear Luma coefficients when calculating linear Luminance, which is not what those coefficients are intended to be used for. The only reason applying the
Rec709 Luma coefficients to linear RGB works is that they are numerically identical to the original
linear CIE RGB->Y coefficients. Rec 709 arbitrarily chose to apply these pre-existing CIE linear coefficients to their nonlinear R'G'B' to get their Luma encoding for transmission and storage, which they were free to do because you can define a transmission and storage
encoding any way you please, so long as you don't lose too much info and there's a way to decode it. You can't define Luminance (or even gamma-compressed luminance) just any way you please -- luminance is based on psychophysical measurements of how real humans perceive the brightness of different colors of light; linear CIE Y is the one and only Luminance that sRGB and ICC profiles themselves and just about everything else uses.)