Skip to content
This repository has been archived by the owner on Jul 27, 2019. It is now read-only.
/ daltonize Public archive

Daltonizing images with Octave / Matlab

Notifications You must be signed in to change notification settings

Dionakra/daltonize

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Daltonizing images with Octave / Matlab

This project tries to perform the correct transformations to a given image to show how a colorblind person would see the image. There are several types of colorblind based on the human eye cones sensitivity are partially damaged or missing at all. In this project I will focus on:

  • Protanopia: Defective long-wavelength cones (L-cones)
  • Deuteranopia: Defective medium-wavelength cones (M-cones)
  • Tritanopia: Defective short-wavelength cones (S-cones)

How it works

To perform the transformation we need to change the image space from RGB to LMS. We need to do this because the LMS system is the one which represents the human eye cones and, which are responsible of color awareness or blindness, and with this representation, we perform the changes to the image and then convert it right back.

To change the color space from RGB to LMS we need to pass through the XYZ color space, and then change it to LMS, so the math behind this is the following:

[X, Y, Z] = [M] * [R, G, B]

Where M is the transformation matrix from RGB to XYZ. There are many of transformation matrices, which can be found here.

Then, we need to change the color space from XYZ to LMS, performing the following transformation:

[L, M, S] = [N] * [X, Y, Z]

Again, N is a transformation matrix, which can be changed depending on the system you are working. Here is a list of them

After this we need to get the transformation matrix between the original, full color LMS space to the colorblind LMS_x space. In order to change from LMS to LMS with protanopia, we can't just delete the L cone. We need to calculate the change of color awareness in the rest of the cones. The full theoretical mathematics process is developed here.

In our case, because the reference systems can be customized, I cannot use the original transformation matrix from LMS to LMS_protanopia and so on, because the original values depends on the transformation matrices chosen. Because of this, we need to calculate these transformation matrices.

Finally, once we have all the needed matrices, we can perform the transformation. Now we just iterate through every pixel, transform it from RGB to LMS space, perform the change from full LMS space to the colorblind LMS_x space and then revert it back to RGB.

Colorblind Color Spectrums

Protanopia Color Spectrum

Protans have either defective long-wavelength cones (L-cones) or the L-cones are missing at all. If they are missing it is called protanopia or sometimes red-dichromacy. Affected persons are dichromats because they have only two working cone types, short- and medium-wavelength, compared to persons with normal vision with three different cone types.

Protanopia histogram

Deuteranopia Color Spectrum

Deuteranopia (also called green-blind). In this case the medium wavelength sensitive cones (green) are missing at all. A deuteranope can only distinguish 2 to 3 different hues, whereas somebody with normal vision sees 7 different hues.

Deuteranopia histogram

Tritanopia Color Spectrum

People affected by tritanopia are dichromats. This means the S-cones are completely missing and only long- and medium-wavelength cones are present.

Tritanopia histogram

Execution example

Source Image:

Beetlejuice

Code

daltonize('example_images/beetlejuice.jpeg', 'wide_gamut_rgb', 'ciecam02');
Protanopia Deuteranopia Tritanopia
Protanopia example Deuteranopia example Tritanopia example

Code optimization

After few tweaks, the performance of the script is really impressive, for example:

  • beetlejuice.jpeg (200*200 px) Elapsed time is 0.026247 seconds.
  • landscape.jpg (2880*1800 px) Elapsed time is 3.02334 seconds.

Acknowledgments

Releases

No releases published

Packages

No packages published

Languages