Thursday, March 31, 2011

Red Green Color Blindness Script

I guess it shouldn't be called color "blindness." With those with red-green color blindness, they have a harder time distinguishing between red and green hues. In this script, you need to already have a picture open (most likely a jpg with just a background layer.
var image = app.activeDocument;

var background = app.activeDocument.artLayers.getByName("Background");

background.duplicate();

background.visible = false;

var copy = image.artLayers.getByName("Background copy");

var newLayer = image.artLayers.add();

var newLayer = image.artLayers.add();

var Layer1 = image.artLayers.getByName("Layer 1");

var Layer2 = image.artLayers.getByName("Layer 2");

image.activeLayer = copy;

var redChannel = image.channels.getByName("Red");

var greenChannel = image.channels.getByName("Green");


var arrayRed = new Array (redChannel);

var arrayGreen = new Array (greenChannel);

var arrayChannel = new Array (redChannel, greenChannel);

image.activeChannels = arrayRed;


image.selection.selectAll();

image.selection.copy();

image.activeLayer = Layer1;

image.paste();

image.activeLayer = copy;

image.activeChannels = arrayGreen;

image.selection.selectAll();

image.selection.copy();

image.activeLayer = Layer2;

image.paste();

copy.visible = false;

image.activeLayer.blendMode = BlendMode.SCREEN;

image.mergeVisibleLayers();

image.selection.selectAll();

image.selection.copy();

copy.visible = true;

image.activeLayer = copy;

Layer2.visible = false;

image.activeChannels = arrayRed;

image.paste();

image.activeChannels = arrayGreen;

image.paste();

image.activeLayer = background;

image.flatten();

image.selection.deselect();
And when you run it on a red-green colorblindness test like this one: source It becomes this image after you run it: So, this code simulates the red-green color blindness. The code takes the red and green channels in an rgb image, copies and pastes them into new channels. The screen layer blend mode adds the two layers and averages them out. Then it pastes the resulting image back onto the red and green channels. The resulting image has the red and green channels being the same. In red green color blindness, individuals have a hard time distinguishing between red and green, and this simulates that effect. You can most clearly see this in a traditional test for the color deficiency.

No comments:

Post a Comment