http://imagej.273.s1.nabble.com/Memory-Problems-in-Fiji-using-macro-setBatchMode-true-tp5004321p5004405.html
Much appreciated.
It seems to be working well.
When run with batchmode off the images never appear.
There seems to be something strange going on here.
I then closed all the open images.
Running the garbage collector does nothing.....
Thanks again for your help.
> On Aug 12, 2013, at 3:07 AM, James Burchfield wrote:
>
> > Hi all,
> >
> > I believe I am having a similar issue to this. I am running a macro
> designed to open an image crop out 2 ROI's resize one of them and save the
> new images. The process works fine in both ImageJ and Fiji except that it
> rapidly builds up memory usage.
>
> The macro is opening five images per loop iteration that are not closed.
> You can see this by changing the line
>
> print (dir1+list[i]);
>
> to
>
> print (i, nImages, dir1+list[i]);
>
> After making this change and running the macro I get output that looks
> likes this:
>
> 1 0 /Users/wayne/stack/Untitled0001.tif
> 2 5 /Users/wayne/stack/Untitled0002.tif
> 3 10 /Users/wayne/stack/Untitled0003.tif
> 4 15 /Users/wayne/stack/Untitled0004.tif
> 5 20 /Users/wayne/stack/Untitled0005.tif
>
> I was able to fix the problem by changing
>
> close("Red");
> close("original" + i);
>
> to
>
> run("Close All");
>
> Here is the modified macro:
>
> dir1 = getDirectory("Choose Source Directory ");
> dest = getDirectory("Choose Destination Directory ");
> list = getFileList(dir1);
> greendir = dest + "greenTEMP"+File.separator;
> reddir = dest + "redTEMP"+File.separator;
> //print(greendir);
> File.makeDirectory(greendir);
> File.makeDirectory(reddir);
> x=getString("set x offset", 3);
> y=getString("set y offset", 1);
> setBatchMode(true);
> for (i=1; i<list.length; i++) {
> print (i, nImages, dir1+list[i]);
> if (endsWith(list[i],".tif")) {
> showProgress(i+1, list.length);
> open (dir1+list[i]); //open image i
> rename ("original" + i);
> run("Rotate 90 Degrees Right");
> //define Green Channel
> w=getWidth()-16;
> h=getHeight()/2-10;
> makeRectangle(x, y, w, h);
> run("Duplicate...", "title=Green");
> saveAs("Tiff", greendir+"green_"+i+".tif");
> close("Green");
> //define red channel
> selectWindow("original"+i);
> w_red=w/1.975*2;
> h_red=h/1.985*2;
> makeRectangle(3, 10+h_red, w_red, h_red);
> run("Duplicate...", "title=Red_Original");
> run("Scale...", "x=1.975 y=1.985 interpolation=Bicubic create
> title=Red_Engorged");
> close("Red_Original");
> run("Scale...", "x=0.5 y=0.5 interpolation=Bilinear average
> create title=Red");
> close("Red_Engorged");
> selectWindow("Red");
> run("Rotate... ", "angle=0.25 grid=2 interpolation=Bilinear
> stack");
> saveAs("Tiff", reddir +"red_"+i+".tif");
> run("Close All");
> }
> }
>
>
> -wayne
>
> > I have tried incorporating the suggested
> > run("Collect Garbage"); in Fiji
> >
> > All this has done is slow down the processing, but the memory issue is
> still there.
> >
> > I am running the latest nightly build of ImageJ.
> >
> > Any help would be greatly appreciated.
> >
> > The macro in question is below.
> >
> > Cheers,
> > James
> >
> > macro "seperate channels[s]"{
> >
> > dir1 = getDirectory("Choose Source Directory ");
> > dest = getDirectory("Choose Destination Directory ");
> > list = getFileList(dir1);
> > greendir = dest + "greenTEMP"+File.separator;
> > reddir = dest + "redTEMP"+File.separator;
> > //print(greendir);
> > File.makeDirectory(greendir);
> > File.makeDirectory(reddir);
> > x=getString("set x offset", 3);
> > y=getString("set y offset", 1);
> > setBatchMode(true);
> > for (i=1; i<list.length; i++) {
> > print (dir1+list[i]);
> > if (endsWith(list[i],".tif")){
> > showProgress(i+1, list.length);
> > open (dir1+list[i]); //open image i
> > rename ("original" + i);
> > run("Rotate 90 Degrees Right");
> > //define Green Channel
> > w=getWidth()-16;
> > h=getHeight()/2-10;
> > makeRectangle(x, y, w, h);
> > run("Duplicate...", "title=Green");
> > saveAs("Tiff", greendir+"green_"+i+".tif");
> > close("Green");
> >
> >
> > //define red channel
> > selectWindow("original"+i);
> > w_red=w/1.975*2;
> > h_red=h/1.985*2;
> > makeRectangle(3, 10+h_red, w_red, h_red);
> > run("Duplicate...", "title=Red_Original");
> > run("Scale...", "x=1.975 y=1.985 interpolation=Bicubic create
> title=Red_Engorged");
> > close("Red_Original");
> > run("Scale...", "x=0.5 y=0.5 interpolation=Bilinear average create
> title=Red");
> > close("Red_Engorged");
> > selectWindow("Red");
> > run("Rotate... ", "angle=0.25 grid=2 interpolation=Bilinear
> stack");
> > saveAs("Tiff", reddir +"red_"+i+".tif");
> > close("Red");
> > close("original" + i);
> > run("Collect Garbage");
> > }
> > }
> >
> > --
> > ImageJ mailing list:
http://imagej.nih.gov/ij/list.html>
> --
> ImageJ mailing list:
http://imagej.nih.gov/ij/list.html>