Detect color in an area of an image and save as based on it

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

aboutrc

Detect color in an area of an image and save as based on it

Post by aboutrc »

I am hoping someone here can help me with this scripting solution i need.

I have 7000 pictures that were supposed to be taken with a white background. I received the folder, and I dont think many of them are with a true 255, 255, 255 background. However, I dont want to open each and every one to check this.

I dont know about javascript, but I am thinking maybe someone has something written out there. I want to create a script that I can run as an batch against a folder called 'original'

The script checks the color in the area at x=100 y=100
If the color of that area is 255, 255, 255 save the file in a folder called 'okwhite'
If the color is not 255, 255, 255 save the file in a folder called 'notwhite'

I figure if I ran an action like this, I would be able to see how many of these I can use without going through each file.

Thanks so much!
rc


-------------------------
Another idea for the script would be to run it as an action, and have a stop that says something "Use the eyedropper to select the pixel area to check" then allows the user to select a pixel area in the open picture, then does the comparison based on that... but that would be another project altogether..

Thanks for all the help everyone.

RC
rc ---at --- aboutrc.com
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: Detect color in an area of an image and save as based on it

Post by Kukurykus »

Make copy of the files you want a script to use on, as they will be removed from 'Original" folder and depending of (un)met condition placed in one of created by script subfloder. Do it just in case for unexpected reason something had to go wrong or else you simply can take fle.remove(), in /**/ like this: (/*fle.remove(),*/), so they will be only coppied.

Code: Select all

var cnt; function bnd(x, y) {return [(frt = [x, x]), [y, x], [y, y], [x, y], frt]}
if ((fld = Folder('~/Desktop/Original')).exists) cnt = fld.getFiles(/.+.jpg$/)
if (!!cnt) {
for(i = 0, a = ['Ok', 'Not']; i < a.length; i++) {
(Folder(a[i] = fld + '/' + a[i] + 'White')).create()
}
#target photoshop
bringToFront()
for(j = 0; j < cnt.length; j++) {
open(fle = File(cnt[j])), (aD = activeDocument).selection.select(bnd(100, 101))
fle.copy(((hst = aD.histogram)[hst.length - 1] ? a[0] : a[1]) + '/' + fle.name)
fle.remove(), aD.close(SaveOptions.DONOTSAVECHANGES)
}
}
else (alert('There are no .jpg files in "Original" folder on your Desktop!'))
Attachments
Files Segregation.zip
(818 Bytes) Downloaded 347 times