Posted by
Zwick, Ari A. on
Jul 13, 2010; 9:52pm
URL: http://imagej.273.s1.nabble.com/Trouble-Calling-Variables-in-Macro-for-the-Image-Calculator-tp3687586p3687588.html
Hi Ben,
Stunning. Unfortunately that did not exclusively solve my problem, but
it did certainly help. The ultimate cure was actually redundancy. Now
before I close that problematic window I run:
selectImage(id);
selectwindow(Mask3.tif);
close();
It made it through 50 iterations without crashing. Thanks for the
advice, it was really helpful.
Ari Zwick
-----Original Message-----
From: ImageJ Interest Group [mailto:
[hidden email]] On Behalf Of
Ben Tupper
Sent: Tuesday, July 13, 2010 1:52 PM
To:
[hidden email]
Subject: Re: Trouble Calling Variables in Macro for the Image Calculator
Hi,
I think your best bet is to keep track of images by ID rather than by
name. Right after you instantiate/open/create/whatever an image use
the getImageID() function to get that image's unique identifier. For
most subsequent commands that operate on that image be sure to use the
command selectImage(id). Note that the Image Calculator command (and
perhaps others) will accept an image ID instead of image name, which
is very handy.
I will be surprised if that doesn't resolve the issue for you.
Cheers,
Ben
On Jul 13, 2010, at 2:33 PM, Zwick, Ari A. wrote:
> Dear ImageJ Community,
>
>
>
> I'm writing a macro that will loop ~800 times, and I'm getting a few
> glitches with my macro calling functions out of the order that I've
> written them in. My solution to this problem is to give individual
> titles to 1 set of problematic images (the rest use the same title for
> each iteration). So I was thinking of something simple such as naming
> my problematic image equal to the value of i (number of
> iterations). So
> I can rename the image rename(i) and the title works, however I can't
> get the Image Calculator to call the value of i, which will change for
> each iteration.
>
>
>
> Can I define a variable such as: p = getTitle(CurrentImage) to call in
> the Image Calculator? I was also thinking about the print command,
> but
> it doesn't seem clear to me that the value is easily accessible in the
> macro. I've been having problems with syntax, so I'd really
> appreciate
> any suggestions about how to call the variable properly, or any other
> work around. Below is a bit of the script that I'm trying to work
> with:
>
>
>
> width = getWidth();
>
> height = getHeight();
>
> work = 10;
>
> for (i=1; i<=work ; i++) {
>
>
>
> m = i/i;
>
> x = m*random() *(width-356);
>
> y = m*random() *(height-356);
>
> z = m*random() *451;
>
> (let p [ getTitle(getCurrentImage)])
>
>
>
> //I know that syntax for p is wrong, found it off a Fiji Wiki
>
> //Later...
>
>
>
> selectWindow("Sample");
>
> makePolygon(356,0,236,0,236,236,0,236,0,356,356,356);
>
> run("Analyze Particles...", "size=0-Infinity circularity=0.00-1.00
> show=Masks exclude");
>
> saveAs("Tiff", "/ecor/azwick/Macro/Mask3.tif");
>
> rename(i);
>
>
>
> imageCalculator("Add", "Mask2",p);
>
> rename("Edge Count");
>
>
>
> //Error
>
> //Later
>
>
>
> selectWindow("Mask3.tif");
>
> close();
>
>
>
> //Error Mask3.tif does not exit. (This is before I tried the i/p
> titles; the error that I'm trying to work around currently)
>
>
>
> I know this is kind of sloppy macro writing, but this is my first time
> actually modifying macro script rather than just recording. The
> saveAs
> Tiff is another attempt to prevent Mask3 from escaping my commands.
> My
> logic is that this problem probably won't go away, but if I can rename
> each file per iteration, then there won't be any overlap of files that
> don't get closed and mistakenly called in later iterations. I'm also
> aware that the CurrentImage command will cause some serious problems,
> because I have about 4 other windows open. I'd appreciate any help
> with
> this and thanks in advance.
>
>
>
> Ari Zwick
>
>
>
>