Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


least blurred image

Community Beginner ,
Jul 13, 2021 Jul 13, 2021

Copy link to clipboard

Copied

Hi all, I have Adobe Photoshop 21.0.2 and a problem.

I have a set of images (of the same thing, let's say a page with handwritten text), and these images can have a certain degree of blurriness. I wonder if there's a way for Photoshop to tell me which image is the least blurred.

TOPICS
Actions and scripting, Windows

Views

272

Likes

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

Adobe Community Professional , Jul 18, 2021 Jul 18, 2021
The following script will process a top level directory and write out a .csv file to the desktop with the standard deviation value for each image. The highest Std. Dev. value will be the "sharpest" image. /* least blurred image https://community.adobe.com/t5/photoshop/least-blurred-image/m-p/12183817 Recursive processing to CSV code based on: https://forums.adobe.com/message/9697558#9697558 Standard deviation histogram processing code based on: https://community.adobe.com/t5/photoshop/how-t...

Likes

Translate

Translate
Adobe Community Professional ,
Jul 13, 2021 Jul 13, 2021

Copy link to clipboard

Copied

Two options that spring to mind...

 

* Compare histogram values at 100% view for the image with the higher Std. Dev. value which will be "sharper" (ensure that the histogram is refreshed, uncached)

 

* Use Adobe Bridge and your eyes with the loupe tool (no, I'm not being sarcastic)

 

A third option would be to use shake reduction to examine the PSF "blur estimation region" preview manually for the same selected region for each image.

Likes

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 ,
Jul 13, 2021 Jul 13, 2021

Copy link to clipboard

Copied

Thank you for your answer.
In this way, however, I should make the choice of the better image, and I,
being human, am fallacious. It would be way better if it was a task for PS
to do by itself.
Can this be a feature I could ask?

Likes

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
Adobe Community Professional ,
Jul 14, 2021 Jul 14, 2021

Copy link to clipboard

Copied

You can make a feature request here:

 

Submit product feedback

 

For now, I can envision a script where you would select a folder of input images and a text file would be output listing the source filename and the standard deviation value for each file.

 

Likes

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 ,
Jul 14, 2021 Jul 14, 2021

Copy link to clipboard

Copied

I've studied the problem, and it seems the solution lies in making a grayscale of each image, an histogram equalization, followed by a convolution of some sort (or more than one, aggregated with an euclidean norm, or a mean) -- it seems there are more than one kernel that can be applied --, then selecting the maximum value of the variance, and then selecting the image with the maximum among these values.

I don't know if everything can be done via a script (output a number from an image as input?).

Thank you for your support!

Likes

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
Adobe Community Professional ,
Jul 14, 2021 Jul 14, 2021

Copy link to clipboard

Copied

Have you read »Depth of field blending« here? 

Combine images with Auto-Blend Layers

Likes

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 ,
Jul 14, 2021 Jul 14, 2021

Copy link to clipboard

Copied

Hi! thank you for your answer. What should I look for in this document?

Likes

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
Adobe Community Professional ,
Jul 14, 2021 Jul 14, 2021

Copy link to clipboard

Copied

»Depth of field blending«? 

Likes

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 ,
Jul 15, 2021 Jul 15, 2021

Copy link to clipboard

Copied

I really can't understand what combining images has to do with my question.

Likes

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
Adobe Community Professional ,
Jul 15, 2021 Jul 15, 2021

Copy link to clipboard

Copied

I was thinking along the same line. By using depth of blending of focus stacking, Photoshop will combine the sharpest parts of each image. At least it should in theory. With that type of image, PS might have difficulty detecting which parts are sharpest due to large areas with little detail.

Likes

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 ,
Jul 15, 2021 Jul 15, 2021

Copy link to clipboard

Copied

Ok, now I think I understand. But that's not what I've asked.

I don't want a costructed image, I would like to know which one is the best.

Likes

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
Adobe Community Professional ,
Jul 15, 2021 Jul 15, 2021

Copy link to clipboard

Copied

»I don't want a costructed image, I would like to know which one is the best.«

What is the point of this in your process? 

 

@Stephen_A_Marsh  already provided a Histogram approach, one could automate that with Scripting. 

Likes

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 ,
Jul 17, 2021 Jul 17, 2021

Copy link to clipboard

Copied

I don't want a constructed composite image because it can lead to artifacts, missing parts, or irregular areas (one taken from an image, another from another, ...). Since I have to photograph a document I would like to have an intact "original" image. I don't know if I've made myself clear.

Likes

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
Adobe Community Professional ,
Jul 17, 2021 Jul 17, 2021

Copy link to clipboard

Copied

If you view at 100% and can't immediately decide which is sharpest, then they are equally sharp. Don't overcomplicate this 😉

 

 

Likes

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 ,
Jul 17, 2021 Jul 17, 2021

Copy link to clipboard

Copied

Each image is 2976×3968, and I have more than 1500 images (each document repeated 5-6 times). If I have to look each one of them I'll surely die 😛

Likes

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
Adobe Community Professional ,
Jul 17, 2021 Jul 17, 2021

Copy link to clipboard

Copied

I was hoping to stand on the shoulders of gaints, however, finding a working script to get the Standard Deviation is proving to be difficult:

 

How to get the histogram's Std Dev

 

Likes

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
Adobe Community Professional ,
Jul 18, 2021 Jul 18, 2021

Copy link to clipboard

Copied

The following script will process a top level directory and write out a .csv file to the desktop with the standard deviation value for each image. The highest Std. Dev. value will be the "sharpest" image.

 

/* 
least blurred image
https://community.adobe.com/t5/photoshop/least-blurred-image/m-p/12183817

Recursive processing to CSV code based on:
https://forums.adobe.com/message/9697558#9697558

Standard deviation histogram processing code based on:
https://community.adobe.com/t5/photoshop/how-to-get-the-histogram-s-std-dev/td-p/9875041
*/

#target photoshop;
app.bringToFront();

main();

function main() {
    var inputFolder = Folder.selectDialog("Select the folder to process:");
    if (inputFolder === null) return;

    // Add or remove file extensions as required
    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 outputFile = File("~/Desktop/" + decodeURI(inputFolder.name) + ".csv");
    outputFile.open('w');
    outputFile.writeln('Filename,Highest Std. Dev. Value = "Sharpest" Image');

    for (var a in fileList) {

        open(fileList[a]);

        ///////////////////////////////////

        /* 
        How to get the histogram's Std Dev
        https://community.adobe.com/t5/photoshop/how-to-get-the-histogram-s-std-dev/td-p/9875041
        Credit to c.pfaffenbichler for the 2018 code and thanks to Kukurykus for the 2021 update!
        */
        if (app.documents.length > 0 && app.activeDocument.mode == DocumentMode.RGB) {
            var theR = histogramMeanStandardDeviation(app.activeDocument.channels[0].histogram);
            var theG = histogramMeanStandardDeviation(app.activeDocument.channels[1].histogram);
            var theB = histogramMeanStandardDeviation(app.activeDocument.channels[2].histogram);
            var theStdDev = (((theR[2] + theG[2] + theB[2]) / 3).toFixed(2));
            // Write the filename and values
            outputFile.writeln(decodeURI(activeDocument.name) + "," + theStdDev);

        }

        ////// get mean of histogram //////
        function histogramMeanStandardDeviation(theHist) {
            // get total number;
            var thePixels = 0;
            for (var m = 0; m < theHist.length; m++) {
                thePixels = thePixels + theHist[m];
            }

            // get mean and median;
            var theMean = 0;
            var aTotal = 0;
            var check = false;
            for (var n = 0; n < theHist.length; n++) {
                theMean = theMean + (n * theHist[n] / thePixels);
                aTotal = aTotal + theHist[n];
                if (aTotal >= thePixels / 2 && check === false) {
                    theMedian = n;
                    check = true;
                }
            }

            // get standard deviation;
            var theStandDev = 0;
            for (var o = 0; o < theHist.length; o++) {
                theStandDev = theStandDev + (Math.pow((o - theMean), 2) * theHist[o]);
            }
            theStandDev = Math.sqrt(theStandDev / thePixels);
            //
            return ([theMean, theMedian, theStandDev]);
        }

        ///////////////////////////////////

        app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
    }

    outputFile.close();
    app.beep();
    alert("CSV created:" + "\n" + decodeURI(outputFile));
}

 

 

Likes

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
Adobe Community Professional ,
Jul 25, 2021 Jul 25, 2021

Copy link to clipboard

Copied

@maurot43944773 – so, how did the script work for you?

Likes

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 ,
Jul 26, 2021 Jul 26, 2021

Copy link to clipboard

Copied

Thank you so much for the script. I didn't know such a thing was possible.

For now I solved my problem by a simple java application that reads all the images in a folder and tell me which one is the sharpest. I though it was faster to load and process than opening PS, load/process all the images, extracting a value from each one, and select the greatest.

Likes

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
Adobe Community Professional ,
Jul 26, 2021 Jul 26, 2021

Copy link to clipboard

Copied

Could do you please do two things:

- share an image you use to test above script with

- mark the given answer as the correct solution 😉

Likes

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
Adobe Community Professional ,
Jul 26, 2021 Jul 26, 2021

Copy link to clipboard

Copied

What Java app? ImageJ? Something else? What method does it use to determine the sharpest image? Can you share links for more info?

 

Does the Java app's "sharpest image" agree with the Photoshop scripts highest Std. Dev. value?

Likes

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 ,
Jul 30, 2021 Jul 30, 2021

Copy link to clipboard

Copied

LATEST

It's a simple console java app (LeastBlurredImage).

 

I found several kernels that can be applied to the image.

The solution lies in making a grayscale of each image, an histogram equalization, followed by a convolution with a kernel, then selecting the maximum value of the variance, and then selecting the image with the maximum among these values.

 

The images are along the lines of deed 15600301 - Copy:

deed-15600301-Copy.jpg

Likes

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