Login  Register

Re: Memory Problems in Fiji using macro setBatchMode(true)

Posted by JimmiB on Aug 13, 2013; 12:41am
URL: http://imagej.273.s1.nabble.com/Memory-Problems-in-Fiji-using-macro-setBatchMode-true-tp5004321p5004405.html

Thanks Wayne,
Much appreciated.
It seems to be working well.
Why are extra images being opened?
When run with batchmode off the images never appear.

There seems to be something strange going on here.
I just opened a 5000 frame stack

Then
ran
run("Scale...", "x=1.975 y=1.985 z=1.0 width=726 height=492 depth=5000
interpolation=Bicubic average process create title=Red_Engorged");
run("Scale...", "x=0.5 y=0.5 z=1.0 width=363 height=246 depth=5000
interpolation=Bilinear average process create title=Red_Engorged-1")

I then closed all the open images.

ImageJ shows <1% memory usage, however in the task manager javaw.exe is
using 8 486 740 K
Running the garbage collector does nothing.....
run("Close All"); does nothing

Does that imply some kind of memory leak?

Thanks again for your help.

Cheers

James

*
                       *
*Dr James Burchfield*
The Garvan Institute of Medical Research
384 Victoria Street
Darlinghurst, NSW, 2010
Australia

Email: [hidden email]
Phone:+61 2 92958229
Web: *www.garvan.org.au*


On Tue, Aug 13, 2013 at 2:31 AM, Rasband, Wayne (NIH/NIMH) [E] <
[hidden email]> wrote:

> 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
>

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