Page 1 of 1

How to make perspective transform

Posted: 2019-01-24T07:03:45-07:00
by jensen31
Hello folks,

maybe I searched wrong. But I am looking for perspective transform.
Here I have an example: https://imgur.com/RDu346A

Thank you for hints or an code example.

best regards
Jens

Re: How to make perspective transform

Posted: 2019-01-24T07:23:25-07:00
by snibgo
jensen31 wrote:But I am looking for perspective transform.
"-distort perspective" does this. See http://www.imagemagick.org/script/comma ... hp#distort . The option takes the coordinates of four points of the input image, and the coordinates of where those points should be in the output image.

Does that help?

Re: How to make perspective transform

Posted: 2019-01-24T09:42:31-07:00
by jensen31
Yes thats it! Thank you!
I am trying now to get an image (1900x1343) transformed like in my example link. Example 2 (the right one https://imgur.com/RDu346A)
I am confused cause the example on IM page is with a 90x90 pixel graphic. Hard to understand which side is what.

So far:
convert /skripte/imgRender/input/image/Tastatur.jpg -matte -virtual-pixel transparent \
-distort Perspective '0,0,0,0 0,1900,0,1900 900,0,900,200 900,900,900,900' \
/skripte/imgRender/Tastatur2.jpg
My problem is to understand which number is what for. I was on the website but also due to my english I dont understand it.

Could you say what each number means?
Like:
before transform x, before transform y, after transform x, after transform y
and so on... 4 parts with 4 numbers each.

Or let me ask something else. I am doing als this to automate writing a list of words onto a an image with an empty placeholder sign. Sign like on the street. So is this the best way to put text perspectivly transformed on an image?

Would help me alot.
Jens

Re: How to make perspective transform

Posted: 2019-01-24T10:24:54-07:00
by snibgo
I suggest you use "-background Blue -virtual-pixel Background" for testing, so you can see what is happening. When it does what you want, change this to "-virtual-pixel transparent".

Your image is 1900x1343 pixels. So the bottom-left pixel is at (1899,0).


Your coordinates are strange. For clarity, I split them:

Code: Select all

'0,0,0,0
0,1900,0,1900
900,0,900,200
900,900,900,900' 
So top-left won't move. (0,1900) is outside your input image, which has the bottom-right pixel at (1899,1342). I don't think you intend this.

Commonly, we have an input image and want to move the corners of this image to specified coordinates, for example:

Code: Select all

'0,0,0,0
0,1342,0,1300
1899,0,1700,0
1899,1342,1850,1300'
jensen31 wrote:So is this the best way to put text perspectivly transformed on an image?
Yes. Write the text to a new image, and trim it. Find the coordinates of the corners. Find the coordinates on the main image where you want each corner of the text image. That gives the 16 numbers.