Page 1 of 1

Strange behavior of Image::affineTransform

Posted: 2009-01-30T03:48:27-07:00
by ivan.savu
I think there's a bug in a Image::affineTransform. When I call it with identity matrix I end up with image that is 1 pixel wider and 1 pixel higher then the original. If I apply transformation multiple times, the image gets wider and higher by number of times I applied transformation. Here's a sample code that illustrates my problem:

Code: Select all

Image image("C:/Documents and Settings/All Users/Documents/My Pictures/Sample Pictures/Winter.jpg");
MagickCore::SetImageVirtualPixelMethod(image.image(), MagickCore::ConstantVirtualPixelMethod);
DrawableAffine affine(1.0,  1.0, 0, 0, 0.0, 0.0);
image.affineTransform(affine);
image.write("test.jpg");


The resulting image is 1 pixel wider, and 1 pixel higher then the original. Also the image itself is translated by one pixel to the right, and one pixel down.
Is this a bug ? Or am I doing something wrong ?

Re: Strange behavior of Image::affineTransform

Posted: 2009-01-30T07:41:17-07:00
by magick
We can reproduce the problem you posted and will have a fix in a few days. Thanks.

Re: Strange behavior of Image::affineTransform

Posted: 2009-02-25T16:50:05-07:00
by anthony
Yes I know of the bug and am working on it, when I can get time from my paying job.

However when fixed it will be 2 pixels wider and higher!!!!!! Not one!!!!

Distort is not a orthogonal resize but also includes filtering beyond the edges of image proper. Virtual Pixels are important!!!!

When fixed this part will be demonstrated properly by the IM example, where distort is used for orthogonal image resizing...
http://www.imagemagick.org/Usage/resize/#distort

At the moment that example is being clipped along the right and bottom edges making them appear 'sharp' when in reality they aren't. That is because the size is 1 pixel two short!

It will be fixed soon.

Re: Strange behavior of Image::affineTransform

Posted: 2009-03-09T21:11:38-07:00
by anthony
The over clipping of 'bestfit' +distort and thus -affine/-transform has now been committed. It will appear in the next release of IM v6.5.0-0

As mentioned images from affine are 'layer' images with an appropriate layers offset and typically an additional pixel added per side (totaling 2 pixels larger) than you may expect. You can either shave, crop, or layer the image appropriately.

Remember it is a layer image do it is aligned correctly on the virtual canvas as appropriate for the affine transform applied, so should be treated accordingly.