• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Smart Exposure Compensation Script

Explorer ,
Apr 30, 2020 Apr 30, 2020

Copy link to clipboard

Copied

Hello,

How can I achieve following action:

 - I have a bulk of 1000 images (CGI scanned textures)

 - I would like to have an action that:

       loads image, blurres it by 1000px (or average filter blur), measures average color, reverse back to non-blurred image and applies Camera Raw exposure by following rules:

       if average color is around 128RGB, nothing changes, if average color is around 64RGB - it applies +0,2E camera raw exposure, if average color is around 192RGB - it applies -0,2E camera raw exposure. I shall be able to make any number of these rules/points - or it would be better if I could import a curve defining this behaviour.

       This shall become an action - so I can apply it with Image Processor and choose what format to save.

 

Thank you for your help!
Jakub

Views

1.2K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Apr 30, 2020 Apr 30, 2020

Thanks to SuperMerlin, I have adapted code that added label metadata based on mean histogram values. This script will open a folder of files and save them in the same format as the original files, overwriting the originals (so work on copies until you have fully tested and are happy). You shouldn't need to apply the average filter.

 

 

// Special thanks to SuperMerlin for the original script
//forums.adobe.com/message/9700071#9700071

// Modified by Stephen Marsh, 2020
//community.adobe.com/t5/
...

Votes

Translate

Translate
Adobe
Community Expert ,
Apr 30, 2020 Apr 30, 2020

Copy link to clipboard

Copied

Why blur by 1000px and not use the Average Filter right away? 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 30, 2020 Apr 30, 2020

Copy link to clipboard

Copied

I do not know that tool - if it does the same, no problem!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 30, 2020 Apr 30, 2020

Copy link to clipboard

Copied

Filter > Blur > Average

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 30, 2020 Apr 30, 2020

Copy link to clipboard

Copied

It does "better" :]

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 30, 2020 Apr 30, 2020

Copy link to clipboard

Copied

Sounds great, lets do that!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 30, 2020 Apr 30, 2020

Copy link to clipboard

Copied

Saves into which format?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 30, 2020 Apr 30, 2020

Copy link to clipboard

Copied

This shall become an action - so I can apply it with Image Processor and choose what format to save.
If this is not available, I would go with 16bit tiff with no compression.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 30, 2020 Apr 30, 2020

Copy link to clipboard

Copied

Sorry, misread that!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 30, 2020 Apr 30, 2020

Copy link to clipboard

Copied

Actually you did not - I did quick edit haha! 🙂

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 30, 2020 Apr 30, 2020

Copy link to clipboard

Copied

Code snippets to get you started (not full working code):

 

 

app.activeDocument.activeLayer.applyAverage();

 

 

And:

 

 

// Call The Camera Raw Filter Exposure Function with a value of +0.2
crExposure(expValue = 0.200000);

// Call The Camera Raw Filter Exposure Function with a value of -0.2
crExposure(expValue = -0.200000);

function crExposure() {
    //community.adobe.com/t5/photoshop/is-there-any-jsx-to-execute-the-auto-tone-of-camera-raw/m-p/10167490
    var desc1 = new ActionDescriptor();
    desc1.putDouble(charIDToTypeID('Ex12'), expValue); // var expValue
    executeAction(stringIDToTypeID('Adobe Camera Raw Filter'), desc1, DialogModes.NO);
}

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 30, 2020 Apr 30, 2020

Copy link to clipboard

Copied

Thanks to SuperMerlin, I have adapted code that added label metadata based on mean histogram values. This script will open a folder of files and save them in the same format as the original files, overwriting the originals (so work on copies until you have fully tested and are happy). You shouldn't need to apply the average filter.

 

 

// Special thanks to SuperMerlin for the original script
//forums.adobe.com/message/9700071#9700071

// Modified by Stephen Marsh, 2020
//community.adobe.com/t5/photoshop/smart-exposure-compensation-script/m-p/11093731

#target photoshop;
app.bringToFront();

main();

function main() {
    var inputFolder = Folder.selectDialog("Please select folder to process");
    if (inputFolder === null) return;
    var fileList = inputFolder.getFiles();
    for (var a in fileList) {
        open(fileList[a]);
        var EXT = fileList[a].name.toLowerCase().match(/[^\.]+$/).toString();
        var mean = meanHist(activeDocument.histogram).toFixed(0);
        if ((EXT)) {
            switch (true) {
                case (mean <= 110): // Mean histogram less than or equal to 110
                    crExposurePointTwo(fileList[a]);
                    break;
                case (mean >= 111 && mean <= 180): // Mean histogram between 111 and 180
                    (fileList[a]);
                    break;
                case (mean >= 181): // Mean histogram greater than or equal to 181
                    crExposureNegPointTwo(fileList[a]);
                    break;
                default:
                    break;
            }
        }
        app.activeDocument.close(SaveOptions.SAVECHANGES);
    }
}

function meanHist(hist) {
    var acc = 0;
    var cnt = 0;
    for (var i = 0; i < hist.length; i++) {
        acc += i * hist[i];
        cnt += hist[i];
    }
    return acc / cnt;
}

