Page 1 of 1

perspective projection corrdinates

Posted: 2012-09-09T01:04:23-07:00
by pospiech
I want to do perspective projections, but I completely fails to understand the coordinates used.

This code does nothing

Code: Select all

convert input.jpg  -matte -virtual-pixel transparent -distort Perspective "0,0,0,0  0,90,0,90  90,0,90,0 90,90,90,90" output.png
This shrinks the image on the right side

Code: Select all

convert input.jpg  -matte -virtual-pixel transparent -distort Perspective "0,0,0,0  0,90,0,90  90,0,90,5 90,90,90,90" output.png
But what is necessary to shrink the image on the left side ?

Re: perspective projection corrdinates

Posted: 2012-09-09T02:39:50-07:00
by Bonzo
The co-ordinate system changed at some point so the version can have an effect.

In your case the blocks of numbers are the original co-ordinates in x y and the new co-ordinates in x y.

so 0,0,0,10 will move the top left corner which is 0,0 to the point 0,10 X stays the same and Y moves down 10px

You can see some examples using php on my website: Distort and more details on Anthony's example site

Re: perspective projection corrdinates

Posted: 2012-09-09T02:51:03-07:00
by pospiech
Bonzo wrote:The co-ordinate system changed at some point so the version can have an effect.

In your case the blocks of numbers are the original co-ordinates in x y and the new co-ordinates in x y.
Coordinates in pixels ? That would be a big problem. I want to let it run in a loop where all images have different pixel sizes.
Bonzo wrote: so 0,0,0,10 will move the top left corner which is 0,0 to the point 0,10 X stays the same and Y moves down 10px
And what does the third '90,0,90,5' mean then? it performs a perspective transformation and does not move the image.
Aditionally I do not understand the meaning of 90, 0 if my image has the size 200x200.
Bonzo wrote: You can see some examples using php on my website: Distort and more details on Anthony's example site
Unfortunaltely all I have seen are fancy examples, but I need very basic examples that allow me to understand how to change the number to achive the image I want.

Re: perspective projection corrdinates

Posted: 2012-09-09T04:48:59-07:00
by pospiech
I found it out by simply trying the effect of each number.

These numbers are organised as original position to target position x1y1 -> x2y2
with the coordinates: left-top, left-bottom, right-top, right-bottom,
where each number is in coordinates of pixels (unfortunately).

So what I need is:

Code: Select all

convert input.jpg  -matte -virtual-pixel transparent -distort Perspective "0,0,0,20  0,200,0,180  200,0,200,0 200,200,200,200" output.png 

Re: perspective projection corrdinates

Posted: 2012-09-09T13:03:26-07:00
by fmw42
It works just a well without the middle comma.

convert input.jpg -matte -virtual-pixel transparent -distort Perspective "0,0 0,20 0,200 0,180 200,0 200,0 200,200 200,200" output.png

The order of corners does not matter.

Re: perspective projection corrdinates

Posted: 2012-09-09T19:20:26-07:00
by anthony
pospiech wrote:I found it out by simply trying the effect of each number.

These numbers are organised as original position to target position x1y1 -> x2y2
with the coordinates: left-top, left-bottom, right-top, right-bottom,
where each number is in coordinates of pixels (unfortunately).

So what I need is:

Code: Select all

convert input.jpg  -matte -virtual-pixel transparent -distort Perspective "0,0,0,20  0,200,0,180  200,0,200,0 200,200,200,200" output.png 
That is correct. Each set of four numbers is the movement of ONE control point, with the first two numbers becoming the second two numbers.

I do explain this in IM Examples, in the section, Distortions Using Control Points
http://www.imagemagick.org/Usage/distor ... rol_points
It is also explained in the option reference... (at the end of the list of distort methods)
http://www.imagemagick.org/script/comma ... p?#distort

This explaination is in 'Affine Distortions' (2 or 3 point) in the section BEFORE the more complex 'perspective distortions'.

Re: perspective projection corrdinates

Posted: 2012-09-09T23:57:04-07:00
by whugemann
Coordinates in pixels ? That would be a big problem. I want to let it run in a loop where all images have different pixel sizes.
In fact, it's not a problem. If you are working with a bunch of images, you will probably have to use a script anyway. This script could also perform any co-ordinate transformation you need. Please note that IM accepts fractional coordinates, such that you don't have to introduce rounding errors. At http://www.imagemagick.org/Usage/windows/#vb_text you find a VBScript that transforms WinMorph's fractional co-ordinates (0 to 1) into the co-ordinates used by IM.

Re: perspective projection corrdinates

Posted: 2012-09-10T18:46:21-07:00
by anthony
Also not the coordinates are 'image coordinates' not 'pixel coordinates'. That means 0,0 referred to the exact edge of the top-left corner of the IMAGE. It is not the center of the PIXEL in the top-corner.

See Image Coordinates vs Pixel Coordinates
http://www.imagemagick.org/Usage/distor ... oordinates

Basically that means if you want to line up a pixel, you need to specify the center of the pixel, which is the pixel coordinates + 0.5.

Often it does not matter much, but if not right the distorted image may have be incorrectly positioned by a sub-pixel distance translation.

Finally image offsets (layer images) are not handled by 'composite' which is a much lower level operator. Images should be 'layered' using -layer merge, -flatten, -mosaic (the later are short aliases for -layer flatten and -layer mosaic).