macro:variance
Variance
A macro to determine image focal quality image-wide (not ROI-wide).
Note (2011): please note that this macro is not really necessary as ImageJ already supports computation of the standard deviation via the same command used to obtain the mean image value:
run("Set Measurements...", " mean standard redirect=None decimal=5");
The variance is the squared value of the standard deviation.
// A macro to determine image focal quality image-wide (not ROI-wide) // Based on algorithm F-10 "Variance" // In: Sun et al., 2004. MICROSCOPY RESEARCH AND TECHNIQUE 65, 139–149. // // Version: 0.1 // Date: 14/07/2006 // Author: Andy Weller macro "Variance_" { run("Clear Results"); run("Set Measurements...", " mean redirect=None decimal=5"); run("Measure"); mean = getResult("Mean"); selectWindow("Results"); run("Close"); W = getWidth(); H = getHeight(); b = 0; Var = 0; // Set to 0 which is out of focus for (j=0; j<H; j++) { for (i=0; i<W; i++) { p = getPixel(i,j); t = (p-mean)*(p-mean); b += t; } } Var = b/(H*W); // Maximum value is best-focused, decreasing as defocus increases print(Var); // This can also (should) be changed to return(Var) }
by Andy Weller — last modified 2006-07-14 20:44
macro/variance.txt · Last modified: 2019/04/12 13:13 by 127.0.0.1