Page 1 of 1

shifting on the right and destination image format

Posted: 2008-01-09T14:34:55-07:00
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.

Re: shifting right (Affine and Distort Transforms)

Posted: 2008-01-09T19:25:01-07:00
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.