Localizing a ROI to a specific (C, Z, T) position

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

Localizing a ROI to a specific (C, Z, T) position

ctrueden
Hi Wayne & everyone,

I am developing a macro that lets you add points to the ROI manager to mark
(X, Y) coordinates on specific image planes. I see that the Roi API has
getCPosition(), getZPosition() and getTPosition() methods to retrieve the
(C, Z, T) plane position associated with a particular ROI. Unfortunately,
it seems that when marking a point and using the T key to add it to the ROI
manager, the points do not retain their specific (C, Z, T) localization,
but only remember the Z component.

The following example demonstrates the issue:
https://gist.github.com/ctrueden/5164235

If you run the draw-rois.ijm macro, it will open Mitosis and generate two
sample ROIs at different positions. If you then run roi-coordinates.bsh, it
will dump the (C, Z, T) positions of those ROIs to the log, which shows
that the ROIs were not completely localized to a specific (C, Z, T)
coordinate.

My question is: how can I ensure the ROIs do get localized? Or, does anyone
have an alternate recommendation for marking (X, Y) points at specific
image planes? My ultimate goal is to produce a working macro like the
tracking-movie.bsh linked in the gist above, but I can't find a way to
preserve the (C, Z, T) coordinates of the added points.

Thanks,
Curtis

P.S. Looking at the RoiManager.restore(ImagePlus, int, boolean) method, I
see that the logic for jumping the current image's position to that of the
selected ROI is also quite complicated (and to me, unintuitive). The
behavior I would prefer is for the image position to just match that of the
selected ROI in all cases, but perhaps there are historical reasons for the
current behavior?

P.P.S. The original version of tracking-movie was a macro, and can be found
at:

https://github.com/uw-loci/misc-plugins/blob/5234fa35/src/main/resources/tracking-movie.ijm

I converted it to Beanshell (part of the gist above) so that I could access
the Roi.get[CZT]Position() methods, but then discovered the the (C, Z, T)
coordinates were not accessible that way either...

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Localizing a ROI to a specific (C, Z, T) position

dscho
Hi Curtis,

On Thu, 14 Mar 2013, Curtis Rueden wrote:

> I am developing a macro that lets you add points to the ROI manager to mark
> (X, Y) coordinates on specific image planes. I see that the Roi API has
> getCPosition(), getZPosition() and getTPosition() methods to retrieve the
> (C, Z, T) plane position associated with a particular ROI. Unfortunately,
> it seems that when marking a point and using the T key to add it to the ROI
> manager, the points do not retain their specific (C, Z, T) localization,
> but only remember the Z component.
>
> The following example demonstrates the issue:
> https://gist.github.com/ctrueden/5164235
>
> If you run the draw-rois.ijm macro, it will open Mitosis and generate two
> sample ROIs at different positions. If you then run roi-coordinates.bsh, it
> will dump the (C, Z, T) positions of those ROIs to the log, which shows
> that the ROIs were not completely localized to a specific (C, Z, T)
> coordinate.
>
> My question is: how can I ensure the ROIs do get localized? Or, does anyone
> have an alternate recommendation for marking (X, Y) points at specific
> image planes? My ultimate goal is to produce a working macro like the
> tracking-movie.bsh linked in the gist above, but I can't find a way to
> preserve the (C, Z, T) coordinates of the added points.

I think the safest way might be to force a given naming by using a
different key than 't' and running a macro that uses roiManager("Rename",
label); to use a consistent name for the ROI.

To retrieve the position from the ROI manager, unfortunately the macro
language is not enough. But you can embed a Javascript snippet in a macro
to retrieve the name of the currently-selected ROI and parse it into the
coordinates.

Here is an example macro set which you can paste into the Script Editor
and install after Language>ImageJ Macro with Run>Install Macro (which
installs the 't' and 'T' shortcuts, 't' to add the current ROI with
coordinates to the ROI manager, 'T' to retrieve the next ROI after the
currently-selected one in the manager):

-- snip --
macro "Add to Manager Plus [t]" {
        index = roiManager("Count");
        run("Add to Manager");
        roiManager("Select", index);
        Stack.getPosition(channel, slice, frame);
        roiManager("Rename", "@" + channel + ";" + slice + ";" + frame);
}

macro "Jump to next ROI [T]" {
        eval("script",
                "importClass(Packages.ij.plugin.frame.RoiManager);" +
                "manager = RoiManager.getInstance();" +
                "index = manager.getSelectedIndex() + 1;" +
                "if (index >= manager.getCount()) index = 0;" +
                "name = manager.getName(index);" +
                "if (name.startsWith('@')) {" +
                "  coords = name.substring(1).replace(';', ',');" +
                "  IJ.runMacro('Stack.setPosition(' + coords + ');');" +
                "}" +
                "manager.select(index);");
}
-- snap --

You'll see that I run a Javascript snippet in the second macro that calls
itself a macro snippet. The reason for this: the macro API and the Java
API make different things easy...

Ciao,
Dscho

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Localizing a ROI to a specific (C, Z, T) position

Rasband, Wayne (NIH/NIMH) [E]
In reply to this post by ctrueden
On Mar 14, 2013, at 3:25 PM, Curtis Rueden wrote:

