Different expectations when rotating an image

Hello,

when rotating an image with non zero origin, the result is different from my expectation.

  1. There is a bug for non quadratic images.
  2. A case differentiation for images with non zero origin could be useful.

Example

initial conditions:

  • the image is not quadratic (in my case 2048x2412)
  • the x-origin is -2740
  • the y-origin is 1206
  • width and hight of the pixels are positive

result after rotating 90° right:

  • the new size is 2415x2048
  • the x-origin is 841
  • the y-origin is -2740
  • width and hight of the pixels are positive

expectation when rotating 90° right:

  • the new size is 2415x2048 :+1:
  • the x-origin is 1206 :-1:
  • the y-origin is -2740 :+1:
  • the pixel width is negative :-1:
  • the pixel height is positive :+1:

For rotating 90° left I get wrong results, too.

Proposal

The wrong value for x-origin is a bug. The lines (right/left)
double xOrigin = imp.getWidth()-1 - cal.yOrigin;
double yOrigin = imp.getHeight()-1 - cal.xOrigin;

have to be corrected to
double xOrigin = imp.getHeight()-1 - cal.yOrigin;
double yOrigin = imp.getWidth()-1 - cal.xOrigin;

because imp is the image before rotating.

I think negative pixel sizes are only desired in special cases, like mine. Maybe one should consider to use negative values when the origin is not zero and keep positive values when the origin is zero.
What is your opinion about using negative pixel sizes?

This proposed bug fix is in the latest ImageJ daily build (1.50d14).

1 Like

For those curious, the diff can be viewed here.

Thanks for quickly fixing this bug.

What is your opinion on using a negative pixel size when rotating images with non zero origin.

In my case, I rotate an Image to speed up processing (row by row instead of column by column). Because the direction changes, my Script/Macro/Plugin has to multiply each calibrated y-coordinate (x-coordinate before rotating) with -1.

I don’t know if this is the general case. But for all my data, where the origin is not zero, the direction is important.