Page 1 of 1

PerlMagick, Distort: One pixel off error

Posted: 2009-05-28T13:11:47-07:00
by Searle
If I understand correctly, the following should be a NOP:

Code: Select all

    $image->Distort( "method" => "Perspective",
        "points" => [ 0,0 => 0,0,  100, 0 => 100,0,  0,100 => 0,100,  100,100 => 100,100 ],
        "best-fit" => 1,
    );
But it's not, the image is displaced by [1,1], no matter what "points" is.
At least for me and my IM 6.5.1.0

Cheers,
Searle

Re: PerlMagick, Distort: One pixel off error

Posted: 2009-05-28T13:26:44-07:00
by fmw42
I believe that has been fixed in later releases. Don't recall exactly when, but Anthony can provide that as I don't see it explicitly mentioned in the changelog file at http://www.imagemagick.org/script/changelog.php, but I could be missing it.

Seems to work fine for me in IM 6.5.2-9 Q16

Image

convert zelda3.png -distort perspective "0,0 0,0 128,0 128,0 128,128 128,128 0,128 0,128" zelda3_noop.png

Image

Re: PerlMagick, Distort: One pixel off error

Posted: 2009-05-28T22:23:19-07:00
by anthony
Searle wrote:If I understand correctly, the following should be a NOP:

Code: Select all

    $image->Distort( "method" => "Perspective",
        "points" => [ 0,0 => 0,0,  100, 0 => 100,0,  0,100 => 0,100,  100,100 => 100,100 ],
        "best-fit" => 1,
    );
But it's not, the image is displaced by [1,1], no matter what "points" is.
At least for me and my IM 6.5.1.0
With bestfit it will be displaced by 1 pixel, but it will also be enlarged by 2 pixels and and a -1,-1 canvas offset.

In other words as a 'layer image' the image is still exactly the same!!!

the extra pixels are added to ensure that any interpolation and re-sampling effects that may come about from the distortion (a no-op is the only time this does not occur) that those effects are also correctly captured.

It is correct!
fmw42 wrote: Seems to work fine for me in IM 6.5.2-9 Q16
You didn't turn on 'best-fit' or 'layered image' flag using +distort, so you did not see it.

Re: PerlMagick, Distort: One pixel off error

Posted: 2009-05-30T02:10:40-07:00
by Searle
Ok, thanks! I understood the extra pixel, and if placing the image at [-1,-1] works by definition,
thats fine for me.

But just for curiosity: how do I switch off layered-image in PerlMagick?

Cheers,
Searle

Re: PerlMagick, Distort: One pixel off error

Posted: 2009-05-31T20:33:20-07:00
by anthony
Searle wrote:Ok, thanks! I understood the extra pixel, and if placing the image at [-1,-1] works by definition,
thats fine for me.

But just for curiosity: how do I switch off layered-image in PerlMagick?

Cheers,
Searle
Depend on what you are doing with the image, and why you are distorting it.

If you remove the 'best-fit' flag *set to '0' then IM does not enlarge the image to try to capture the whole distortion, but uses the input image as a 'viewport' for the output. In otherwords it will 'clip' the distorted image by the size (and location) of the input image.

If flattening the image onto another (compose using the virtual offset values) see
http://www.imagemagick.org/Usage/layers/#flatten
then no change is needed, as it will be shifted by the -1,-1 offset the distort set. If this offset is not whated you would use repage to reset all virtual offsets and sizes to zero.

NOTE SRT also allows you to specify the coordinates around which the image is to be rotated and scaled, and even lets you specify where to 'move' that coordinate for the output image.
NOTE that coordinates are image coordinates, not pixel positions, as such 0,0 is the top-left edge/corner of image, and 0.5,0.5 is the middle of the top-level pixel. You can even move images by half a pixel, and see the half-pixel movement when you compare the input to the output! Yes it is that exact!