Skip to content

Instantly share code, notes, and snippets.

@lm913
Last active January 1, 2016 23:33
Show Gist options
  • Save lm913/64925c06d711aba14bd5 to your computer and use it in GitHub Desktop.
Save lm913/64925c06d711aba14bd5 to your computer and use it in GitHub Desktop.
// enable double clicking
#target photoshop
app.bringToFront();
var doc = activeDocument,
docName = activeDocument.name;
// Save the current preferences
var startRulerUnits = app.preferences.rulerUnits,
startTypeUnits = app.preferences.typeUnits,
startDisplayDialogs = app.displayDialogs;
// Set Adobe Photoshop CC 2015 to use pixels and display no dialogs
app.preferences.rulerUnits = Units.PIXELS;
app.preferences.typeUnits = TypeUnits.PIXELS;
app.displayDialogs = DialogModes.NO;
var outputFile = '~/Desktop/Lab_' + docName.slice(0, -4) + '.csv', //output
sampler = doc.colorSamplers.add([0, 0]),
lumRange = (100 / 6),
lum1 = [],
lum2 = [],
lum3 = [],
lum4 = [],
lum5 = [],
lum6 = [],
blnk = [,,,,];
initFile(outputFile);
doc.convertProfile("Lab Color", Intent.RELATIVECOLORIMETRIC, true, true );
if(doc.width > 30){
doc.resizeImage(null,UnitValue(30,"px"), null, ResampleMethod.NEARESTNEIGHBOR);
}
for (var y = 0; y < doc.height; ++y) {
for (var x = 0; x < doc.width; ++x) {
sampler.move([x, y]);
var color = sampler.color,
l = (color.lab.l).toFixed(2),
a = (color.lab.a).toFixed(0),
b = (color.lab.b).toFixed(0);
if(l <= lumRange){
lum1 = [l,a,b];
writeToFile(outputFile, lum1);
$.writeln(lum1); //debug
$.writeln('**********'); //debug
} else if (l > lumRange && l <= lumRange*2){
lum2 = [l,a,b];
writeToFile(outputFile, blnk+lum2);
$.writeln(lum2); //debug
$.writeln('**********'); //debug
} else if (l > lumRange*2 && l <= lumRange*3){
lum3 = [l,a,b];
writeToFile(outputFile, blnk+blnk+lum3);
$.writeln(lum3); //debug
$.writeln('**********'); //debug
} else if (l > lumRange*3 && l <= lumRange*4){
lum4 = [l,a,b];
writeToFile(outputFile, blnk+blnk+blnk+lum4);
$.writeln(lum4); //debug
$.writeln('**********'); //debug
} else if (l > lumRange*4 && l <= lumRange*5){
lum5 = [l,a,b];
writeToFile(outputFile, blnk+blnk+blnk+blnk+lum5);
$.writeln(lum5); //debug
$.writeln('**********'); //debug
} else {
lum6 = [l,a,b];
writeToFile(outputFile, blnk+blnk+blnk+blnk+blnk+lum6);
$.writeln(lum6); //debug
$.writeln('**********'); //debug
}
//writeToFile(outputFile, lum1.concat(lum2, lum3, lum4, lum5, lum6));
//lum1 = [,,,]; lum2 = [,,,]; lum3 = [,,,];
//lum4 = [,,,]; lum5 = [,,,]; lum6 = [,,,];
}
}
function writeToFile(fileName, text){
var csvFile = new File(fileName);
csvFile.open("a");
csvFile.writeln(text);
csvFile.close();
}
function initFile(fileName){
var csvFile = new File(fileName);
csvFile.open("w");
csvFile.writeln(docName + "\nL1,a,b,L2,a,b,L3,a,b,L4,a,b,L5,a,b,L6,a,b");
csvFile.close();
}
//clean up
doc.activeHistoryState = doc.historyStates[0];
app.purge(PurgeTarget.HISTORYCACHES);
alert("Complete");
@lm913
Copy link
Author

lm913 commented Jan 1, 2016

Desired Output
screen shot 2016-01-01 at 6 25 31 pm

@lm913
Copy link
Author

lm913 commented Jan 1, 2016

Test file pixel values expressed from left to right and top to bottom
screen shot 2016-01-01 at 6 33 16 pm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment