Color Reader Script


This script is simply another utility tool related to color topics.   It will read the color values from a path selection in a Photoshop document.   The image can be in Lab or RGB mode and 8-bit or 16-bit encoding.

I wanted to find an alternative to the JavaScript histogram techniques.   The reason is that the histogram is rather inaccurate for images in 16-bit mode.   The histogram is limited to 256 integer levels.   And, accessing the histogram is not terribly fast.

This will save the current document as a Photoshop RAW image.   This is not the same as a typical camera RAW format.   It contains no metadata at all.   Only the raw pixel color values are saved and they are saved as a binary byte stream.   By reading this into a JavaScript binary string, the color values may be accessed by pixel location.  

Note that in 16-bit mode Adobe saves the values in true 16-bit format instead of its quasi 15-bit format.   So some mathematical transforms are necessary for the values to correlate to the Photoshop information panels and color samplers.

The basic operation is to open a document in Photoshop, make a rectangle selection of the area to be sampled, save it as a pen path, then run the script.   You can define multiple pen paths, with unique names.   If the pen path is named "penPath", it will read 24 patches from a Color Checker image, similar to ReadMacbethPatches, but with improved accuracy.   For more usage information, install the script in the Photoshop scripts folder, then run it with no document open.

The image may also contain adjustment layers if desired.

Download ColorReaderRaw.jsx V1.2 in a ZIP file here:

I have validated the numbers extensively with sample images in all supported modes.   This script is still under construction and should be considered a sample only at this time.   If you have any suggestions regarding accuracy, performance, or additional function I would appreciate your feedback.

In the final analysis, it is more accurate than the histogram approach, but it is not much faster.   And it can be slower with very large selection areas.   This is a factor of JavaScript performance, not an issue with Adobe.   With my system it takes about 20 seconds to process all pixels in a 1.5 MB 8-bit image.   Thirty seconds for the same image in 16-bit.   This is a significant improvement over the 30 minutes needed in my first tests.   It runs in less than a second with a more typical test of 24 samples (50x50) in a single pass.

I tested the accuracy against four color checker target images in Lab, RGB, 8-bit, and 16-bit.   These image patches were created with other scripts so they contain no noise or pixel-to-pixel variations.   The 8-bit values all validated perfectly.   The 16-bit values are all within +- 0.005 precision.   Since the input data is in 15-bit integer format, this is as good as it gets (+-1/128).

There are some inherent problems with Adobe quasi 15-bit math, particularly in the Lab conversions.   Evidence of this is available here: Adobe Math.  

That Legal Stuff

This script is provided as shareware with no warranty.   My testing was all with PS CS2.   You are free to use and modify it.   If you feel obliged to pay something, make a contribution to your favorite charity.

I hope you also gained some new insight from this article.   If you have any comments, or suggestions, I would welcome your input.   Please send me an  Email.

Rags Gardner
Rags Int., Inc.
204 Trailwood Drive
Euless, TX 76039
(817) 267-2554
Send Email
November 30, 2006
December 2, 2006
December 5, 2006

This page last updated on: Thursday April 12 2007
You are visitor number 9,718 since 11/30/06