Posted by
Wayne Rasband on
URL: http://imagej.273.s1.nabble.com/Batch-processing-images-with-custom-threshold-values-tp3698896p3698897.html
Here is a macro that runs the particle analyzer on all the images in
a folder using custom threshold values and saves the results as a
text file. It requires ImageJ 1.38o or later. The particle analyzer
in earlier versions created a "Summary" window for each image.
requires("1.38o");
dir = getDirectory("Choose a Directory ");
list = getFileList(dir);
setBatchMode(true);
for (i=0; i<list.length; i++) {
showProgress(i, list.length);
open(dir+list[i]);
getStatistics(area, mean, min, max, std);
threshold = mean + 2.5*std;
setThreshold(threshold, 255);
run("Analyze Particles...", "size=10-1000 summarize");
close;
}
selectWindow("Summary");
saveAs("Text", getDirectory("home")+"Summary.txt");
-wayne
On Jul 4, 2007, at 5:37 PM, Adem Can wrote:
> Dear List members,
>
> I am working on a project which requires cell counts from thousands of
> images. Obviously, batch processing is the right way to work on these
> images. I am not a programmer but still managed to reverse engineer
> some
> batch processing macros originally written for other functions for
> myself.
> But still there are problems that I need your expertise to solve.
>
> These are 8-bit images of immunoreactive neurons to be counted. I
> can't use
> the built-in autothresholding or entropy methods. Instead for each
> image a
> different threshold value is calculated according to the following
> formula:
> mean gray values+(2.5xSTD). I can calculate these values en masse
> with batch
> statistics macro. But after that, I have to do actual cell counting
> one by
> one, entering the appropriate threshold value for each image, a
> process
> which is, needlessly to say, unproductive.
>
> The ideal macro will batch process the following steps:
>
> -Open each image from a folder
> -Calculate the threshold value for that image, according to a user
> defined
> algorithm (e.g. mean gray values+(2.5xSTD))
> -Calculate number and total area of cells according to user defined
> parameters (e.g. min-max pixel size) using the threshold value from
> the
> previous step
> -Export these cell number and area values with the file name of the
> image
> into an Excel sheet (or a text file)
>
> So far I could not write such a macro. Thank you in advance for
> your help.
>
>
> Adem Can
> The University of Texas at Austin, Department of Psychology