function crExposurePointTwo() {
    //community.adobe.com/t5/photoshop/is-there-any-jsx-to-execute-the-auto-tone-of-camera-raw/m-p/10167490
    var desc1 = new ActionDescriptor();
    desc1.putDouble(charIDToTypeID('Ex12'), 0.200000); // var expValue
    executeAction(stringIDToTypeID('Adobe Camera Raw Filter'), desc1, DialogModes.NO);
}

function crExposureNegPointTwo() {
    //community.adobe.com/t5/photoshop/is-there-any-jsx-to-execute-the-auto-tone-of-camera-raw/m-p/10167490
    var desc1 = new ActionDescriptor();
    desc1.putDouble(charIDToTypeID('Ex12'), -0.200000); // var expValue
    executeAction(stringIDToTypeID('Adobe Camera Raw Filter'), desc1, DialogModes.NO);
}

 

 

https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 01, 2020 May 01, 2020

Copy link to clipboard

Copied

Stephen! You are a true wizard!
This works like a charm and its super fast! Wow!
I honestly am so thankful - also ultra fast to run, no words! :))
Before me tagging this as the correct answer (which it really is based on my post), I woul love to ask if we could potentially take this little further.
Now by running this I realised one thing - to make this smooth I would need to make 50 - 100 points = 50 - 100 ifs.
That would be doable - but what if I need to change or experiment with numbers? I would need to change all values multiple times and that would take forever... Therefor I would love to ask - would it be possible to make the "if" part based on a curve? Please see attached.
All this would require is probably a path to saved "ACV" curve and two exposure compensation values - minimum and maximum.

This would be an incredible help. I am sorry for realizing this later.
Jakub

PS: Would the script possibly not overwrite files? Just add "_2" or anything. I already see myself loosing some part of library.
curve1.jpgcurve2.jpg

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 01, 2020 May 01, 2020

Copy link to clipboard

Copied

Thanks for the kind words, I just hack away – sometimes with success, I couldn't have written the script that SuperMerlin created.

 

I'll have to pass the baton over to somebody else. I have tried to make the requested modifications (both saving with a new filename and using a curve preset), however, I keep breaking the script.

 

Some snippets for the .acv code:

 

 

 

 

lightenCurvePreset();

function lightenCurvePreset() {
    var idCrvs = charIDToTypeID("Crvs");
    var desc29 = new ActionDescriptor();
    var idpresetKind = stringIDToTypeID("presetKind");
    var idpresetKindType = stringIDToTypeID("presetKindType");
    var idpresetKindUserDefined = stringIDToTypeID("presetKindUserDefined");
    desc29.putEnumerated(idpresetKind, idpresetKindType, idpresetKindUserDefined);
    var idUsng = charIDToTypeID("Usng");
    desc29.putPath(idUsng, new File("~/Desktop/Lighten.acv")); // Path to curve preset
    executeAction(idCrvs, desc29, DialogModes.NO);
}


darkenCurvePreset();

function darkenCurvePreset() {
    var idCrvs = charIDToTypeID("Crvs");
    var desc10 = new ActionDescriptor();
    var idpresetKind = stringIDToTypeID("presetKind");
    var idpresetKindType = stringIDToTypeID("presetKindType");
    var idpresetKindUserDefined = stringIDToTypeID("presetKindUserDefined");
    desc10.putEnumerated(idpresetKind, idpresetKindType, idpresetKindUserDefined);
    var idUsng = charIDToTypeID("Usng");
    desc10.putPath(idUsng, new File("~/Desktop/Darken.acv")); // Path to curve preset
    executeAction(idCrvs, desc10, DialogModes.NO);
}

 

 

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 01, 2020 May 01, 2020

Copy link to clipboard

Copied

»PS: Would the script possibly not overwrite files? Just add "_2" or anything. I already see myself loosing some part of library.«

You could replace the line 

app.activeDocument.close(SaveOptions.SAVECHANGES);

with something like this: 

var docName = app.activeDocument.name;
var basename = docName.match(/(.*)\.[^\.]+$/)[1];
var docPath = thedoc.path;
tifOpts = new TiffSaveOptions() ;
tifOpts.embedColorProfile = true;
tifOpts.imageCompression = TIFFEncoding.NONE;
tifOpts.layers = true;
app.activeDocument.saveAs((new File(docPath+'/'+basename+"_2"+'.tif')),tifOpts,false);
app.activeDocument.close();

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 03, 2020 May 03, 2020

Copy link to clipboard

Copied

Thank you all,
Will look into all of this soon!

Jakub

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 03, 2020 Dec 03, 2020

Copy link to clipboard

Copied

Hi @Stephen_A_Marsh 

STUDIO5FAA_0-1607006419027.png

I tried and it got an error.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 04, 2020 Dec 04, 2020

Copy link to clipboard

Copied

Perhaps try running outside of ESTK, directly in Photoshop, perhaps with a new copy/paste making sure that you have copied all the code.

 

I have tested on both Mac (Studio Code ES Debugger) and Win (ESKT) with no errors.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 05, 2020 Dec 05, 2020

Copy link to clipboard

Copied

LATEST

That's my mistake. it works fine.
Thanks @Stephen_A_Marsh 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines