Login  Register

Memory leak when using Macro to process 1000+ images

Posted by George H on Aug 19, 2014; 11:11am
URL: http://imagej.273.s1.nabble.com/Memory-leak-when-using-Macro-to-process-1000-images-tp5009264.html

Hi,

I am using ImageJ v1.49e and I wrote a simple macro that will read in 1000+
images from a directory and perform some processing. Once its all over I
save the summaries to a file. I do this all in batchmode so the windows
don't open and close quickly.

So the issue is that the memory usage keeps rising until the program
crashes. I really do not know why this is happening and I am opening and
closing each image.

Can anyone locate in the code below where things are going wrong?  Thanks.

-----
Dialog.create("Select Options");
Dialog.addSlider("Subtract Background Rolling:", 0.0, 90.0, 30.0);
Dialog.addSlider("Min Particle Size (px):", 5, 90, 15);
Dialog.addSlider("Min Particle Circularity:", 0.0, 1.0, 0.40);
Dialog.addCheckbox("Save Summaries to file", true);
Dialog.show();

inputDir = getDirectory("Choose the Input Directory");
inputDir = replace(inputDir, "\\\\", "\\\\\\\\");

if(inputDir != "") {
inputList = getFileList(inputDir);
 rollingValue = Dialog.getNumber();
minParticleSize = Dialog.getNumber();
minParticleCirc = Dialog.getNumber();
 saveSummaries = Dialog.getCheckbox();
 setBatchMode(true);
 for (i=0; i < inputList.length; i++) {
showProgress(i+1, inputList.length);
 fileName = inputList[i];
imageAnalysis(inputDir, fileName, rollingValue, minParticleSize,
minParticleCirc);
 }
 if(saveSummaries) {
selectWindow("Summary");
 saveAs("Results", inputDir+"summaries.txt");
}

call("java.lang.System.gc");
 setBatchMode(false);

if(isOpen("Summary")) {
         selectWindow("Summary");
         run("Close" );
}
}
else {
exit("Must select an input and output directory");
}


function imageAnalysis(inputDir, fileName, rollingValue, circSize,
minCircularity) {
open(inputDir+fileName);
 run("Enhance Local Contrast (CLAHE)", "blocksize=127 histogram=256
maximum=3 mask=*None* fast_(less_accurate)");
run("8-bit");
 run("Subtract Background...", "rolling="+rollingValue);
setAutoThreshold("Triangle");
 setOption("BlackBackground", false);
run("Convert to Mask");
run("Set Measurements...", "area mean min centroid shape feret's
area_fraction redirect=None decimal=3");
 run("Analyze Particles...", "size="+circSize+"-Infinity
circularity="+minCircularity+"-1.00 exclude clear summarize");
 close();
}


--
George
[hidden email]

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html