After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 101256 - Improve colorblindness display filter
Improve colorblindness display filter
Status: RESOLVED FIXED
Product: GIMP
Classification: Other
Component: User Interface
git master
Other All
: Low enhancement
: 2.4
Assigned To: GIMP Bugs
GIMP Bugs
Depends on:
Blocks:
 
 
Reported: 2002-12-15 09:29 UTC by Ben FrantzDale
Modified: 2005-03-26 12:41 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
The photoshop script described above (296 bytes, application/octet-stream)
2002-12-17 13:09 UTC, Ben FrantzDale
  Details
Use a LUT instead of pow() (3.54 KB, patch)
2005-03-25 23:01 UTC, Gautier Portet
committed Details | Review
patch stripped down to the part that works fine (3.32 KB, patch)
2005-03-26 00:17 UTC, Sven Neumann
none Details | Review

Description Ben FrantzDale 2002-12-15 09:29:54 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.
Comment 1 Sven Neumann 2002-12-16 00:50:46 UTC
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.
Comment 2 Ben FrantzDale 2002-12-16 04:24:45 UTC
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
Comment 3 Michael Natterer 2002-12-16 15:28:59 UTC
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.
Comment 4 Nathan Summers 2002-12-16 16:46:31 UTC
"(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.

Comment 5 Sven Neumann 2002-12-16 16:49:37 UTC
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.
Comment 6 Ben FrantzDale 2002-12-17 13:08:13 UTC
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.)
Comment 7 Ben FrantzDale 2002-12-17 13:09:52 UTC
Created attachment 13070 [details]
The photoshop script described above
Comment 8 Sven Neumann 2002-12-17 16:04:10 UTC
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. 
Comment 9 Sven Neumann 2002-12-20 12:37:59 UTC
I have received a copy of a paper which looks interesting. Will try to
find some time to read it over the xmas holidays...
Comment 10 Michael Natterer 2003-01-23 13:26:45 UTC
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.
Comment 11 Sven Neumann 2003-01-24 00:07:13 UTC
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.
Comment 12 Dave Neary 2003-07-22 18:48:54 UTC
Changing milestone to future. This is mostly done, and what's left to
do won't block 2.0

Dave.
Comment 13 Sven Neumann 2005-03-22 18:04:02 UTC
This is a nice little optimization job. The module works correctly but a number
of smaller improvements (see above) are possible.
Comment 14 Gautier Portet 2005-03-25 23:01:26 UTC
Created attachment 39261 [details] [review]
Use a LUT instead of pow()

Here is a patch to use a LUT instead of pow().
Comment 15 Sven Neumann 2005-03-25 23:44:14 UTC
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.
Comment 16 Sven Neumann 2005-03-26 00:14:43 UTC
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].
Comment 17 Sven Neumann 2005-03-26 00:17:05 UTC
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.
Comment 18 Sven Neumann 2005-03-26 00:26:05 UTC
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.
Comment 19 Sven Neumann 2005-03-26 00:55:38 UTC
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.

Comment 20 Sven Neumann 2005-03-26 12:41:58 UTC
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.