Re: [Gimp-developer] Different results between RGB to Grayscale conversion and Desaturate (luminosity) filter



On Mon, Jun 15, 2015 at 2:29 PM,  <thomas manni free fr> wrote:

in master branch, using Colors > Desaturate (luminosity) and Image
Mode > Grayscale on a RGB image
(whatever the image precision) gives different results.

This does not appear in branch gimp-2-8, since the 2 actions
are computed the same way (using GIMP_RGB_LUMINANCE).

In master, for Desaturate (luminosity) filter, GIMP_RGB_LUMINANCE is
used on a R'G'B'A buffer.
For Grayscale conversion, drawables' buffers formats are converted
to babl_format Y (or Y' according to the initial format).

As these 2 actions seem to have the same goal (obtain the relative
luminance), shouldn't we obtain the same result ?



I am not sure they should behave the same way / give the same result -
nor that any of the results are ideal yet.

What is GIMP_RGB_LUMINANCE?

GIMP_RGB_LUMINANCE is defined using the Y values from the sRGB XYZ matrix. LUMINANCE calculations are only correct if done on linearized RGB. The values are given in libgimpcolor/gimprgb.h and match similar code in babl:

/*  Map D50-adapted sRGB to luminance  */

/*
 * The weights to compute true CIE luminance from linear red, green
 * and blue as defined by the sRGB color space specs in an ICC profile
 * color managed application. The weights below have been chromatically
 * adapted from D65 (as specified by the sRGB color space specs)
 * to D50 (as specified by D50 illuminant values in the ICC V4 specs).
 */

#define GIMP_RGB_LUMINANCE_RED    (0.22248840)
#define GIMP_RGB_LUMINANCE_GREEN  (0.71690369)
#define GIMP_RGB_LUMINANCE_BLUE   (0.06060791)

#define GIMP_RGB_LUMINANCE(r,g,b) ((r) * GIMP_RGB_LUMINANCE_RED   + \
                                   (g) * GIMP_RGB_LUMINANCE_GREEN + \
                                   (b) * GIMP_RGB_LUMINANCE_BLUE)

is it the equivalent of the V component of
HSV (MAX(MAX(R,G),MAX(G,B)) ?

Neither CIELAB Lightness nor XYZ relative Luminance have anything at all to do with HSV Value, which is merely the maximum of R, G, and B as encoded in whatever RGB working space the image happens to be in.

It is possible that GIMP could ask the user how they want to derive a
grayscale/desaturated version.Perhaps only ask when doing desaturate
and do the best we can do for the implicit conversion when going from
color to grayscale mode - something like the Luminance component of
CIE Lab normalized to 0.0-1.0 range.

CIE Lab "L" is CIELAB Lightness, which is not the same as XYZ "Y" relative luminance. CIELAB Lightness represents an attempt at perceptual uniformity (with JAB/JCH "J" being a more recent attempt).

XYZ "Y" represents relative luminance, which is well-defined, and not perceptually uniform, and can only be properly calculated from RGB using linear gamma RGB (https://en.wikipedia.org/wiki/Relative_luminance; note that the wikipedia article Y values are for the D65 sRGB color space, not the D50-adapted sRGB color space profile).

Converting from RGB to grayscale ("Image/Mode/Grayscale") should be done by calculating XYZ "Y" from linearized RGB. Currently it works correctly at "gamma" precision (so it must be requesting RGBA). It's not working at "linear" precision, but "linear" precision is messed up generally at present.

However, at "gamma" precision" the current "Colors/desaturate/luminosity" code, which ought to convert to XYZ "Y", is producing wrong results. As Manni notes, it looks like it is operating on perceptually uniform RGB instead of requesting linear gamma RGBA. I can't check what it does at "linear" precision because the conversion to "linear" precision isn't working properly.

Best,
Elle
--
http://ninedegreesbelow.com
Color management and free/libre photography


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]