I’ve heard that it should be possible to do a lossless rotation on a jpeg image. That means you do the rotation in the frequency domain without an IDCT. I’ve tried to google it but haven’t found anything. Could someone bring some light to this?
What I mean by lossless is that I don’t lose any additional information in the rotation. And of course that’s probably only possible when rotating multiples of 90 degrees.
You do not need to IDCT an image to rotate it losslessly (note that lossless rotation for raster images is only possible for angles that are multiples of 90 degrees).
The following steps achieve a transposition of the image, in the DCT domain:
I’m going to assume you can already do the following:
I can’t show you the full code, because it’s quite involved, but here’s the bit where I IDCT the image (note the IDCT is for display purposes only):
This is the image that is shown:
Nothing fancy is happening here — this is just the original image.
Now, here’s the code that implements both the transposition steps I mentioned above:
This is the resulting image:
You can see that the image is now transposed. To achieve proper rotation, you need to combine reflection with transposition.
EDIT
Sorry, I forgot that reflection is also not trivial. It also consists of two steps:
Here’s code that performs a vertical reflection after the transposition.
Here’s the image you get:
You will note that this constitutes a rotation by 90 degrees counter-clockwise.