Macro stopped with too many windows open

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Macro stopped with too many windows open

weide025
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");

Reply | Threaded
Open this post in threaded view
|

Re: Macro stopped with too many windows open

Gabriel Landini
On Tuesday 25 Mar 2014 12:45:44 you wrote:
> 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?  *

> imgName=getTitle();
> run("Duplicate...", "title=1.tif");
> run("Threshold Colour");

I have not tried your code, but I do not think you need the 3rd line. The
macro generated after that line is precisely to do what you chose before
pressing "macro" and do it programatically without calling the plugin.

You need to close the images that you do not need, for example, at the end:

selectWindow(imgName);
close();

Not sure you need  this line at the end, *after* you measured, as it would not
do anything:
run("Clear Outside", "slice");

Hope it helps

Gabriel

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