Posted by
F Javier Díez Guerra on
Jan 04, 2006; 3:58pm
URL: http://imagej.273.s1.nabble.com/automate-bkg-substract-from-roi-tp3704147p3704148.html
Wayne,
Thanks again for the macro to substract bkg for roi.
This has come when I was finishing a different approach (more inefficient).
I have no programming experience but had managed to get running a macro
that should also do the same work, although it is locked for stacks with
only 3 images, since I did not find the way to nest two "for()" loops. The
result was:
n = roiManager("count");
if (n==0)
exit("This macro requires at least one ROI Manager entry");
setSlice(1);
sum = 0;
for (j=0; j<n; j++) {
roiManager("select", j);
getStatistics(area, mean);
sum += mean;
}
average = sum/n;
print(average);
run("Select None");
run("Subtract...", "image value="+average);
setSlice(2);
sum = 0;
for (j=0; j<n; j++) {
roiManager("select", j);
getStatistics(area, mean);
sum += mean;
}
average = sum/n;
print(average);
run("Select None");
run("Subtract...", "image value="+average);
setSlice(3);
sum = 0;
for (j=0; j<n; j++) {
roiManager("select", j);
getStatistics(area, mean);
sum += mean;
}
average = sum/n;
print(average);
run("Select None");
run("Subtract...", "image value="+average);
As you see this is a simple copy/paste of the same routine for each image
in the stack.
Well, this has taken me some time of playing around with images. I hope
that the experience will be useful for future macros.
Best regards,
F Javier Diez-Guerra, PhD
Profesor Titular
Centro de Biologia Molecular Severo Ochoa
Facultad de Ciencias, Universidad Autónoma
Ctra Colmenar Viejo Km 15
Cantoblanco, 28049 Madrid
SPAIN
phone: +34 91 4978051
Fax: +34 91 4978087
e-mail:
[hidden email]