How to make perspective transform

Discuss digital image processing techniques and algorithms. We encourage its application to ImageMagick but you can discuss any software solutions here.
Post Reply
jensen31
Posts: 8
Joined: 2016-01-01T16:15:43-07:00
Authentication code: 1151

How to make perspective transform

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to make perspective transform

Post 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?
snibgo's IM pages: im.snibgo.com
jensen31
Posts: 8
Joined: 2016-01-01T16:15:43-07:00
Authentication code: 1151

Re: How to make perspective transform

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to make perspective transform

Post 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.
snibgo's IM pages: im.snibgo.com
Post Reply