Problem with normalized variance for stack
Posted by sathya1 on Jan 31, 2013; 4:47pm
URL: http://imagej.273.s1.nabble.com/Problem-with-normalized-variance-for-stack-tp5001625.html
Hi
I'm trying to extend the "Normalized variance" macro by Andy Weller from a single image to an entire stack. An then show those results in the results window. But I somehow am not able to make it work. Please help. This is the normalized variance macro by Andy Weller:
// A macro to determine image focal quality image-wide (not ROI-wide)
// Based on algorithm F-11 "Normalized Variance"
// In: Sun et al., 2004. MICROSCOPY RESEARCH AND TECHNIQUE 65, 139–149.
//
// Version: 0.3
// Date: 11/07/2006
// Author: Andy Weller
macro "Normalized_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;
normVar = 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;
}
}
normVar = b/(H*W*mean); // Maximum value is best-focused, decreasing as defocus increases
print(normVar); // This can also (should) be changed to return(normVar)
}
thanks!