Interactive image rotation in macro

I am trying to rotate images in a somewhat interactive way (I don’t have a predictable regular rotation angle for all my images). I thought this would be straightforward, running a loop until user is satisfied with rotation. But the run("Undo") command doesn’t work, it doesn’t even work manually to undo the rotation of an image. How can I revert the rotation if user didn’t like it? Moreover, is there any way to lively preview the rotation? This would prevent multiple rounds of rotating back and forth.

I welcome any other approach to solve this.

// Rotate image

run("To Bounding Box");
run("Rotate... ");

satisfied_with_rotation = false;

while(satisfied_with_rotation == false){

satisfied_with_rotation = getBoolean("Are you satisfied with the rotation?");	

 if(satisfied_with_rotation == true){
 } else {
	run("Undo"); //>> undo doesn't work

Hi Matias,
The Image>Transform>Rotate command works with undo as long as you don’t select ‘Enlarge Image to Fit’. Here is a macro example:

  run("Blobs (25K)");
  run("Rotate... ", "angle=15 grid=1 interpolation=Bilinear");

The dialog has preview, so if you don’t specify any arguments the user will get the dialog box. As far as I know, there is currently no way to switch on the preview checkbox automatically; this has to be done by the user.

run("Blobs (25K)");
run("Rotate... ");

Could this be an OS issue? I obtain the correct functioning in Ubuntu but not in Windows 10.

Well, I’m also using Ubuntu, but I don’t see why the OS should play a role. Unless you have a really old version, I don’t think that the ImageJ version could make a difference (the relevant code has not changed for more than two years).
Could you check Edit>Options>Memory&Threads? If you don’t have “Keep multiple undo buffers”, undo will be impossible as soon as you click on another window.

I have it checked now…However “Undo” doesn’t work well on my end (on Windows). For example, it works for to undo a deletion, but not the rotation.

Also, although ubuntu manual transform>Rotate shows preview with 8-bit RGB tiffs, run("Rotate... ") does not with composite tiffs. Same for “Undo”…So maybe it has to do with that?

The latest ImageJ daily build (1.52i39) fixes a bug that caused Undo to fail to work after a rotation with “Enlarge image to fit result” enabled.

1 Like

I’m sorry but I do not have “Enlarge Image to fit result” enabled, how is this related ?

The Rotate command in the latest ImageJ daily build (1.52i42) supports live interactive rotation, but not for composite color images. The daily build also fixes a bug that caused Undo of manually rotated composite color images to not work. The type of Undo used for composite color images (TRANSFORM) is normally disabled in macros to reduce memory consumption and increase speed but it can be enabled using setOption(“SupportMacroUndo”,true). Here is an example:

  run("Fluorescent Cells (400K)");
  run("Rotate... ", "angle=75");
1 Like


I had a query regarding a similar issue. My macro asks the user to do the rotation using the rotation tool. This allows the user to run the preview option as they figure out the best possible rotation angle. Is it possible to extract the value of rotation angle once the user has chosen a value? At the moment I ask the user to manually enter the data after rotation (to save the parameter in a log file once the macro is over). Below is the macro code -

> waitForUser("Action required", "You will be asked to Rotate.\n\nIf you don't wish/need to rotate, press cancel in the next dialog box.\n\nRemember to press OK for rotation of entire stack!!\n\nIMP! Please remember the angle that you choose. In the next box you will be asked to enter the data for saving in final log.\n\n[Esc to abort]");
> run("Rotate... ");
> //to save rotation data
> Dialog.create("Rotation Angle");
> rotationdegree="ENTER ANGLE HERE";
> Dialog.addString("Please enter the value of rotation that was entered (in degrees). \n This is to help the user save this information", rotationdegree);
> rotationdegree=Dialog.getString();

You can extract the current rotation angle in the latest ImageJ daily build (1.52p33) using getValue("rotation.angle")

1 Like

Thank you @Wayne. Is there a tutorial for these functions? Especially for the call() function?

All built in macro functions, including call() and getValue(“rotation.angle”) are described at

Thank you @Wayne. I’ll bookmark this link then, it is not available on the link I was previously using (

Thanks for pointing this out. I think it is not intended for these two pages to get out of sync.

As far as I know, is a mirror of (@ctrueden correct me if I’m wrong), and the former was more reliably accessible in the past.

In general, the ImageJ developers recommend using the domain, as it is bundling all resources about ImageJ, including the ImageJ 1.x documentation, the ImageJ wiki, and most update sites.

@Wayne, any reason why and differ here?

The NIH has made it difficult for me to update files on the ImageJ website so I only update in conjunction with new ImageJ releases. Go to for the latest updates, for example to see a description of the new getValue(“rotation.angle”) function.

1 Like

@Wayne Would it make sense to change the relevant sections of to preferentially reflect instead of

1 Like

I would mirror since it has the latest updates.