Skip to main content
Participating Frequently
January 13, 2010
Answered

How to automate color sampler

  • January 13, 2010
  • 3 replies
  • 5194 views

Hi,

I have a case where I have to measure a target (60 different fields) from 20 variations of the same photo. Photoshop only allows to use four color samplers at the same time and I would need 60. I have 20 variations of the same image ( x&y coordinates of these fields remain same between these variations). I need to measure Lab values and I have to get those values to excel.

Is there a "easy" way to automate color sampler to get all the 60 fields & values - and maybe make PS to write it on a file?

Now I'm about to make 15 different actions to measure those fields (4 fields per action...), and I have to write all values manually to excel - great..

Is there a better way to do it?

Thanks!

This topic has been closed for replies.
Correct answer Paul Riggott

Please try this..

You will need to create a text file with all the x,y sampler location IE:

200,300

250,200

300,150

You will be able to select the text file and it will load the locations, you have the option of selecting point sample or 3,5,11,31,51 or 101 average.

3 replies

larpouAuthor
Participating Frequently
January 23, 2010

I've been using now the script and it's really nice. Is it possible to get exact lab values out of ps? or is the only way to get rounded values?

Paul Riggott
Inspiring
January 23, 2010

No problem here you are..

February 3, 2010

Hi Paul,

Great script!

will it be possible to do the following steps in the script you wrote?

1. Select/Open a .RW2 image [maybe an extra textbox on the script?]

2. Automatically adjust the "exposure", "contrast" with predefined values [on camera raw plugin]

3. Then runs the rest of the script normally... taking samples etc.

i am really glad to find your script as i previously was manually, tediously taking each samples from my images....

Inspiring
January 13, 2010

I think a question to ask would be: Are these sample points going to be the same for every set you have to compare or will they be at different coordinates for each set?

Would you need an easy way to set up the sample point coordinates? This seems like the most time-consuming portion of what you are doing to me. If that's the case, it may be beneficial to make 2 scripts. One to log the coordinates quickly as you pick them and another to go through the set to compare. I guess it could be done with one script with a check first to see how many sample points have been selected for this set. If it is 60, then run the comparison.

Is this more of what you're looking for?

larpouAuthor
Participating Frequently
January 13, 2010

Sample points will have same X Y -location in same set. I have to make three sets and about 20 variations in one set (total 60 images 60 measure points so about 3600 samples). Sets have minor differences so I need script for each set. So easy way to set up coordinates for sample points would be really nice (and also ability to change color samper average method 11x11, 31x31...).

That sounds brilliant idea to have the ability to first to select all the fields and then capture.

Inspiring
January 13, 2010

Are you loading the image files all into one document on separate layers? Or are you opening up each image and setting the points, getting your values, then closing and opening the next?

Sorry to be asking so many questions. I'm not so good at this stuff so I like to know the details.

Paul Riggott
Inspiring
January 13, 2010

I wonder if this will work...

if(documents.length){
var doc = decodeURI(activeDocument.fullName.fsName);
var Name = activeDocument.name.match(/(.*)\.[^\.]+$/)[1];
var outFile = File("~/desktop/"+Name+".csv");
var sampledColours=[];// Array to hold results
var sampleXY=[ ///////// Amend with all your locations to test
[1,2],
[2,2],
[3,2],
[250,250],
[260,250],
[300,260],
[250,250],
[260,250],
[300,260],
[250,250],
[260,250],
[300,260],
[250,250],
[260,250],
[300,260],
[250,250],
[260,250],
[300,260],
[260,250],
[300,260],
[250,250],
[260,250],
[300,260],
[250,250],
[260,250],
[300,260],
[250,250],
[260,250],
[300,260],
[250,250],
[260,250],
[300,260],
[250,250],
[260,250],
[300,260],
[250,250],
[260,250],
[300,260],
[260,250],
[300,260],
[250,250],
[260,250],
[300,260],
[250,250],
[260,250],
[300,260],
[250,250],
[260,250],
[300,260],
[250,250],
[260,250],
[300,260],
[250,250],
[260,250],
[300,260],
[250,250],
[260,250],
[300,260],
[260,250],
[300,260]
];
for(var a in sampleXY){
var result = getSample(sampleXY[0],sampleXY[1]);
var L = Math.round(result.lab.l);
var A = Math.round(result.lab.a);
var B = Math.round(result.lab.b);
var pos ="X = "+ sampleXY
[0]+" Y = "+sampleXY[1];
sampledColours.push([[doc],[pos],,
,]);
}
outFile.open("w");
for(var s in sampledColours){
outFile.writeln(sampledColours);
}
outFile.close();
}

function getSample(X,Y){
app.activeDocument.colorSamplers.removeAll();
var xPos = new UnitValue( X,'px') ;
var yPos = new UnitValue( Y,'px' );
var mySampler = app.activeDocument.colorSamplers.add([xPos,yPos]);
var myColor = mySampler.color;
return(myColor);
}

larpouAuthor
Participating Frequently
January 20, 2010

Thanks!


That seems to do the job, but I still need to measure 11x11 average - any idea?

Inspiring
January 20, 2010

At the end of the thread http://forums.adobe.com/message/2452336 there is a sript that allows you to set the sample size.