Barrel


Author V. C. Mohan
Extensively modified on Date 24 oct 2021

This plugin corrects Barrel type or Pin Cushion type distortions in an image that result in due to camera lens projecting image by bending rays unlike iwhat happens in a pinhole camera.. ( The distortions due to perspective are not compensated by this plugin. For correcting perspective distortion one need to use Reform function of this plugin.) In the test mode a distorted matrix of dots is overlain on the specified frame. These will be along lines which will be straightened. Best fit parameters can be arrived at.

Input formats RGB,YUY2, Y or YUV are acceptable.All bit depths are handled. This function is Thread safe. MT_NICE_FILTER

A polynomial with 4 coefficients are used to correct. a, b, and c are the coefficients to be specified and the fourth d is computed internally. These parameters mainly depend upon the lens of the camera, focal length of lens and setting of zoom. Two methods of corrections are implemented. 1.Brown_Conrad and 2. Division method

For many high definition still photographic cameras databases are available on the web. But for video cams there is no such database. The possible reasons are 1. Video camera resolution is limited 2. The camera and or subjects move and therefore such distortions are not noticeable. However, due to advent of HD video cams and the consequent increased usage of tripod one may attempt to correct for such distortions.

By the use of test mode the values of coefficients can be arrived at. For a particular camera and setting of focus, these coefficients will remain same. In test mode the input clip frames are dimmed for better visibility and overlain with dots which lie along distorted lines. This display may aid in selecting proper coefficients.


Note a + b + c should not exceed 1.0 .
After correction one may need to crop image at the edges.
>Note. This Barrel or Pin cushion distortion correction must be done on un cropped image or on symmetrically cropped image as it assumes the center of distortion to be the center of frame.
Details of parameters
Description Name Type Limits Default
Input clip clip RGB or planar YUV444 or Y format only none
coefficient a (xa in independant mode and start val in test mode) a float between 0.0 and 0.5 0.005
coefficient b(xb in independant mode and start val in test mode) b float between 0.0 and 0.5 0.005
coefficient c(xc in independant mode and start val in test mode) c float between 0.0 and 0.5 0.005
whether to correct pin cushion or barrel type distortion pin Boolean true for pin, false for barrel false
method to be used method integer 1 or 2 1
Interpolation scheme q integer 1. manipal, 2. bilinear, 3. bicubic 4x4, 4 Lanczos 6X6 4 1
whether in test mode test Boolean true for test, false for normal false
dimming factor in test mode dim float between 0 and 1.0 0.5
dot density( test mode only) dots int between 1 to 4 2

#Usage examples:-
blankclip(width = 720, height = 480, pixel_type = "RGB32",color = $ffffff,  length = 10)
grid()
Barrel(a = 0.005, b = 0.005, c = 0.005,pin = false)
Barrel(a = 0.005, b = 0.005, c = 0.005,pin = true)
 
Barrel Distortion Example:-

Pin Cushion Distortion Example
with following script dots displayed
Barrel(im,a = 0.005, b = 0.005, c = 0.005,pin = false, test = true)

To my index page down loadmovePlus plugin To Avisynth