How to make a seamless barrel (fisheye lens) or pincushion distortion

Hi, I have undistorted grayscale images and wish to distort them locally with barrel (fisheye) or pincushion distortions. It is important that the 'edges' of the lens are not seen, i.e. I want to manipulate the distortion function, not work with masking or so to merge images . I have seen answers here relating how to apply the distortion in general, but it warps the entire picture.
related thread: http://stackoverflow.com/questions/2589851/how-can-i-implement-this-visual-effect-in-matlab the function fisheye_inverse is already quite nice but I'm not sure how to manipulate the position of the effect, and its overall size or direction.
See the link for a successful example from another software.

Answers (1)

That code looks wrong to me. But it does give a similar effect. I don't think it was developed by someone with a Ph.D. in optics, like I have. If you want a true barrel or pincushion aberration simulated, you don't scale the location of the point by the square of the distance to the optic axis like they did, though that might seem reasonable to someone who hasn't taken a course in lens design. The actual formula , for a real optical system at the lowest order, says that the distance the point moves , from its "perfect" position, is proportional to the cube of the distance of the perfect point from the origin (optic axis). In other word not rNew = a*rOld^2 like they did, but rNew = rOld + a*rOld^3 or rNew = rOld(1+arOld^2), where r means radius from the optic axis, which is not the same formula as your links used.

2 Comments

You're right, the code at least in the first link is odd, it even gives the option to change the exponent. The image processing demo that is also linked in the last question (<http://www.mathworks.de/products/image/examples.html?file=/products/demos/shipping/images/ipexcheckerboard.html#17>) gives the same equation as you do. And indeed I'm froma different field so I appreciate your help.
But my actual question is how to change the focus of the distortion to a different part of the image and make the distortion taper off so that only a defined part of the image is affected, e.g. have a distortion only in the upper left corner or so... ideally, I would put in the coordinates and extent of the distortion, next to the strength a.
Thanks again!

Sign in to comment.

Categories

Asked:

on 6 Jan 2014

Commented:

on 7 Apr 2014

Community Treasure Hunt

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

Start Hunting!