Page 1 of 1

Correct Rotation Issue

Posted: 2011-01-05T07:14:29-07:00
by Rah1
Hi,

I have this issue with rotation that I cant solve since few days. Im trying to build an image which has several images (items) over each other. I have successfully done the item insertions with specific size and position of each item.

However, when i try to rotate the items to be placed (with "rotate" or even by "affine"), the items are rotated but displaced. i believe it has something to do with the center of rotation being the top left of the canvas.

Example:
This is the without rotation.
Image

Now with rotation (using manual graphics tools) - rotated to -50degs (this is what is needed)
Image

Now with imagemagick code - rotated by only 5degs (otherwise it goes outside canvas)
Image


As you can see it starts moving away from its location as i start rotating it. I dont have the same image all the time nor the same size so its not possible to apply a "translate" everytime.

-

Re: Correct Rotation Issue

Posted: 2011-01-05T07:19:40-07:00
by Rah1
and before you get confused, the yellow is the background image, the horse is the "item" (a transparent image) placed over it using a single imagemagick code.

For example:
convert -page +0+0 {background_image} -draw "rotate 90 image over {x1},{y1} {width},{height} '{horse_image}' " \
-flatten {saveas_image}

=

Re: Currect Rotation Issue

Posted: 2011-01-05T15:08:21-07:00
by fmw42
use -distort SRT. it has more control over the rotation center and displacement and may produce a better quality. see http://www.imagemagick.org/Usage/distorts/#srt

Re: Currect Rotation Issue

Posted: 2011-01-05T20:35:21-07:00
by anthony
draw rotate is very low-level. Basically it 'warps' the drawing canvas by modifying a affine matrix.
See Warping of the Drawing Surface
http://www.imagemagick.org/Usage/draw/#transform

But by default it rotates around origin (as it should), and what you are seeing is correct behavior. If you want a different point of rotation you need to specify it using a translate option to change the location of the origin around which the image is rotated (or scaled) by the affine transformation.

For more on affine transformations see the examples in...
http://www.imagemagick.org/Usage/distorts/affine/

As for quality of results, draw rotate modifies an affine matrix and uses its own internal affine image distortion routine. It is not nearly as good as the newer -distort functions, whether it is SRT, Affine, or AffineProjection. Basically draw uses a simple interpolated lookup of the source image without making use of the more advanced (and slower) -distort Elliptical Weighted Average which uses cylindrical filters for its process.

For more detail and understanding of these terms and how distortions work see the introduction sections of http://www.imagemagick.org/Usage/distorts/

Re: Currect Rotation Issue

Posted: 2011-01-05T20:49:55-07:00
by anthony
Just to finish off this animation was created using -rotate
Image
and this using the Distort SRT
Image

Note that -rotate uses a different method of rotation to BOTH draw and distort, a method involving using 3 separate shears, and some 90 degree rotations. the result is as you can see not very accurate, and causes 'jitters' in the center of rotation.

The Distort method however directly distorts the source image using mathematical formula and as such has no jitter. The advanced EWA re-sampling produces much sharper and clearer distortions (with the latest IM v6.6.5 onward).

Re: Correct Rotation Issue

Posted: 2011-01-07T07:50:07-07:00
by Rah1
Hi, thanks for the reply,
if possible, can I see the code of your example koala rotation using Distort SRT.
Thanks

Re: Correct Rotation Issue

Posted: 2011-01-09T21:23:12-07:00
by anthony
It is from IM Examples, Warping, Animations
http://www.imagemagick.org/Usage/warping/#animations
Links to script used to generate each animation is given.

Specifically (in the respective order)
http://www.imagemagick.org/Usage//warpi ... ate_rotate
http://www.imagemagick.org/Usage/warpin ... istort_rot

The scripts actually programmically generates the IM command to use!
That is it is a self-programming shell script.

The alternative is to generate a pipeline of images and collect them together.

Also note that each rotated image is always generated from the original source (first) image, so as to prevent image degrading due to iterative processing. Parenthesis is used to generate each image almost like it is a completely separate image processing command.