VCLib Documentation  6.12.2

Lens Transformations (Undistortion)

Lens Transformations (Undistortion)

Functions

I32 lens_transform (image *src, image *dst, point *center, F32 k3, U8 bgnd)
 Lens Distortion Correction (Subpixel Interpolated). More...
 
I32 lens_transform2 (image *src, image *dst, point *center, F32 f, F32 magnification, U8 bgnd)
 Lens Distortion Correction Using Tilted Camera Assumption. More...
 
void deinit_lens_transform2 ()
 Deallocates 2D Table for Lens Transform. More...
 
I32 init_lens_transform2 (F32 f, F32 magnification, I32 nr, I32 nc)
 Allocates and Initializes a Table for General Lens Transforms. More...
 

Detailed Description

Function Documentation

◆ lens_transform()

I32 lens_transform ( image src,
image dst,
point center,
float  k3,
U8  bgnd 
)

The function performs a lens correction transformation.

Pincushion- and barrel-type distortions can be corrected. Distortions of this type typically increase with the square of the distance to the optical centerpoint. The transformation is performed using the following formula:

\[ \left[ \begin{array}{c} x_\textrm{dst} - \textrm{center}_x \\ y_\textrm{dst} - \textrm{center}_y \end{array} \right] = \left[ \begin{array}{c} x_\textrm{src} - \textrm{center}_x \\ y_\textrm{src} - \textrm{center}_y \end{array} \right] * \left( 1 - \frac{k_3}{1000} * \left[ \begin{array}{c} x_\textrm{src} - \textrm{center}_x \\ y_\textrm{src} - \textrm{center}_y \end{array} \right]^2 \right) \]

Pixels for which the corresponding source image is not defined, are set to bgnd.

Parameters
srcPointer to Source Image.
dstPointer to Destination Image.
centerCenterpoint for Transform.
k3Transform Coefficient with
  • k3 = 0: No Distortion.
  • k3 < 0: Barrel Distortion.
  • k3 > 0: Pincushion Distortion.
bgndBackground Grey Value.
Memory Consumption
None.
See also
lens_transform2().
Return values
ERR_NONEon Success.

◆ lens_transform2()

I32 lens_transform2 ( image src,
image dst,
point center,
float  f,
float  magnification,
U8  bgnd 
)

The function performs a subpixel interpolated lens correction for barrel-type distortions (subpixel interpolated radial lens correction according to Pers, Kovacic, Nonparametric, Model-Based Radial).

The function corrects non-linear circular symmetric distortions based on a universal model of the lens. The model assumes that the lens maps a part of a sphere to the CCD-sensor. All the user needs to know is the focal length of the lens in units of the sensor pixel size. The model cannot be applied to telecentric lenses and some specially corrected lenses and has to be approved for a specific lens. Also, it is possible that focal length parameter for this routine deviates from the actual f-value. The transformation is performed using the following formula:

\[ \left[ \begin{array}{c} x_\textrm{dst} - \textrm{center}_x \\ y_\textrm{dst} - \textrm{center}_y \end{array} \right] = \left[ \begin{array}{c} x_\textrm{src} - \textrm{center}_x \\ y_\textrm{src} - \textrm{center}_y \end{array} \right] * \left( \textrm{mag} * \textrm{correction}(r^2) \right) \]

The key parameter for the correction is f, namely the focal length of the lens divided by the pixel size. For example, using a lens with a focal length of 6 mm together with a VC4472 camera ( 4.4×4.4µm pixel size) would be: $ f := 1000.0 * \hbox{\kern.1em\raise.25ex\hbox{6.0}/\kern-.15em\lower.25ex\hbox{4.4}}$. The factor of 1000 is due to the fact that 1 mm equals 1000 µm. The image can be magnified (mag > 1.0) or demagnified (mag < 1.0). A tilt in the object plane (object plane not perpendicular to optical axis) can be easily adjusted by setting the transformation centerpoint (center.x, center.y) to some pixel outside the CCD midpoint, since this effectively rotates the optical axis. Pixels for which the corresponding source image is not defined, are set to bgnd. When called the first time, the function builds up a table for the correction values. The memory for the table is automatically allocated and the table is calculated, which may take some time. The table is kept in memory for further use with the same parameters. If the parameters are changed, the old table will be released and a new table will be set up. To deallocate the table memory, the function void deinit_lens_transform2() should be called.

Parameters
srcPoints to Source Image.
dstPoints to Destination Image.
centerCenterpoint for Transform.
fFocal_Length_Of_Lens / Pixel_Size.
bgndBackground Grey Value.
Memory Consumption
4*( dst->dx - p->cx)*( dst->dy - p->cy) Bytes, use function deinit_lens_transform2() to release memory.
See also
lens_transform().
Return values
ERR_TYPEif src and dst Type are not equal, or not valid.
ERR_MEMORYif Memory Allocation fails.
ERR_NONEon Success.
ERR_TYPEif src and dst Type are not equal, or not valid.
ERR_MEMORYif Memory Allocation fails.
ERR_NONEon Success.

◆ init_lens_transform2()

I32 init_lens_transform2 ( float  f,
float  magnification,
I32  nr,
I32  nc 
)

This function allocates and initializes a table for doing general lens transforms. If no change in parameters occured, there will not be any allocation or calculation. To deallocate the table, call the function deinit_lens_transform2().

Return values
ERR_MEMORYif Memory Allocation fails.
ERR_NONEon Success.
ERR_MEMORYif Memory Allocation fails.
ERR_NONEon Success.
ERR_MEMORYif Memory Allocation fails.
ERR_NONEon Success.

◆ deinit_lens_transform2()

void deinit_lens_transform2 ( )

This function deallocates the 2D Table being allocated after calling init_lens_transform2().