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

It does help SuperMerlin, I was looking into this using ImageJ as it can batch export out a spreadsheet file of the histogram mean value.

Is there any chance of the output having a column for the full file path+filename+extension?

Once we have an exported spreadsheet, then a Bride Script or ExifTool can be used to import a keyword, label, rating or other metadata entry in. Once there is metadata, it can be used to sort or filter… However I am still working on that bit, adding a conditional variable metadata entry based on the mean histogram value. Some sort of range would be required, such as:

Low Key = mean value between ???-???

Medium Key = mean value between ???-???

High Key = mean value between ???-???

At a start point, simply using the mean histogram value as a metadata value and then sorting on this value would be a start.

This is obviously not a one step workflow and there is still work to be done, but at least we have something brewing!