Skip to main content
Known Participant
July 10, 2017
Question

sort bright photos from dark photos in bridge?

  • July 10, 2017
  • 3 replies
  • 5604 views

This needs a creative mind.

I know we can sort pics via metadata in a bridge script, but is there any way to sort bright photos from dark photos? (regardless of aperture, flash, exposure time - based solely on illumination)  I'd like to run a different action on each.

And if not in bridge, can anyone think of a clever conditional in photoshop actions?

This topic has been closed for replies.

3 replies

paulinaj36745582
Participant
December 29, 2019

I've tested/tried everyone script above and noone work. I've tried it on CC2018, CC2019 and older version of Photoshop - CS2.

I've got error:

Error 1242: Illegal argument - argument 1
- File/Folder expected
Une: 19
-> open(fileList);

So I changed open(fileList) to open(fileList[a]) and script startr running but nothing happen, only open and close files from selected folder.

Is anything I'm doing wrong? I run script directly from Photoshop -> Files -> Scripts. I have more then 5 milion photos day and night and I want separate day from nighy shots. Do this task manual is neverending story, so maybe someone could help me to run this script and help automate Label .jpg photos.

Legend
September 16, 2020

Have you thought of using the time captured in metadata? 9PM is night, 3PM is day. etc.

Participant
May 8, 2018

Awesome script, thanksSuperMerlin I'm only working with jpgs and in lightroom, so I would like to avoid xmp. How can I write this directly to the exif instead of creating an xmp?

Also, can anyone thing of how I could sort images in lightroom this way? Without renaming the filename.

SuperMerlin
Inspiring
May 8, 2018

This version writes the mean value to keywords I.E. "Mean value = 114.34"

Sorry I know nothing about Lightroom, so can't help there.

#target photoshop; 

app.bringToFront(); 

 

main(); 

function main(){ 

var inputFolder= Folder.selectDialog ("Please select folder to process"); 

if(inputFolder == null) return; 

var fileList = inputFolder.getFiles(/\.(jpg|dng|tif|psd|psb|exr|png)$/i); 

if (ExternalObject.AdobeXMPScript == undefined) ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");    

for(var a in fileList){ 

open(fileList); 

var doc = activeDocument; 

if (doc.mode != DocumentMode.LAB) doc.changeMode(ChangeMode.LAB);  

var L = activeDocument.channels["Lightness"].histogram;   

var mean =  meanHist(L).toFixed(2); 

if(fileType() != "Camera Raw"){ 

setMetadata( fileList, mean); 

}else{ continue;}

app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

}

}; 

function setMetadata( file,mean){ 

var data = "Mean value = " + mean;

if ( !ExternalObject.AdobeXMPScript ) ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript'); 

        var xmpf = new XMPFile( File(file).fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE ); 

        var xmp = xmpf.getXMP();    

        xmp.appendArrayItem(XMPConst.NS_DC, "subject", data, 0,XMPConst.PROP_IS_ARRAY);  

      if (xmpf.canPutXMP( xmp )) { 

         xmpf.putXMP( xmp ); 

      } 

      xmpf.closeFile( XMPConst.CLOSE_UPDATE_SAFELY ); 

}; 

function meanHist(hist) {  

   var acc = 0;  

   var cnt = 0;  

   for (var i = 0; i < hist.length; i++) {  

     acc += i*hist;  

     cnt += hist;  

   }  

   return acc/cnt;  

}; 

function fileType(){ 

var ref = new ActionReference(); 

ref.putProperty( charIDToTypeID("Prpr"), stringIDToTypeID("format")); 

ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );  

return executeActionGet(ref).getString(stringIDToTypeID("format")); 

};

Known Participant
September 16, 2020

Doesn't work for me too on PS 21.2. Seems everything related to activeDocument.histogram goes down a black hole on newer versions of PS. Any thoughts on that? Is that a known bug or a change in the API?

Stephen Marsh
Community Expert
Community Expert
July 12, 2017

Is there a different, consistent metadata value to help distinguish between a light and dark file?

If not, then this would likely need the help of Photoshop in order to assess the histogram.

Re: export histogram mean value for RGB to csv file

How to get vaules in the histogram

SuperMerlin
Inspiring
July 12, 2017

I don't know if this will help. This script will create a csv file of mean histogram values for a folder of documents.

(Photoshop Script)

#target photoshop;

app.bringToFront();

main();

function main(){

var inputFolder= Folder.selectDialog ("Please select folder to process");

if(inputFolder == null) return;

var fileList = inputFolder.getFiles(/\.(jpg|dng|tif|psd|crw|cr2|psb|exr|nef|dcr|dc2|erf|raf|orf|tga|mrw|mos|srf|pic|pct|pxr|pdd|pef|png|x3f|rw2)$/i);

var outFile = File(Folder.desktop +"/"+decodeURI(inputFolder.name)+".csv");

outFile.open('w');

outFile.writeln("Filename,Mean Histogram");

for(var a in fileList){

open(fileList);

var area = activeDocument.histogram;

outFile.writeln(decodeURI(activeDocument.name)+ "," + mean(area).toFixed(0));

app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

}

outFile.close();

alert("Process complete\nCSV created...\n" + decodeURI(outFile));

}

function mean(hist) {

   var acc = 0;

   var cnt = 0;

   for (var i = 0; i < hist.length; i++) {

     acc += i*hist;

     cnt += hist;

   }

   return acc/cnt;

};

Stephen Marsh
Community Expert
Community Expert
July 12, 2017

The script can be amended to add a label or metadata instead of outputing to a csv file.

It depends if the mean value will suffice?


Cool, that would help SuperMerlin, thanks!

I don’t know what else can be done? How do we tell software to differentiate between say low key and high key?

A perfectly “level” average/midtone key would = 128 mean levels

A perfect high key image would = 255 mean levels

A perfect low key image would = 0 mean levels

Of course, we are not dealing with perfectly flat gray/white/black images – there is a range of tones.

So it is probably too hard to try to work out a range, such as low key = 0-50 mean levels etc.

At least having a keyword appended to the image that was numerical would allow the sorting of low to high or high to low etc.

Would it be possible to do the following?

1) Append the mean value as a keyword (so as not to replace existing keywords)

2) Perhaps add a space and text to the value, so instead of say “66”, it would read as “66 mean histogram value” or something?

I’ll post what I have knocked up using your original script and ExifTool shortly.