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?".
alireza
Posts: 14
Joined: 2016-10-07T09:14:21-07:00
Authentication code: 1151

Re: Distortion

Post by alireza »

Great. what does distort:viewport=800x800-300-300 and -trim and +repeat do?!
Thanks.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Distortion

Post by snibgo »

snibgo's IM pages: im.snibgo.com
alireza
Posts: 14
Joined: 2016-10-07T09:14:21-07:00
Authentication code: 1151

Re: Distortion

Post by alireza »

my image size is 3264 x 2448 what values should I use for distort:viewport?
Thanks.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Distortion

Post by snibgo »

I don't know.
snibgo's IM pages: im.snibgo.com
alireza
Posts: 14
Joined: 2016-10-07T09:14:21-07:00
Authentication code: 1151

Re: Distortion

Post by alireza »

so that only works with square images. Right?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Distortion

Post by fmw42 »

Snibgo's example shows that the distortion has poles (zeros) and goes out of bounds. This is typical of a polynomial expression with negative values. I suspect the distortion works best when the image is kept small enough to avoid going beyond the first pole (zero). That is probably why the image size is typically left unchanged. There is probably no (easy) way to predict where your input bounds would be in the output space. All you can probably do easily is trial and error changing the viewport size until you get what you want.

The viewport dimensions tell you how big to make the output and what offset you need to expand the area. If your input is say 600x600 and you want an output centered that is 800x800, you need a negative Xoffset and Yoffset of half the difference. So 800x800-100-100.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Distortion

Post by fmw42 »

Images do not have to be square for distort barrel. And you can provide separate arguments for x and for y. See the arguments at http://www.imagemagick.org/Usage/distorts/#barrel
alireza
Posts: 14
Joined: 2016-10-07T09:14:21-07:00
Authentication code: 1151

Re: Distortion

Post by alireza »

IT WORKED. THANK YOU FMW42 AND SNIBGO.
Last edited by alireza on 2016-10-12T08:28:04-07:00, edited 1 time in total.
alireza
Posts: 14
Joined: 2016-10-07T09:14:21-07:00
Authentication code: 1151

Re: Distortion

Post by alireza »

So I guess the way it works is:
my original image is 3264x2448.
by -define distort:viewport=3464x2648-100-100 we define a virtual background that has a border 100 pixel around my original image then we apply distort barrel "0.0301 -.0733 0" and this will only apply to the original image not the one with extended border and then -trim will trim the virtual background to the pixels of undistorted image and +repage dont know wxavctly what it does but it's working,,
I overlayed my undistorted image using this method to the undistorted image (created without using -define distort:viewport:...) and they match.
awesome..
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Distortion

Post by fmw42 »

Actually it is filling the expanded output via the viewport with pixels from the input. Most IM transformations are reverse. They sequence through the output and find a corresponding location in the input from the transformation and then put that pixel color from the input at the location in the output.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Distortion

Post by fmw42 »

See http://www.imagemagick.org/Usage/distorts/#mapping for the concept of reverse mapping.
User avatar
bazza
Posts: 20
Joined: 2016-06-15T18:06:36-07:00
Authentication code: 1151
Location: Argntina

Re: Distortion

Post by bazza »

Hello.
I wish to calculate the barrel Distortion of a camara c920

https://therandomlab.blogspot.com.ar/20 ... -view.html
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Distortion

Post by snibgo »

IM contains no tools to automatically calculate barrel distortion of a lens.

The Hugin toolset does.
snibgo's IM pages: im.snibgo.com
Post Reply