Hel with perspective distortion.

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
sabater_wb

Hel with perspective distortion.

Post by sabater_wb »

I'm trying to do a distortion in a image, but I didn't understand how to do it, yet.

Image

What I need to do is to move the Blue points to the Red points.

image width: 330
image height: 266
-------------------
Points coordinates:

A blue: 0,0
B Blue: 0,266
C Blue: 330,0
D Blue: 330,266

A red: 75,0
B red: 0,180
C red:330,74
D red:277,266
----------

I know how to do a perspective transformation with imagemagick. What I don't know is witch point is each.

-distort Perspective "0,0,0,0 0,0,0,0 0,0,0,0 0,0,0,0"

Could somebody help me?

---------

I need a result like this:
Image
sabater_wb

Re: Hel with perspective distortion.

Post by sabater_wb »

thanks. I don't need help with this, anymore. I did it after a lot of tries.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Hel with perspective distortion.

Post by anthony »

As a FYI for others....

the points are specified in the order. blueA redA blueB redB blueC redC blueD redC
That is in sets of 4,
so that list them as: from this, to this, from this, to this etc etc etc

so the solution was

Code: Select all

distort Perspective '0,0 75,0   0,266 0,180   330,0  330,74    330,266 277,266'
note numbers can be separated by any number of spaces or one comma and
spaces. Use that to help group your numbers to make changes easier.

You should also be able to read in from a file of from, to columns such as

Code: Select all

0,0         75,0
0,266      0,180
330,0     330,74
330,266  277,266
say called "points.txt" (it could be generated from a spread sheet if you want).
and then used like this

Code: Select all

convert photorqj.jpg -virtual-pixel white -distort perspective '@points' result.jpg
It worked perfectly for me.

You can also use more than four control points, but the perspective will be a least squared error fit to all the given data points. that is useful for people attempting to join together multiple panorama images using some automatic tools.

Also the points do NOT need to be integers, but can be floating point values.

And finally while the above used the image corners (image edge) for adjustments, sometimes you want to match up a 'pixel location' rather than an edge. Just remember that pixel positions need to be specified with a 0.5 offset (center of the pixel) rather than just the pixel number. that is 0,0 is the top left corner, but 0.5,0.5 is the top left pixel.

I need to update this information and add the above example in IM Examples.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply