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.
Now with rotation (using manual graphics tools) - rotated to -50degs (this is what is needed)
Now with imagemagick code - rotated by only 5degs (otherwise it goes outside canvas)
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.
-
Correct Rotation Issue
Correct Rotation Issue
Last edited by Rah1 on 2011-01-06T00:49:23-07:00, edited 1 time in total.
Re: Correct Rotation Issue
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}
=
For example:
convert -page +0+0 {background_image} -draw "rotate 90 image over {x1},{y1} {width},{height} '{horse_image}' " \
-flatten {saveas_image}
=
Last edited by Rah1 on 2011-01-06T00:50:01-07:00, edited 1 time in total.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Currect Rotation Issue
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
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Currect Rotation Issue
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/
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/
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Currect Rotation Issue
Just to finish off this animation was created using -rotate
and this using the Distort SRT
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).
and this using the Distort SRT
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).
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
Re: Correct Rotation Issue
Hi, thanks for the reply,
if possible, can I see the code of your example koala rotation using Distort SRT.
Thanks
if possible, can I see the code of your example koala rotation using Distort SRT.
Thanks
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Correct Rotation Issue
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.
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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/