Page 2 of 2

Re: Distortion

Posted: 2016-10-11T11:05:33-07:00
by alireza
Great. what does distort:viewport=800x800-300-300 and -trim and +repeat do?!
Thanks.

Re: Distortion

Posted: 2016-10-11T11:07:54-07:00
by snibgo

Re: Distortion

Posted: 2016-10-11T11:09:13-07:00
by alireza
my image size is 3264 x 2448 what values should I use for distort:viewport?
Thanks.

Re: Distortion

Posted: 2016-10-11T11:20:34-07:00
by snibgo
I don't know.

Re: Distortion

Posted: 2016-10-11T11:26:38-07:00
by alireza
so that only works with square images. Right?

Re: Distortion

Posted: 2016-10-11T11:28:08-07:00
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.

Re: Distortion

Posted: 2016-10-11T11:30:19-07:00
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

Re: Distortion

Posted: 2016-10-11T11:43:41-07:00
by alireza
IT WORKED. THANK YOU FMW42 AND SNIBGO.

Re: Distortion

Posted: 2016-10-11T11:49:42-07:00
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..

Re: Distortion

Posted: 2016-10-11T11:52:18-07:00
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.

Re: Distortion

Posted: 2016-10-11T11:55:26-07:00
by fmw42
See http://www.imagemagick.org/Usage/distorts/#mapping for the concept of reverse mapping.

Re: Distortion

Posted: 2017-05-09T22:02:47-07:00
by bazza
Hello.
I wish to calculate the barrel Distortion of a camara c920

https://therandomlab.blogspot.com.ar/20 ... -view.html

Re: Distortion

Posted: 2017-05-09T22:33:14-07:00
by snibgo
IM contains no tools to automatically calculate barrel distortion of a lens.

The Hugin toolset does.