Strange behavior of Image::affineTransform

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
ivan.savu

Strange behavior of Image::affineTransform

Post 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 ?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Strange behavior of Image::affineTransform

Post by magick »

We can reproduce the problem you posted and will have a fix in a few days. Thanks.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Strange behavior of Image::affineTransform

Post 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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Strange behavior of Image::affineTransform

Post 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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply