shifting on the right and destination image format

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
zomp

shifting on the right and destination image format

Post by zomp »

Why the following command

Code: Select all

convert -affine 1,0,0,1,20,0 -transform source.png dest.png
fails to shift on the right while the following command

Code: Select all

convert -affine 1,0,0,1,20,0 -transform source.png dest.gif
does it right?
Why does the success depend on the destination file format?

Thanks for your wonderful program.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: shifting right (Affine and Distort Transforms)

Post by anthony »

The -affine command is totally virtual canvas based!!

If you just translate an image by a integer amount, the image will be translated (and with all the processing that that involves), however the result is just the original image with a new virtual canvas offset adjusted appropriately by the amount of translation.
That is the actual image is unchanged, just with a different offset, which is exactly what you requested!!!

For more information see...
http://imagemagick.org/Usage/distorts/a ... fine_trans

If you like to see that offset, -flatten the image to 'fill out' the virtual canvas. This is also demonstrated in the IM Example pages on affine (see link above)

Note that -affine is a old operator in the IM core library, that is actually part of the -draw operator of IM. It only uses image interpolation for pixel color lookup.
http://imagemagick.org/Usage/misc/#interpolate
As such when scaling by more than 50% you can get lots of resizing artifacts (equivalent to the -scale resize operator for undistorted resizes). See IM examples Resize for more info on this.
http://imagemagick.org/Usage/resize/#artifacts

The new operator which may eventually replace -affine is -distort
with its SRT, Affine and AffineProjection methods. See...
http://imagemagick.org/Usage/distorts/#SRT
This allows you to specify the transform in terms of individual transformation styles, control point movements, or an affine matrix, respectively.

Also this operator does NOT do unscaled pixel interpolated lookup, but does a scaled cylindrical filtered lookup of colors from the source image. What is that... That means that you get a good result even when the image gets minimized by more that 50%! For examples of this see IM Exmaples, distort, Viewing Distant Horizons
http://imagemagick.org/Usage/distorts/#horizon
As such the new distort method is the recommended method fo affine distortion.

NOTE the final image size of -distort is the same as the original image, however if you use +distort instead you will get the automatic output image size (on a virtual canvas) adjustment that you saw in -affine. It also has some special 'expert' control settings that lets you define a specific 'viewport' into the distorted space, allowing you to adjust resulting image, as you like.

Please read IM Examples, and if you have any further questions, please ask. I'll be happy to explain, and/or update the examples pages according to user feedback.

PS: I am planing to go back into the distort color lookup filter handling soon, to try and speedup and improve the results of -distort in the near future. When that is done I plan to expand the distortions available further. Comments and suggestions welcome.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply