Page 1 of 2
Distortion
Posted: 2016-10-07T09:17:54-07:00
by alireza
So I am using this command to convert.exe" c:\kodak-cma.JPG -distort barrel "0.0301 -.0733 0" d:\corrected.jpg to create undistorted image.
and it works fine. except I don't want the cropping as it tries to keep the image resolution the same. Is there anyway to avoid that?
Thanks
Re: Distortion
Posted: 2016-10-07T09:36:31-07:00
by snibgo
What cropping? The output should be the same size as the input, with no cropping.
Perhaps you mean you want to scale the result down, so the output image is contained with the same dimensions. If so, then supply a fourth number, eg 1.1.
Re: Distortion
Posted: 2016-10-07T11:31:44-07:00
by alireza
so we know that d=1-(a+b+c) will normalize based on smaller side of the image if I use 1.1 for d it will affect the distortion. Isn't that true?
I just want not to loose any data from my original image after removing distortion. your method works but it's affecting the solution.
in another word if I use d=1 and d=1.1 and overlay the result in photoshop and scale the images they should match but they are not.
Re: Distortion
Posted: 2016-10-07T12:27:49-07:00
by snibgo
alireza wrote:so we know that d=1-(a+b+c) will normalize based on smaller side of the image
Yes. More precisely, when d=1-(a+b+c) pixels at a radius from the centre r=1 won't move.
Changing any one of the four parameters a, b, c or d will change the function. For a pure scale, you can multiply all four parameters by the same factor.
Re: Distortion
Posted: 2016-10-07T13:16:03-07:00
by alireza
I appreciate it. You have been very helpful Sir.
Thank you.
Re: Distortion
Posted: 2016-10-10T10:53:04-07:00
by alireza
one more thing.let's forget about scaling.
I have values for a kodak camera as a=0.0301 b=0.0733 c=0 and d=1-(a+b+c)
I ran the distorted image thru ptlens and convert.exe (imagemagik) and I am getting the same exact undistorted image result and as I expected the corner of image are pulling outward after removing distortion.
Now I tried to create a grid in excel and show this visually in excel
so I am using r'=a.r^4+b.r^3+c.r^2+(1-a-b-c).r
but instead of the corner image moving outward it's actually moving inward and when I change the sign of a,b,c seems like I am getting the correct result.
Can you think of a reason for that?
Re: Distortion
Posted: 2016-10-10T11:37:48-07:00
by snibgo
With those parameters in IM's convert, I would expect the middle of long side to remain in the same position, and the corners to move inwards.
The formula you show is correct, where r is the destination radius and r' is the source radius. Pixels that start at a given source radius will be distorted (moved) to the destination radius.
For example, my "toes" image is 267x233 pixels, so the diagonal is approx 354.37 and the ratio diagonal/short_dim is 1.52. The radius at the corners is 1.52.
When the destination radius is 1.52, the formula tells us the source radius (where the pixel comes from).
0.0301*1.52^4 + 0.0733*1.52^3 + (1-0.0301-0.0733)*1.52 = 1.7809
So the source for each corner is further out than the corner. The corners will move inwards. IM will use virtual pixels for the new corners.
Code: Select all
%IM%convert toes.png -virtual-pixel Black -distort barrel 0.0301,0.0733,0 toes_barrel.jpg
If you are getting the opposite result, please show your command, and the input and output images.
Re: Distortion
Posted: 2016-10-10T11:56:15-07:00
by fmw42
except I don't want the cropping as it tries to keep the image resolution the same. Is there anyway to avoid that?
Use +distort rather than -distort.
see
http://www.imagemagick.org/Usage/distor ... rt_bestfit
http://www.imagemagick.org/Usage/distor ... t_viewport
Re: Distortion
Posted: 2016-10-10T12:32:44-07:00
by alireza
OH. Thanks again I didn't realize r' is source and r is the destination I was using it backward.
Interesting that when I changed the signs of a,b,c I got a visually correct result.
I have to try to solve for r in excel and re-plot.
Thanks again you have been very helpful.
r'=a.r^4+b.r^3+c.r^2+(1-a-b-c).r
Posted: 2016-10-10T12:52:00-07:00
by alireza
Can excel solve the polynomial degree 4 equations?!
Re: Distortion
Posted: 2016-10-11T09:43:24-07:00
by alireza
snibgo wrote:For a pure scale, you can multiply all four parameters by the same factor.
Is this really right?
let's say a=0.0301 b=-0.0733 and c=0 therefore d=1-(a+b+c)=1.0432
so I multiplied everything by 1.1
a=0.03311
b=-0.08063
c=0
d=1.14752
for a uniform scale I used this command:
convert source -distort barrel "0.03311 -0.08063 0 1.14752"
and overlayed this image with the image I got from convert source -distort barrel "0.0301 -0.0733 0" and scaled to see if they match and they are not matching.
How can Use +distort command?
any other method that after distortion removal process I still have all my pixels from original photo (no cropping).
Thanks,
Re: Distortion
Posted: 2016-10-11T09:50:11-07:00
by alireza
when I use +distort barrel, there's still cropping. Is there any additional switches I should use to keep all the pixels in my original image without cropping?
Thanks.
Re: Distortion
Posted: 2016-10-11T10:10:05-07:00
by snibgo
No, it's an over-simplification to simply multiply ABCD by the same number.
As far as I know, "+distort" doesn't work with barrel. I suspect the reason is that the maths is very complex. I don't know the maths to do what is wanted.
But it can be done, with viewports. For example:
Code: Select all
%IM%convert toes.png -virtual-pixel Black -define distort:viewport=750x750-250-250 -distort barrel -0.0301,-0.0733,0 -quality 40 toes_debarrel2.jpg
(Note that the output has the input more than once.)
Re: Distortion
Posted: 2016-10-11T10:46:03-07:00
by alireza
a=0.0301 (positive not negative)
b=-0.0733 (negative)
c=0
can you apply these parameters to your toes.png and get an output without loosing pixels?
Thanks,
Re: Distortion
Posted: 2016-10-11T11:00:45-07:00
by snibgo
Yes, like this:
Code: Select all
%IM%convert toes.png -virtual-pixel Black -define distort:viewport=800x800-300-300 -distort barrel 0.0301,-0.0733,0 -trim +repage p.png