Skip to main content
Known Participant
July 10, 2017
Question

sort bright photos from dark photos in bridge?

  • July 10, 2017
  • 3 replies
  • 5598 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;

};

SuperMerlin
Inspiring
July 12, 2017

OK, as a proof of concept, I used SuperMerlin’s original script to output the mean histogram level value to CSV file.

I then added the path to the image as a column. So the CSV import file had two columns with the following titles:

SourceFile,Subject

/path/to/file/hi.JPG,166 mean histogram value

/path/to/file/low.JPG,32 mean histogram value

/path/to/file/mid.jpg,128 mean histogram value

I then used the following ExifTool command to import and append the mean value as an entry in the Subject (keyword) metadata against each image:

exiftool -sep ',' -csv+='/path/to/csv/file/import-file.csv' 'path/to/image/folder'

Then in Bridge the keywords can be used to sort the images from say high key to low key based on the mean histogram value keyword:


Here is another version that labels the documents...

Big downfall at the moment. It does not do raw files.

#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|tif|psd|)$/i);

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

for(var a in fileList){

open(fileList);

var mean =  meanHist(activeDocument.histogram).toFixed(0);

switch( true ){

        case ( mean <= 110 ): setLabel( fileList,"To Do"); break;

        case ( mean > 111 && mean <= 180 ): setLabel( fileList,"Approved"); break;

        case ( mean >= 181 ): setLabel( fileList,"Review"); break;

        default : break;

    }

app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

}

};

function setLabel( file,label){

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.deleteProperty(XMPConst.NS_XMP, "Label");  

        xmp.setProperty(XMPConst.NS_XMP, "Label",label); 

      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;

};