- #Camera lens distortion distance how to
- #Camera lens distortion distance software
- #Camera lens distortion distance code
- #Camera lens distortion distance professional
#Camera lens distortion distance how to
#Camera lens distortion distance software
Correct Lens Distortion with Photography Software.What is Lens Distortion in Photography?.
#Camera lens distortion distance code
I also include an optional radius parameter, which allows the user to correct only a subset of the image (rather than the entire thing), but other than that the code is roughly identical to what you see above. If you’d like to see my actual source code, check out this GitHub link. (This sample image has no sharpening applied.)Īgain, I only use a simple resampling technique a more sophisticated one would produce clearer results at the edges. When correcting severe distortion like this, you might want to apply a sharpening algorithm to the final image. Use of a zoom parameter allows us to preserve much more of the photo. The pier at the bottom has been completely erased!īy utilizing a zoom parameter, it is possible to include more of the image in the finished result: If we attempt to correct the image without applying any zoom, the image must be stretched so far that much of the edges are lost completely:
![camera lens distortion distance camera lens distortion distance](https://www.ricoh-iosd.eu/media/8c26a31a95b875cdb08b608f20b982f5/Distortion_5MP.jpg)
Severe distortion like this is difficult to fully correct. To give a specific example of the second circumstance, consider this fish-eye photo from Wikipedia, courtesy of Josef F. On images with severe distortion, such as true fish-eye photos, zooming-out retains more of the source materialĪs there is not a universally “correct” solution to these two scenarios, I recommend providing zoom as a tunable parameter.On images with only minor lens distortion, zooming out reduces stretching artifacts at the edges of the corrected image.I added the zoom parameter after some experimentation specifically, I find zoom useful in two ways: I should mention that the algorithm works just fine without the zoom parameter. Note also that sourceX and sourceY will be floating-point values - so for best results, you’ll want to interpolate the color used instead of just clamping sourceX and sourceY to integer values. Note that you’ll need to do some bounds checking, as sourceX and sourceY may lie outside the bounds of the original image. Set color of pixel (x, y) to color of source image pixel at (sourceX, sourceY) Set sourceY = halfHeight + theta * newY * zoom Set sourceX = halfWidth + theta * newX * zoom Set distance = squareroot(newX ^ 2 + newY ^ 2) Set correctionRadius = squareroot(imageWidth ^ 2 + imageHeight ^ 2) / strength 0 = no change, high numbers equal stronger correction. My use of simple bilinear resampling blurs the output slightly a more sophisticated resampling technique would produce clearer results.Ī key feature of the algorithm is that it works at any aspect ratio - rectangular images, like the one above, are handled just fine, as are perfectly square images.Īnyway, here is the required code, as pseudocode: (Pay special attention to the lines on the floor and the glass panels on the right.) Here’s the same image, as corrected by the algorithm in this article.
![camera lens distortion distance camera lens distortion distance](https://ae01.alicdn.com/kf/H9240da7f2fc247d8af777d72e2ee2675x/Distortion-free-4K-wide-angle-15X-micro-distance-high-definition-fish-eye-portrait-four-in-one.jpg)
This lovely demonstration photo comes from Wikipedia, courtesy of Ashley Pomeroy Here is a sample photo that suffers from typical spherical distortion: The effect is also fast enough to preview in real-time.īefore sharing the algorithm, let me demonstrate its output. The key part of the algorithm is less than ten lines of code, so there’s not much work involved.
![camera lens distortion distance camera lens distortion distance](https://www.mdpi.com/sensors/sensors-20-03695/article_deploy/html/images/sensors-20-03695-g004.png)
PhotoDemon’s new lens correction tool in action. This approach requires way more resources than a small developer like myself could handle, so I chose a simpler solution: a universal algorithm that allows the user to apply their own correction, with two tunable parameters for controlling the strength of the correction.
#Camera lens distortion distance professional
Some professional software packages address the problem by providing a comprehensive list of cameras and lenses - then the user just picks their equipment from the list, and the software applies a correction algorithm using a table of hard-coded values. Lens distortion is a complex beast, and a lot of approaches have been developed to deal with it. (There are very few useful examples of lens correction on the Internet - most articles simply refer to existing software packages, rather than explaining how the software works.) I thought I’d share the algorithm I use, in case others find it useful.
![camera lens distortion distance camera lens distortion distance](https://image.made-in-china.com/202f0j00dVzYTDOnYaoU/Dual-Lens-USB-Camera-Module-2MP-1080P-Android-with-No-Distortion-Lens-for-Distance-Measuring-Equipment.jpg)
One of the new features in the development branch of my open-source photo editor is a simple tool for correcting lens distortion.