Distort Quadrilateral to Quadrilateral

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
josephs
Posts: 40
Joined: 2014-04-08T10:13:43-07:00
Authentication code: 6789

Distort Quadrilateral to Quadrilateral

Post by josephs »

Hi Everyone.

Really stuck here. I am attempting to distort a non-orthogonal quadrilateral to another non-orthogonal quadrilateral. The closest I cam come to achieve this is by using the 'BilinearReverse'...but the output is for orthogonally aligned rectangle so result is not desired. Is ImageMagick able to distort any quadrilateral to any quadrilateral, maintain straight edges. If yes, please lead me in right direction :)

Thanks in advance for any help!
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Distort Quadrilateral to Quadrilateral

Post by snibgo »

"-distort perspective" is probably what you want. See http://www.imagemagick.org/script/comma ... hp#distort
snibgo's IM pages: im.snibgo.com
josephs
Posts: 40
Joined: 2014-04-08T10:13:43-07:00
Authentication code: 6789

Re: Distort Quadrilateral to Quadrilateral

Post by josephs »

I have tried distort perspective with unfavorable results. I think its because perspective assumes a rectangular shape as input...I am trying to distort a quadrilateral with vertices anywhere.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Distort Quadrilateral to Quadrilateral

Post by snibgo »

If you put a sample image somewhere like dropbox.com and paste the URL here, someone might take a look.
snibgo's IM pages: im.snibgo.com
josephs
Posts: 40
Joined: 2014-04-08T10:13:43-07:00
Authentication code: 6789

Re: Distort Quadrilateral to Quadrilateral

Post by josephs »

After further research i was able to confirm it is not possible to achieve what I am asking. As noted on in IM documentation: "There are future plans to produce a true Bilinear distortion that will attempt to map any quadrilateral to any other quadrilateral, while preserving edges (and edge distance ratios)."

So for now not possible but its all good because I was able to use existing tools with some creativity to achieve the affect I was looking for (more-or-less anyway).
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Distort Quadrilateral to Quadrilateral

Post by fmw42 »

You should be able to do it with a combination of -distort BilinearRevers and -distort BilinearForward, but you will need to pick control points manually for each of the two operations. The result of the first operation should be a rectangle.
josephs
Posts: 40
Joined: 2014-04-08T10:13:43-07:00
Authentication code: 6789

Re: Distort Quadrilateral to Quadrilateral

Post by josephs »

Great solution! Seems so simple can't believe I missed it! Thank you.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Distort Quadrilateral to Quadrilateral

Post by anthony »

The "True Bilinear" distortion was in reference to doing both halfs of the Bilinear distortion operations simultaneously.

The next stage... Grid Distortion, would require some major re-arrangement of the distortion code, so that multiple distortions can be applied to an image based on which area of the destination image is being worked on. That I am not going to do.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply