imwarp function gives strange result

9 views (last 30 days)
Dmitriy Churin
Dmitriy Churin on 7 Apr 2022
Commented: Image Analyst on 8 Apr 2022
Hello,
I am using imwarp function to remove the lens distortion but it does not work as expected. I create displacement matrix for x and y coordinate. The displacement is nonlinear, for example dx=A*x^2. Let say my border pixel at x=3504 should go to pixel value 3204 (dx(3504)=300) after using imwarp, but it actually goes to value to a value 3246. When I use linear displacement dx=300, then everything maps correctly. Any idea how to get it done correctly?
Im=imread('car2.jpg');
[ny nx nz]=size(Im);
x=1:1:nx;
y=1:1:ny;
D_lin=zeros(ny,nx,2);
D_nonlin=zeros(ny,nx,2);
[X Y]=meshgrid(x,y);
dx_lin=300*ones(ny,nx);
dy_lin=0*ones(ny,nx);
dx_nonlin=dx_lin.*(X./nx).^2;
dy_nonlin=0;
D_lin(:,:,1)=dx_lin;
D_lin(:,:,2)=dy_lin;
D_nonlin(:,:,1)=dx_nonlin;
D_nonlin(:,:,2)=dy_nonlin;
Im_lin=imwarp(Im,D_lin);
Im_nonlin=imwarp(Im,D_nonlin);
Thanks,
Dmitriy

Answers (1)

Image Analyst
Image Analyst on 7 Apr 2022
If you have the Computer Vision Toolbox, type "Fisheye calibration basics" into the help's search field.
The optical aberration (more accurately) called "Distortion" is also called by the layman's terms "Fisheye distortion" or "Pincushion distortion". It's where the distorted point is moved away from the optical axis by a delta that is proportional to the cube of the distance from the optic axis. Like rDistorted = rIdeal + factor * rIdeal^3. If factor is positive the point is moved away and you get pincushion distortion. If the factor is negative the point is moved closer and you have fisheye distortion.
  2 Comments
Dmitriy Churin
Dmitriy Churin on 7 Apr 2022
I tried this function, but when I don't have radial symmetry it's not easy to use. So I thought it would be easier to use distortion grid from Zemax. But as I mentioned above, it's not doing what I want. Is there any other way to avoid this issue?
Image Analyst
Image Analyst on 8 Apr 2022
I haven't used imwarp much so I can't really help on that.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!