GNOME Bugzilla – Bug 101256
Improve colorblindness display filter
Last modified: 2005-03-26 12:41:58 UTC
Doing graphic design work, it is often helpful to see how a colorblind person sees the world. A filter to remap colors like this could be very helpful.
This could be implemented as a display filter module so it wouldn't change the image data but would only alter the way the pixels are displayed. The framework seems to work fine in 1.3 and it should be trivial to implement this by copying most of the code from the highcontrast module.
Cool. A good first approximation would be (r',g',b') = (r/2+g/2, r/2+g/2, b) I couldn't find a better formula after some googling. The above shows up a bit bright compared to the examples I've seen online. (Perhaps using the apparent brightness huristic of r*.3, g*.59, b * .11 would work better.) There's also this document which is helpful: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnhess/html/hess10092000.asp
Added the framework to current CVS. Now we need some real formulas plus their scientific names... Leaving the bug open for now because it is not finished. 2002-12-16 Michael Natterer <mitch@gimp.org> * modules/Makefile.am * modules/cdisplay_colorblind.c: added a display filter which will simulate the vision of people with color-deficiency to address bug #101256. Didn't know any scientific name or any correct formula, so I just added the framework plus the approximation formula from the bug report. Will need some more work to become usable.
"(Perhaps using the apparent brightness huristic of r*.3, g*.59, b*.11 would work better.)" This won't work, because those constants are the relative sensitivities of the red, green, and blue cones. Since colorblind people don't all three cones, the relative sensitivities are different.
Improved it slightly: 2002-12-16 Sven Neumann <sven@gimp.org> * modules/cdisplay_colorblind.c: use scientific terms and added an approximation formula for tritanopia. Now we need better formulas. I've asked a friend of mine who works at the library to try to get his hands on some of the paper referred to from most web pages dealing with this subject.
I sent an email to Alex Wade of http://www.vischeck.com asking about this. (This site also describes a filter that color blind people could use to allow them to distinguish between colors.) His response: > Could I just ask you where you read about this? We were planning to > implement a GIMP filter but never managed to find the time... He is interested in implementing this feature himself, 'though from the sound of it the rough approximation I mentioned above is already in CVS. He did have this to say, for a better approximation: > Does GIMP have an LAB color space? Because there's a nice > approximation which, although not entirely correct, is a > reasonable hack for protanopia and deuteranopia. I've > attached the photoshop script that implements it here. > Basically, you xform to LAB space, zero the (I > think) 'a' channel then xform back again. (I'll attach the script to this bug.)
Created attachment 13070 [details] The photoshop script described above
Would probably help to see the source code for this script. But then I actually don't want to see it unless the author clearly states that he's willing to accept the code to be used in a GPLed GIMP module. I'd rather see a plain formula to avoid any possible license problems. We can then convert it to source code ourselves.
I have received a copy of a paper which looks interesting. Will try to find some time to read it over the xmas holidays...
Fixed except for a small buglet. Leaving it open... 2003-01-23 Michael Natterer <mitch@gimp.org> * modules/cdisplay_colorblind.c: Bob Dougherty <bobd@stanford.edu> and Alex Wade <wade@ski.org> added the code needed to make this filter actually do something useful. Thanks for this contribution. Addresses bug #101256.
This checkin fixes the remaining bug and speeds it up a for a large range of images: 2003-01-23 Sven Neumann <sven@gimp.org> * modules/cdisplay_colorblind.c: use bpl (line pitch) when iterating over the buffer. Added a simple color cache that speeds up the filter for images that only use a few colors. There remains a TODO item: We should clip the result to the RGB gamut more elegantly. Instead of clamping betwenn 0 and 255, a less saturated color should be choosen by moving along the confusion line for the simulated color defiency. Another possible improvement is optimization. Gamma correction which is now performed using pow() could probably be implemented using LUTs. I keep this bug report open but lower its priority since the display filter is working reasonably well thanks to the contribution from visicheck.
Changing milestone to future. This is mostly done, and what's left to do won't block 2.0 Dave.
This is a nice little optimization job. The module works correctly but a number of smaller improvements (see above) are possible.
Created attachment 39261 [details] [review] Use a LUT instead of pow() Here is a patch to use a LUT instead of pow().
What's the purpose of the factor 16? Also, since the gamma factor is fixed, we could consider to precompile the LUT and include it as constant data. That's a minor issue though, the patch can be applied first.
The inverse lookup table works but you shouldn't use CLAMP when creating it. But for the back transformation you need to transform from floats to unsigned char. The lookup table should consist of guchar then. Clamp the float to 0,255, cast it to a guchar and use that as the index into the LUT of guchar[256][3].
Created attachment 39265 [details] [review] patch stripped down to the part that works fine Here's a stripped down version of your changes that has the inv-lut only. Feel free to use that as the basis to improve the patch further.
Thinking about it further, it seems that we are loosing too much precision in the gamma back-transformation if we use a LUT there. We could of course increase the size of the LUT but there's a memory/speed tradeoff here and this module shouldn't use too much memory.
OK, I've applied what we have plus some minor changes: 2005-03-26 Sven Neumann <sven@gimp.org> * modules/cdisplay_colorblind.c: applied a modified version of a patch by Gautier Portet that introduces a LUT for the gamma correction (bug #101256). Also moved constants out of the CdisplayColorblind struct.
This change reduces memory requirements and replaces the calls to pow() for the backward transformation by a binary search in the LUT: 2005-03-26 Sven Neumann <sven@gimp.org> * modules/cdisplay_colorblind.c: use the same LUT for all color channels. Do a binary search in the LUT for the backward transformation. I think we can close this report as FIXED now. There are certainly always ways to improve things further but unless someone can point out a particular problem or enhancement, it doesn't make sense to keep this report open any longer. Gautier, thanks a lot for your patch.