> Hi Wayne & everyone,
>
> I am developing a macro that lets you add points to the ROI manager to mark
> (X, Y) coordinates on specific image planes. I see that the Roi API has
> getCPosition(), getZPosition() and getTPosition() methods to retrieve the
> (C, Z, T) plane position associated with a particular ROI. Unfortunately,
> it seems that when marking a point and using the T key to add it to the ROI
> manager, the points do not retain their specific (C, Z, T) localization,
> but only remember the Z component.

This bug is fixed in the ImageJ 1.47n daily build. Hyperstack selections added to the ROI Manager are now restored to their original CZT positions.

-wayne

> The following example demonstrates the issue:
> https://gist.github.com/ctrueden/5164235
>
> If you run the draw-rois.ijm macro, it will open Mitosis and generate two
> sample ROIs at different positions. If you then run roi-coordinates.bsh, it
> will dump the (C, Z, T) positions of those ROIs to the log, which shows
> that the ROIs were not completely localized to a specific (C, Z, T)
> coordinate.
>
> My question is: how can I ensure the ROIs do get localized? Or, does anyone
> have an alternate recommendation for marking (X, Y) points at specific
> image planes? My ultimate goal is to produce a working macro like the
> tracking-movie.bsh linked in the gist above, but I can't find a way to
> preserve the (C, Z, T) coordinates of the added points.
>
> Thanks,
> Curtis
>
> P.S. Looking at the RoiManager.restore(ImagePlus, int, boolean) method, I
> see that the logic for jumping the current image's position to that of the
> selected ROI is also quite complicated (and to me, unintuitive). The
> behavior I would prefer is for the image position to just match that of the
> selected ROI in all cases, but perhaps there are historical reasons for the
> current behavior?
>
> P.P.S. The original version of tracking-movie was a macro, and can be found
> at:
>
> https://github.com/uw-loci/misc-plugins/blob/5234fa35/src/main/resources/tracking-movie.ijm
>
> I converted it to Beanshell (part of the gist above) so that I could access
> the Roi.get[CZT]Position() methods, but then discovered the the (C, Z, T)
> coordinates were not accessible that way either...
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Localizing a ROI to a specific (C, Z, T) position

ctrueden
Hi Wayne & everyone,

> Hyperstack selections added to the ROI Manager are now restored to
> their original CZT positions.

Thank you very much! It works perfectly.

For those interested, I published a new version of the Tracking Movie
script to the LOCI Fiji update site. Of course, you will need today's daily
build of ImageJ for it to work as expected, until 1.47n is finalized. See
the web page for details:

    http://loci.wisc.edu/software/tracking-movie-script

Regards,
Curtis


On Fri, Mar 15, 2013 at 12:13 PM, Rasband, Wayne (NIH/NIMH) [E] <
[hidden email]> wrote:

> On Mar 14, 2013, at 3:25 PM, Curtis Rueden wrote:
>
> > Hi Wayne & everyone,
> >
> > I am developing a macro that lets you add points to the ROI manager to
> mark
> > (X, Y) coordinates on specific image planes. I see that the Roi API has
> > getCPosition(), getZPosition() and getTPosition() methods to retrieve the
> > (C, Z, T) plane position associated with a particular ROI. Unfortunately,
> > it seems that when marking a point and using the T key to add it to the
> ROI
> > manager, the points do not retain their specific (C, Z, T) localization,
> > but only remember the Z component.
>
> This bug is fixed in the ImageJ 1.47n daily build. Hyperstack selections
> added to the ROI Manager are now restored to their original CZT positions.
>
> -wayne
>
> > The following example demonstrates the issue:
> > https://gist.github.com/ctrueden/5164235
> >
> > If you run the draw-rois.ijm macro, it will open Mitosis and generate two
> > sample ROIs at different positions. If you then run roi-coordinates.bsh,
> it
> > will dump the (C, Z, T) positions of those ROIs to the log, which shows
> > that the ROIs were not completely localized to a specific (C, Z, T)
> > coordinate.
> >
> > My question is: how can I ensure the ROIs do get localized? Or, does
> anyone
> > have an alternate recommendation for marking (X, Y) points at specific
> > image planes? My ultimate goal is to produce a working macro like the
> > tracking-movie.bsh linked in the gist above, but I can't find a way to
> > preserve the (C, Z, T) coordinates of the added points.
> >
> > Thanks,
> > Curtis
> >
> > P.S. Looking at the RoiManager.restore(ImagePlus, int, boolean) method, I
> > see that the logic for jumping the current image's position to that of
> the
> > selected ROI is also quite complicated (and to me, unintuitive). The
> > behavior I would prefer is for the image position to just match that of
> the
> > selected ROI in all cases, but perhaps there are historical reasons for
> the
> > current behavior?
> >
> > P.P.S. The original version of tracking-movie was a macro, and can be
> found
> > at:
> >
> >
> https://github.com/uw-loci/misc-plugins/blob/5234fa35/src/main/resources/tracking-movie.ijm
> >
> > I converted it to Beanshell (part of the gist above) so that I could
> access
> > the Roi.get[CZT]Position() methods, but then discovered the the (C, Z, T)
> > coordinates were not accessible that way either...
> >
> > --
> > 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