snibgo wrote: ↑2017-08-24T22:12:27-07:00
Is the "-intensity" setting a good way of flagging that data is linear? No, I don't think so. For one thing, when changing colorspaces, the "-intensity" setting is only used when the colorspace was Gray, Rec601Luma or Rec709Luma.
I agree that -intensity isn't a
good way (in fact, having a linear and a nonlinear grayscale colorspace is the way other software does it and this would make everything "just work" like it used to when there were several such colorspaces in IM), but the fact is that IM
does currently use "-intensity" in this way when using one of those four "-intensity" settings.
In fact, IM
sets rec709luminance (for example) as the intensity property on the resulting grayscale image (just as much so when -grayscale rec709luminance is used, btw, seemingly contrary to the documentation) and then IM
also reads this setting back and respects it when converting this grayscale image back to a color image. This is unlikely by accident -- it is designed so that, for example, it makes everything work correctly in round-trips back and forth between linear grayscale images and linear RGB without changing the data more and more every time!
But there are other cases where this usage of the intensity is not implemented, and I can't submit a bug report on these unless it is recognized that the intensity is or should be used in this manner, rather than just de facto.
snibgo wrote: ↑2017-08-24T22:12:27-07:00
Even then, only two intensity settings are important: Rec601Luminance and Rec709Luminance. And "-intensity" has many other possible values that are not related to linearity.
I haven't tested other values of -intensity but the four luma/luminance ones are the most basic (frankly, primarily rec709luminance since the luma ones are already the default, and rec601luminance doesn't actually make photometric sense as it is inconsistent with the very
definition of RGB and sRGB in terms of Linear Luminance Y in XYZ colorspace, which specifically use the "rec709" coefficients, which, btw, for linear RGB, pre-date Recommendation 709 by decades).
I'm okay with saying "all bets are off" for now on the others intensities. (Although in fact it seems clear from the formulas in the documentation that Lightness and Brightness always use the nonlinear (sRGB) values (the primed R', G', B') so these should probably be marked as nonlinear as well; and Average apparently doesn't change anything between linear and nonlinear, so it should probably preserve the current linearity/nonlinearity. For MS and RMS I would say all bets are truly off.)
snibgo wrote: ↑2017-08-24T22:12:27-07:00
I think the best way of flagging that data is linear is to declare it as "-set colorspace RGB".
Okay, if that's the best we can do, then would you be willing to propose that the IM
documentation state something along the lines of
The RGB colorspace can also be used for single-channel images (instead of using the Gray colorspace), to indicate the linearity of the data values and ensure that operations such as transformations to color images will correctly take this linearity into account.
If it were proposed by me I'm almost certain that this idea wouldn't go anywhere
Using RGB colorspace could be either instead of, or in addition to, the current ways of indicating linear gray (which is mainly rec*luminance intensity setting on gray image, but sometimes/inconsistently instead the gamma setting when it comes to reading & writing certain specific file formats & some other operations).
Currently, everything "just works" with linear RGB color images, but then the situation becomes unclear (and inconsistently implemented) when we try to use linear grayscale. There has to be some recognized way of doing this rather than just an undocumented workaround that everyone has to find out for themselves.
Sometimes I don't use ImageMagick for awhile and then when I come back I always have to figure out all over again how to work around the issues in order to make linear grayscale work without mangling the image data!
snibgo wrote: ↑2017-08-24T22:12:27-07:00
Sadly, not all file formats have colorspace metadata. They do often have "gamma" metadata, which is often used as flag meaning "linear RGB or non-linear sRGB".
Understand, and gamma is the best we can do in those file formats. But when gamma=1 or gamma~0.4545 the best we can do is convert to and from what ever flag (or multiple flags) IM uses internally to identify linear vs nonlinear(sRGB-like) images. Some formats have exactly one colorspace (jpeg, hdr, etc.) so there's no ambiguity. And for formats that have no specified colorspace or gamma whatsoever, we always assume sRGB, which is fine as a default.
snibgo wrote: ↑2017-08-24T22:12:27-07:00
In my view, the major issue is the way the file formats don't handle colorspaces well. There isn't a clean well-defined flag that defines colorspace, or says what process should be used to make the data linear, or that it is already linear.
I understand. But once we decide that the input image is to be treated as sRGB, then there is only one correct way to linearize it (to either RGB or XYZ), which is given in the sRGB specification. If we decide that it's linear RGB or another supported colorspace, then there's one correct way to transform it to any other given colorspace, and IM already does this mostly correctly for multichannel color images.
snibgo wrote: ↑2017-08-24T22:12:27-07:00
As you probably know, the RGB<->sRGB conversion isn't simply a gamma adjustment. By contrast, the linearRGB<->AdobeRGB conversion is a simple gamma adjustment.
I understand, but if IM would just work consistently with sRGB (not necessarily
pure gamma=1/2.2 since this is very rare) and linear, including grayscale sRGB (as found in all grayscale jpeg files and most grayscale png files) and linear "grayscale RGB", that would be a great start -- just the basics!
I wouldn't want to try to get too ambitious about other colorspaces before then
snibgo wrote: ↑2017-08-24T22:12:27-07:00
Dabrosny wrote:And I'd like to know the correct way to tag a grayscale image as linear for IM processing ...
I've never understood IM's obsession with "grayscale" as a colorspace. As far as I'm concerned, "gray" is simply a special case of RGB, sRGB, AdobeRGB or whatever colorspace. (True, for some specialist purposes like TV transmission, "gray" might be something different. But for general image processing, I want to treat gray images just like colour images.)
Exactly! Any homogeneous red-blue-green colorspace (where all three channels behave similarly) can have a single-channel version of itself, which is equivalent to when the color version "just happens" to have all three channels equal! (There are some heterogeneous colorspaces like Lab that don't behave this way, but I'm happy to ignore them for now and stick to the basics.)
snibgo wrote: ↑2017-08-24T22:12:27-07:00
For v7, I use v7.0.3-5, which has a multitude of colorspaces for colour but only "Gray" for grayscale images. Probably because file metadata often has a flag for "gray", assumed to act like sRGB.
Code: Select all
magick rose: -colorspace RGB -modulate 100,0,100 -verbose info:
This has only one channel, and says:
... which is what I would hope. But all bets are off when saving the image to a file, and reading it back, hoping to find the same thing.
I think it would be a reasonable goal for the bets to be back "on" some day for it to behave predictably and consistently even when saving and reading images (to the extent possible for the format).
-Dabrosny [Using IM7.0.6 or higher, Q16 HDRI x64 native executable, command line, often invoked from cygwin bash/sh (as of Aug. 2017)]