Macro commands to move overlay

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

Macro commands to move overlay

Straub, Volko A. (Dr.)
I have written a macro that creates a series of rectangular overlays on an image. Once the overlays are created I can click on an overlay label/index and use the mouse to move the overlay. However, I would like to move the existing overlays from a macro (i.e. enter specific coordinates rather than manually drag the overlay with the mouse). I am aware that I could select the overlay from a macro, then delete it and redraw a new overlay at the new coordinates. However, doing it this way results in altering the index for all other overlays and gives the new overlay the highest index. This makes it a bit difficult to keep track of the indices of all overlays. So, I was wondering whether there are any commands that can be used to directly move the position of an existing overlay equivalent to clicking on the overlay with the mouse and dragging it?
Any advice/suggestion would be very welcome.

Volko

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

Re: Macro commands to move overlay

Rasband, Wayne (NIH/NIMH) [E]
On Aug 28, 2013, at 5:48 AM, Straub, Volko (Dr.) wrote:

> I have written a macro that creates a series of rectangular overlays on an image. Once the overlays are created I can click on an overlay label/index and use the mouse to move the overlay. However, I would like to move the existing overlays from a macro (i.e. enter specific coordinates rather than manually drag the overlay with the mouse). I am aware that I could select the overlay from a macro, then delete it and redraw a new overlay at the new coordinates. However, doing it this way results in altering the index for all other overlays and gives the new overlay the highest index. This makes it a bit difficult to keep track of the indices of all overlays. So, I was wondering whether there are any commands that can be used to directly move the position of an existing overlay equivalent to clicking on the overlay with the mouse and dragging it?
> Any advice/suggestion would be very welcome.

The ImageJ 1.48c daily build adds an Overlay.moveSelection() function you can use to move overlay selections. Here is an example that creates an overlay with three selections, moves the second selection to a new location and then moves it back to its original location.

  requires("1.48c");
  newImage("Untitled", "8-bit black", 500, 500, 1);
  makeRectangle(50, 50, 100, 100);
  run("Add Selection...");
  makeRectangle(200, 200, 100, 100);
  run("Add Selection...");
  makeRectangle(350, 350, 100, 100);
  run("Add Selection...");
  run("Select None");
  wait(1500);
  Overlay.moveSelection(1, 350, 50);
  wait(1500);
  Overlay.moveSelection(1, 200, 200);

-wayne

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

Re: Macro commands to move overlay

Straub, Volko A. (Dr.)
Thanks Wayne, this was exactly the type of command I was looking for.
As a workaround, I have also learned that it is possible to achieve this
by adding the overlay to the ROI manager, select an ROI, use
makeRectangle to draw a selection followed by the update ROI manager
command (Thanks Kees for the tip).

Regards,
Volko


On 29/08/2013 01:00, Rasband, Wayne (NIH/NIMH) [E] wrote:

> On Aug 28, 2013, at 5:48 AM, Straub, Volko (Dr.) wrote:
>
>> I have written a macro that creates a series of rectangular overlays on an image. Once the overlays are created I can click on an overlay label/index and use the mouse to move the overlay. However, I would like to move the existing overlays from a macro (i.e. enter specific coordinates rather than manually drag the overlay with the mouse). I am aware that I could select the overlay from a macro, then delete it and redraw a new overlay at the new coordinates. However, doing it this way results in altering the index for all other overlays and gives the new overlay the highest index. This makes it a bit difficult to keep track of the indices of all overlays. So, I was wondering whether there are any commands that can be used to directly move the position of an existing overlay equivalent to clicking on the overlay with the mouse and dragging it?
>> Any advice/suggestion would be very welcome.
> The ImageJ 1.48c daily build adds an Overlay.moveSelection() function you can use to move overlay selections. Here is an example that creates an overlay with three selections, moves the second selection to a new location and then moves it back to its original location.
>
>    requires("1.48c");
>    newImage("Untitled", "8-bit black", 500, 500, 1);
>    makeRectangle(50, 50, 100, 100);
>    run("Add Selection...");
>    makeRectangle(200, 200, 100, 100);
>    run("Add Selection...");
>    makeRectangle(350, 350, 100, 100);
>    run("Add Selection...");
>    run("Select None");
>    wait(1500);
>    Overlay.moveSelection(1, 350, 50);
>    wait(1500);
>    Overlay.moveSelection(1, 200, 200);
>
> -wayne
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

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