Posted by
Rasband, Wayne (NIH/NIMH) [E] on
Aug 29, 2013; 12:00am
URL: http://imagej.273.s1.nabble.com/Macro-commands-to-move-overlay-tp5004590p5004602.html
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