I have a bunch of photos that have badges on them, close to 1500 of them, I need a way to detect if there is a yellow badge on it. Is it possible to make a action or a script to color sample from a exact pixel coordinate every time and if it finds the color that represents the badge then send it to a particular folder, for it to be grouped with other jpegs that were found to have a badge. Any thoughts or opinions on this would be helpful?
Asked
Active
Viewed 2,772 times
3
-
5Yes, this would be possible. What specific parts of it are you having trouble with? – Oliver Charlesworth Apr 28 '11 at 20:21
-
well i have made plenty of actions but I wasnt sure if you could record your exact cordinates when you color sample. Can you – Lawrence Apr 28 '11 at 20:22
-
Are you talking about a badge in a specific .psd layer, or an exported image (gif, jpg, png...)? – Demian Brecht Apr 28 '11 at 20:22
-
You cannot do this with javascript unless you're using HTML 5. http://stackoverflow.com/questions/2541481/get-average-color-of-image-via-javascript – cwharris Apr 28 '11 at 20:25
-
The badge frequency (color) is it the same all the time? or it change to a similar color? If the badge is yellow for instance, then it need to be checked against the yellow color, every time the program find a new photo and direct it to the right place. Is there a way to rename a file with a prefix or sufix to tell it has a badge? It is one possibilities, otherwise I think you will need a try with an OCR Reader. I'm not sure if the reader will recognize colors, but sure it recognize While and Black tones ... ;-) – devasia2112 Apr 28 '11 at 20:27
-
1Why is this tagged Photoshop? It cannot be done in Photoshop, I'm afraid. – Chuck Le Butt May 15 '11 at 06:59
-
1possible duplicate of [How to use javascript or jQuery to read a pixel of an image?](http://stackoverflow.com/questions/1041399/how-to-use-javascript-or-jquery-to-read-a-pixel-of-an-image) – Matt Ball Jun 09 '11 at 15:45
2 Answers
3
I know this is old but since it was tagged in Photoshop (and it definitely CAN be done in Photoshop with JavaScript), here is a solution:
#target photoshop
// TEST FUNCTION
function hasBadge(doc, x, y) {
// remove all current color samplers because photoshop has a limit of 4 or so and create a new sampler at the coordinates
for (var i=0; i<doc.colorSamplers.length; i++) {
doc.colorSamplers[i].remove();
}
var sampler = doc.colorSamplers.add([x, y]);
//This is where it could get tricky based on the actual color of the badge. If the badge is always consistently the same exact color you could test it's hexValue...
if (sampler.color.rgb.hexValue === "ffff00") {
return true;
}
// If the color is not consistent you can try to test if it's within a range of rgb values. This may take some tweaking...
if (sampler.color.rgb.red > 200 && sampler.color.rgb.green > 200 && sampler.color.rgb.blue < 50) {
return true;
}
return false;
}
// PROGRAM
var x = 200;
var y = 200;
// Process an entire folder. Can also use File.openDlg() to select files but might be easier to select by folder if you have a ton of files
var inputFolder = Folder.selectDialog("Select a folder to process");
var fileList = inputFolder.getFiles("*.JPG"); //Use whatever extension you want or no extension to select all files
// For each file in the folder...
for(var i=0; i<fileList.length; i++) {
var doc = open(fileList[i]);
if (hasBadge(doc, x, y) {
doc.saveAs(new File("C:/my/file/path/" + doc.name));
doc.close(SaveOptions.DONOTSAVECHANGES);
}
}

pdizz
- 4,100
- 4
- 28
- 42
0
You can find the answer here:
How to use JavaScript or jQuery to read a pixel of an image when user clicks it?
Basically you
draw the image in a canvas element then you can use the
getImageData
method to return an array containing RGBA values.

Community
- 1
- 1

joe_coolish
- 7,201
- 13
- 64
- 111
-
Or, I could be helpful and answer the question with a summary of the information that the person needs. IDK, sometimes just flagging a post as a duplicate feels a bit elitist and snobby; it just doesn't help anybody (Kinda like down voting 1.5 year old post and then posting how you know better and how you would have done things differently. It doesn't help any one and makes you come off as a tool) Thanks for your suggestion, but next time try and be helpful by keeping your comments to yourself :) – joe_coolish Oct 02 '12 at 15:52