Created
January 31, 2013 13:23
-
-
Save jcupitt/4682824 to your computer and use it in GitHub Desktop.
Simulate Deuteranope vision in ruby-vips.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
require 'rubygems' | |
require 'vips' | |
a = VIPS::Image.jpeg(ARGV[0], :sequential => true) | |
# import to CIELAB colour space using the ICC profile embedded in the image | |
lab = a.icc_import_embedded(:relative) | |
# turn to XYZ, a linear light space | |
xyz = lab.lab_to_xyz() | |
# and now to bradford cone space (a variant of LMS) | |
brad = xyz.recomb([[0.8951, 0.2664, -0.1614], | |
[-0.7502, 1.7135, 0.0367], | |
[0.0389, -0.0685, 1.0296]]) | |
# through the Deuteranope matrix, see | |
# http://moinmo.in/AccessibleMoin?action=AttachFile&do=view&target=daltonize.py | |
deut = brad.recomb([[1, 0, 0], | |
[0.494207, 0, 1.24827], | |
[0, 0, 1]]) | |
# back to xyz (this is the inverse of the brad matrix above) | |
xyz = deut.recomb([[0.987, -0.147, 0.16], | |
[0.432, 0.5184, 0.0493], | |
[-0.0085, 0.04, 0.968]]) | |
# .. and export to sRGB for saving | |
rgb = xyz.xyz_to_srgb() | |
rgb.write(ARGV[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment