I have a question about processing of images with ColorSpace -> Automatic by Mathematica.
First of all, ColorSpace -> Automatic is assumed by default when no colorspace is specified for a new Image object:
i1 = Image[{{{.1, .3, .5}}}, "Real"];
i1 // Options
{ColorSpace -> Automatic, Interleaving -> True}
Earlier versions of the Documentation didn't explain what ColorSpace -> Automatic means. The most recent version mentions this option value only on the Documentation page for ImageColorSpace where the following is written:
Returned color space can be any of the following:
??<...>
??Automatic??no color space specified
So it means exactly "no color space specified" and nothing more. Logical and expected, but is this really so?
Let us create several one-pixel images with different number of color channels and try to convert them to the "RGB" colorspace. This task is apparently ambiguous since it isn't clear how to convert an image from unknown colorspace with arbitrary number of channels to RGB, so I would expect Mathematica to return an error saying precisely this. Let us check:
i2=Image[{{{.1,.3,.5,.7}}},"Real"];
i3=Image[{{{.1,.3,.5,.6,.7}}},"Real"];
i4=Image[{{{.1,.3,.5,.6,.65,.7}}},"Real"];
Column[InputForm[ColorConvert[#,"RGB"]]&/@{i1,i2,i3,i4}]
Image[{{{0.1, 0.3, 0.5}}}, "Real", ColorSpace -> "RGB", Interleaving -> True]
Image[{{{0.1, 0.4, 0.7}}}, "Real", ColorSpace -> "RGB", Interleaving -> True]
Image[{{{0.1, 0.4, 0.6499999999999999}}}, "Real", ColorSpace -> "RGB", Interleaving -> True]
Image[{{{0.2, 0.55, 0.675}}}, "Real", ColorSpace -> "RGB", Interleaving -> True]
We have got no expected error messages and some strange images as the output. The first case (i1) is obvious: the channel values just remain the same, hence ColorSpace -> Automatic in this case is assumed to be equivalent to ColorSpace -> "RGB" (what is undocumented and unexpected of course: why not "HSB", "LUV", "LAB", etc.?). The other cases are entirely unclear: why the four-channel pixel {.1,.3,.5,.7} is converted to the three-channel one {0.1, 0.4, 0.7}? Why the five-channel pixel {.1,.3,.5,.6,.7} is converted to the three channel {0.1, 0.4, 0.65}, and so on? What happens here? Apparently this behavior is inconsistent and misleading and can cause subtle bugs which are hard to debug when developing a serious image-processing application.
So my questions are:
1) Is it a bug that ColorConvert behaves this way?
2) If not, what is the meaning of ColorSpace -> Automatic then? Apparently it doesn't currently mean "no color space specified" at least for ColorConvert.
3) How other image-processing functions handle ColorSpace -> Automatic?
(Inspired by this question; reported to the support as [CASE:3963067].)