How to check if an overlay already exists?

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

How to check if an overlay already exists?

ved sharma
Hi ImageJ users,

I'm writing a macro and I need to check if an overlay already exists in an image. Is there a way to do this? I am looking for something similar to "selectionType()" commmand, which returns -1 if there is no ROI.

Thanks,

Ved
Reply | Threaded
Open this post in threaded view
|

Re: How to check if an overlay already exists?

Tiago Ferreira-2
On 2011.11.08, at 15:24 , Ved Sharma wrote
> I'm writing a macro and I need to check if an overlay already exists in an image. Is there a way to do this? I am looking for something similar to "selectionType()" commmand, which returns -1 if there is no ROI.

Two options:
Overlay.size returns zero if the image does not have an overlay
getInfo("overlay") returns an empty string if the image does not have an overlay

if (Overlay.size==0 || getInfo("overlay"))
    exit("Image has no overlay");

-tiago
Reply | Threaded
Open this post in threaded view
|

Re: How to check if an overlay already exists?

ved sharma
In reply to this post by ved sharma
Hi Tiago,

Thanks for your reply. But I guess I did not put my question correctly. I want to check whether the overlay is hidden or not. So there is an overlay but I want to check the state (hidden or shown).

Ved
Reply | Threaded
Open this post in threaded view
|

Re: How to check if an overlay already exists?

Tiago Ferreira-2
On 2011.11.08, at 16:02 , Ved Sharma wrote
> I guess I did not put my question correctly. I want to check whether the overlay is hidden or not. So there is an overlay but I want to check the state (hidden or shown).

I knew it couldn't be that simple :)
Probably it would be useful to add such a function.

Right now the only thing I can think of is to use the Flatten command followed by Overlay.show/Overlay.hide and compare the flattened images to infer the hidden state of the overlay.
But that would be so wrong in so many levels...
-tiago
Reply | Threaded
Open this post in threaded view
|

Re: How to check if an overlay already exists?

ved sharma
In reply to this post by ved sharma
Basically I want to assign my macro to a shortcut key (e.g. F1), and when I press it, it should change the state of the overlay (hidden<->visible). So in the absence of a "isOverlayHidden" command, the best I can think of is:

//----------------------
a = random;
if(a>=0 &&amp; a<0.5)
        run("Show Overlay");
else
        run("Hide Overlay");
//----------------------

Any ideas if this can be made any better?

Ved
Reply | Threaded
Open this post in threaded view
|

Re: How to check if an overlay already exists?

Rasband, Wayne (NIH/NIMH) [E]
On Nov 8, 2011, at 5:57 PM, Ved Sharma wrote:

> Basically I want to assign my macro to a shortcut key (e.g. F1), and when I press it, it should change the state of the overlay (hidden<->visible). So in the absence of a "isOverlayHidden" command, the best I can think of is:
>
> //----------------------
> a = random;
> if(a>=0 &&amp; a<0.5)
> run("Show Overlay");
> else
> run("Hide Overlay");
> //----------------------
>
> Any ideas if this can be made any better?

The ImageJ 1.46a daily build adds an Overlay.hidden() macro function that can be used to determine if an overlay is hidden or not. Here is an example macro that, when you press "1", shows the overlay if it is hidden, or hides it if it showing:

  macro "Toggle Overlay [1]" {
     if (Overlay.size==0)
        exit("There is no overlay");
     if (Overlay.hidden)
        Overlay.show;
     else
        Overlay.hide;
  }

-wayne
Reply | Threaded
Open this post in threaded view
|

Re: How to check if an overlay already exists?

ved sharma
In reply to this post by ved sharma
Great!!! Thanks for adding this function.

Ved