The problem is greyscale has no linear or non-linear aspect associated with it.
IM has recently gone though a number of stages of 'how to do this' as such it is highly version dependant. However the latest version should have the handling for this sorted out (both in
-separate actions, and in image saving). So when saving, some versions of IM saved it as non-linear sRGB, others flagged it simply as linear data. The latter is correct behaviour, as a grayscale image is just data, without a true colorspace, until otherwise specified depending on what it will be used for (and that could be quite a large number of things).
-separate is meat to extract the channel values from an image, as such extracting red generates a grayscale image. The fact that this grayscale image was extracted from a non-linear colorspace is lost, or exactly what colorspace it was from (which may not be sRGB).
Grayscale data could for example be values from Luma, Luminence, Brilance, Hue, or A*, B*, U*, V*, or alpha image channel data. It could be image map data, such as a mask, lookup tables for color, distortions, displacement, or even 'which image', image segmentation, object identification, and probably may other things. It is something the user needs to track and define when he finnaly decides to use that data. There is just too many possibilities to 'track' or even determine.
So how do you want that data saved?
You can save it as a linear grayscale image (IM will assume it is linear data), or tell IM this grayscale image is really a non-linear sRGB grayscale image using
-set colorspace sRGB, in which case you have defined the data is non-linear sRGB data for display.
The latter is correct for viewing purposes. For just preserving that raw data, the former is more correct, but either can be used, the data in the save file should remain the same in either case.
If you set it as being linear RGB rather than leaving it as grayscale, or setting it as sRGB, then IM will generally convert that colorspace to sRGB, as most image file formats (not MIFF) only handles sRGB. (ASIDE; JPEG actually saves as a YUV colorspace internally, and uses a profile to determine output colorspace, or sRGB is not present)
Note while color channels of a sRGB image is non-linear, the alpha channel (and CMYK images) are linear.
But you may want to convert those to non-linear sRGB for display on web browsers whcih may not understand a 'linear grayscale' save image. You can do that using
-colorspace sRGB instead, though that does convert the data values.
Remember IM is designed for maximum use by as many people as possible. It is not designed to save people from doing the wrong thing. So think about what you want.
fmw42 wrote:Code: Select all
convert image -set colorspace RGB -channel R -separate +channel result
Note this saves linear-Red values to a grayscale'. Most display programs should convert the linear image to your monitors correct gamma settings, so should come out correct.
However most programs I have seen (including IM "display", and "show:" coder, Eye-of-Gnome, "xv", ) displays the grayscale image as if it is sRGB even though it is flagged as being linear data.
Firefox however displayed the image very 'light', as did the "chrome" web browser. That is it 'colorspace corrected' the image for display and is equivalent to converting 'linear colorspace' to sRGB colorspace, like this
Code: Select all
convert result.png -set colorspace RGB -colorspace sRGB show:
NOTE: IM "display" should be displaying the image AS IS, regardless of 'colorspace' on purpose so you can actually see the data AS IS, for debugging purposes. That is the behaviour I am seeing, and is correct, otherwise you could not do something like the above and see a difference.