GNOME Bugzilla – Bug 155507
A way to convert a single layer to grayscale
Last modified: 2005-04-19 20:31:57 UTC
We need a plug-in that uses the same algorithm as the image mode change from rgb to grayscale so you could change a single layer.
What about Desaturate (Layer->Colors->Desaturate) ?
Desaturate does something different. Should have confirmed this bug earlier :)
Could be done with a script-fu: put the layer into "Value" mode, insert a white layer underneath it, and merge down.
This would be very easy to implement. Probably even easier to do it in the core than as a plug-in. The core already has gimp_drawable_convert_grayscale() so one would only have to add an action for it and add it to the menus. The only real problem is how to name the menu.
If we were starting from scratch, the ideal thing would be to make "Desaturate" do this instead of what it currently does: in my experience the results are superior 95% of the time. But backward compatibility means that's not an option. Anything appearing next to "Desaturate" in the menu and with nearly the same meaning is going to be confusing -- I would suggest "Make gray" as possibly least confusing.
- Desaturate (one way) - Desaturate (another)
Ah! I have it: "Luminosity". That's what it is, after all.
My suggestion in comment #4 to use gimp_drawable_convert_grayscale() is of course bogus. gimp_drawable_convert_grayscale() does actually convert the drawable to grayscale. Here we want it to stay RGB but appear as grayscale (in other words r == g == b for any pixel).
Since there are even more ways to get gray pixels, perhaps we should have a dialog instead that gives the choice of: [x] Lightness (max(r,g.b) + min(r,g,b) / 2) [ ] Luminosity (0.30 * r + 0.59 * g + 0.11 * b) [ ] Average ((r + g + b) / 3) Are there other reasonable ways that I missed?
The first formula should be (max(r,g.b) + min(r,g,b)) / 2) of course.
Created attachment 45108 [details] [review] Adds a Luminosity item in the Layer/Colors menu to apply the grayscale algorithm This is not the definitive solution since Sven proposed a dialog with various algorithms to desaturate the layer.
Photoshop has this "Channel mixer" thing that lets you tune how you mix the channels into grayscale - it's extremely nice for making "black and white photos" from digital photos, as you can have different colors respond with different luminocity.
You know, GIMP has this "Channel Mixer" thing that let's you do exactly that. It's located in Filters->Colors.
Yeah, just noticed. Funny I hadnt seen it before. I guess it should be in Layer -> Colors from the user point of view - although the whole tools vs plugins division is not very easy to solve, since one can make quite good arguments for putting some things on either location.. neither is "wrong"..
To make things even more fun, it turns out that the technical definition of "desaturate" is r=g=b=max(r,g,b). This, of course, is not the formula we currently use for the "desaturate" menu item. *sigh* Tigert suggests that if we have a popup, we have a preview as well.
It turns out that the luminosity formula above is not correct for sRGB. Luminance for sRGB is 0.2126 * r + 0.7152 * g + 0.0722 * b.
Created attachment 45150 [details] [review] Splits "desaturate" in 3 formulae This patch should pave the way for a Desaturate dialog letting the user choose the formula: desaturate can be called with one of the three modes currently implemented. With this patch, Desaturate still uses the (max+min)/2 formula, while Luminosity uses the formula provided above. The third one (average) has no menu item calling it. Please review this patch before I go on with the dialog, thanks.
Created attachment 45264 [details] [review] Desaturate dialog offering three formulae
2005-04-16 Sven Neumann <sven@gimp.org> Applied a patch (with minor modifications) from Karine Delvare that makes it possible to choose between various ways to remove color from a drawable (bug #155507): * libgimpbase/gimpbaseenums.h: added new enum GimpDesaturateMode. * libgimpbase/gimpbaseenums.c * libgimp/gimpenums.c.tail * plug-ins/pygimp/gimpenums.py * tools/pdbgen/enums.pl: regenerated. * app/core/gimpdrawable-desaturate.[ch]: implement other formulas to remove colors from a drawable. * tools/pdbgen/pdb/color.pdb: let gimp_desaturate() call gimp_drawable_desaturate() with GIMP_DESATURATE_LIGHTNESS so that it behaves like it always did. * app/pdb/color_cmds.c: regenerated. * app/dialogs/Makefile.am * app/dialogs/desaturate-dialog.[ch]: new files that define a simple dialog to choose a mode for desaturation. * app/actions/drawable-actions.[ch]: use the new dialog. Now what's left to do is to expose this functionality to the PDB.
Created attachment 45455 [details] [review] Adds desaturate_full procedure in the PDB
Fixed in CVS: 2005-04-19 Michael Natterer <mitch@gimp.org> * tools/pdbgen/pdb/color.pdb: applied patch from Karine Delvare which adds gimp_desaturate_full(). Fixes bug #155507. * app/pdb/color_cmds.c * app/pdb/internal_procs.c * libgimp/gimpcolor_pdb.[ch]: regenerated. * libgimp/gimp.def: added the new symbol.