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.
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
...
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.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
You can make a feature request here:
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.
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!
Copy link to clipboard
Copied
Greetings, Im new at scripting... Will this method move the most OOF (Out of Focus) Image to a separate folder or vice versa?
Copy link to clipboard
Copied
If you are referring to the script that I posted, then the description says it all:
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.
So no, it does not move images, it writes a spreadsheet file to "log" each image. The Standard Deviation value can be sorted in the spreadsheet.
Copy link to clipboard
Copied
Have you read »Depth of field blending« here?
Copy link to clipboard
Copied
Hi! thank you for your answer. What should I look for in this document?
Copy link to clipboard
Copied
»Depth of field blending«?
Copy link to clipboard
Copied
I really can't understand what combining images has to do with my question.
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.
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.
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.
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.
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 š
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 š
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
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));
}
Copy link to clipboard
Copied
@maurot43944773 ā so, how did the script work for you?
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.
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 š
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?
Copy link to clipboard
Copied
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:
Copy link to clipboard
Copied
Did you ever find out what method work best for you? i am currently working in the way way that you wre then and is now looking for a solution to detect soft/out of focus images