Login  Register

Macro stopped with too many windows open

Posted by weide025 on Mar 25, 2014; 7:45pm
URL: http://imagej.273.s1.nabble.com/Macro-stopped-with-too-many-windows-open-tp5007077.html

I am new to ImageJ and working with macros.  

I am using Threshold Colour to select specific areas or ROI within an image.  I want to know the total number of selected pixels and then save the image with just the selected area, for 6,000 images.  The following macro works in the batch process, but it stops after only 210 images.  The problem seems to be too many windows are open.  Each image that is processed leaves the "Threshold Colour" window open.  Is there some code I can include in the macro that will close that window after it processes an image?  

Thanks!

imgName=getTitle();
run("Duplicate...", "title=1.tif");
run("Threshold Colour");
// Threshold Colour v1.12a------
// Autogenerated macro, single images only!
// G. Landini 27/Sep/2010.
//
min=newArray(3);
max=newArray(3);
filter=newArray(3);
a=getTitle();
run("HSB Stack");
run("Convert Stack to Images");
selectWindow("Hue");
rename("0");
selectWindow("Saturation");
rename("1");
selectWindow("Brightness");
rename("2");
min[0]=45;
max[0]=255;
filter[0]="pass";
min[1]=40;
max[1]=255;
filter[1]="pass";
min[2]=40;
max[2]=255;
filter[2]="pass";
for (i=0;i<3;i++){
  selectWindow(""+i);
  setThreshold(min[i], max[i]);
  run("Convert to Mask");
  if (filter[i]=="stop")  run("Invert");
}
imageCalculator("AND create", "0","1");
imageCalculator("AND create", "Result of 0","2");
for (i=0;i<3;i++){
  selectWindow(""+i);
  close();
}
selectWindow("Result of 0");
close();
selectWindow("Result of Result of 0");
rename(a);
// Threshold Colour ------------
run("8-bit");
run("Create Selection");
selectWindow(imgName);
run("Restore Selection");
run("Measure");
run("Clear Outside", "slice");