From 11:00 PM CST Friday, Apr 11th - 1:30 PM CST Saturday, Apr 12th, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

NI Vision Concepts Help

Content Type
Programming Language
Current manual

Concepts

Concepts

The calibration software uses a calibration algorithm and a list of known pixel to real-world mappings to compute calibration information for the entire image. The calibration software uses these known mappings to compute the pixel to real-world mapping for the entire image. Individual calibration algorithms may have specific requirements for creating the list of pixel to real-world mappings.

After you calibrate an image, you can define a calibration axis in order to express pixel measurements in real-world units, or spatially correct a portion of a distorted image.

You can also review statistical results to evaluate the quality or state of your calibration system.

Mapping Pixel Coordinates to Real-World Coordinates

You can specify a list of pixel to real-world mappings in two ways, depending on the calibration algorithm you select. You can manually map pixel coordinates to real-world coordinates, or you can use a calibration grid.

The resulting calibration information is valid only for the imaging setup that you used to create the mapping. Any change in the imaging setup that violates the mapping information compromises the accuracy of the calibration information.

Defining Mappings Manually

To define mappings manually, input a list of real world points and the corresponding pixel coordinates to the calibration software. The following table describes the algorithms that allow you to define mappings manually:

Name Description
Simple Calibration Simple calibration transforms pixel coordinates to real-world coordinates by scaling the image horizontally and vertically. Provide the calibration software with the horizontal and vertical distance between pixels in real-world units.
Perspective Calibration Provide a set of pixel to real-world mappings to perspective calibration to correct the perspective distortion. A minimum of 4 pixel to real-world mappings are required to correct the perspective distortion, but additional mappings may provide better results.

Using a Calibration Grid

A calibration grid consists of a grid of equidistant points similar to the grid of dots shown in figure A. 

Calibration Setup

To use a calibration grid, provide the calibration with the horizontal (dx) and vertical (dy) spacing between the points in real-world units. The calibration software uses the image of the grid, shown in figure B, and the spacing between the dots in the grid to generate the list of pixel to real-world mappings required for the calibration process.

The following algorithms support using a calibration grid:

  • Distortion Model
    • Division
    • Polynomial
  • Camera Model
  • Microplane Calibration

Refer to the following guidelines to achieve accurate results with a calibration grid:

  • The calibration grid should cover most of the field of view or area under inspection.
  • A minimum of 4 pixel to real-world mappings are required to correct distortion in the image, but additional mappings may provide better results.
Using Multiple Calibration Grid Images

Some calibration algorithms may require multiple calibration grids. For example, a distortion model can only be learned for points that are present in a calibration grid image. If the points do not cover the entire field of view or area under inspection, the distortion model may be inaccurate.

NI Vision calibration software can use multiple calibration grid images. The following figure illustrates multiple calibration grid images obtained by repositioning the calibration grid within a single field of view.

noloc_calibration_multiple_grids.png

When multiple images are supplied, the calibration software uses a least square method to optimize the distortion model. After learning the distortion model, you must perform perspective calibration to set the working plane on which you want to make measurements and enable pixel to real-world mappings.

The following figure illustrates the steps involved in using multiple calibration grid images.

loc_calibration_distortion_process.png

First, learn the distortion or camera model using points from multiple calibration grid images. Then learn the perspective calibration for the working plane on which you want to make the measurement. If the working plane changes, you must relearn the perspective calibration.

Using Multiple Calibration Grid Images in Multiple Planes

To compute a camera model, you must provide multiple grid images from at least three different projection planes. The following figure illustrates the same calibration grid in multiple projection planes.

noloc_calibration_multiple_planes.png

For accurate results, the calibration grids used to calculate the camera model should cover a minimum relative angle of 45 degrees. The following figures illustrate different relative angle coverages:

noloc_calibration_relative_angles.png

Figure A illustrates two calibration grids with a relative angle range of 20 degrees. Figure C illustrates two calibration grids with a relative angle of 90 degrees. A camera model calculated for figure A would be less accurate than the camera model calculated for figure C. For example, the point where the grids intersect in Figure C is much more clearly defined than in the other figures. If the relative angle between calibration grids is too small, the calibration software indicates that it does not have sufficient data to compute the camera model.

For the most accurate results, use multiple calibration grid images to compute a camera model, as illustrated in the following figure:

noloc_calibration_relative_angles2.png

Calibration Axis

To express measurements in real-world units, you must define a calibration axis. To define a calibration axis, specify the following information:

  • The origin of the calibration axis, expressed in pixel coordinates
  • The angle between the calibrated x-axis and the horizontal axis of the image, expressed in degrees
  • The direction of the calibrated vertical axis, either direct or indirect

The following figure illustrates a default calibration axis and a user-defined calibration axis. The origins of the coordinate systems lie at the center of the circled dots. Point A indicates the origin for a default calibration axis starting at the top leftmost pixel of an image. Point B indicates the origin of a user-defined calibration axis.

The calibration axis angle, defined by θ, specifies the orientation of the calibrated x1 axis with respect to the horizontal axis in the image.

The calibration axis originating at point A uses an indirect vertical axis, while the calibration axis originating at point B uses a direct vertical axis.

noloc_defcoordsys.png

The following figures illustrate vertical axis directions. An indirect axis orientation, as shown in figure A, corresponds to a typical digital image where the top left pixel serves as the origin. A direct axis orientation, as shown in figure B, corresponds to the orientation of a real-world cartesian Y-axis.

Axis Direction of a Coordinate System

Default Calibration Axis Definition

If the calibration uses multiple calibration grid images, the calibration axis is defined in the working plane image.

The calibration process defines a default calibration axis as follows:

  1. The origin is set according to the following conditions:
    • If you use manually defined reference points, the origin is placed at point 0, 0 relative to the points you define.
    • If you use a calibration grid image, the origin is placed at the center of the left, top-most point in the calibration grid image.
  2. The angle is set to zero. This aligns the x-axis with the topmost row of points in the calibration grid image.
  3. The vertical axis direction is set to indirect. This aligns the y-axis to the leftmost column of points in the calibration grid image.

If you specify a list of points instead of using a calibration grid, the points define the default calibration axis origin, angle, and vertical axis direction.

Redefining a Calibration Axis

You can use NI Vision software to redefine a calibration axis. For example, you may want to define a calibration axis based on measurements taken from a part under inspection.

The following figure shows an inspection application whose objective is to determine the location of the hole in the board with respect to the corner of the board. The board is on a stage that can translate in the x and y directions and can rotate about its center. The corner of the board is located at the center of the stage.

In the initial setup, shown in figure A, the defined calibration axis aligns with the corner of the board using the following parameters:

  • The origin of the calibration axis is defined as the location in pixels of the corner of the board
  • The angle of the calibration axis is set to 180 degrees
  • The axis direction is set to indirect

In this example, you can use pattern matching to find the location in pixels of the hole, as illustrated by the crosshair mark in figure A. Convert the location of the hole in pixels to a real world location. This conversion returns the real world location of the hole with respect to the defined calibration axis.

During the inspection process, the stage may translate and rotate by a known amount. This causes the board to occupy a new location in the camera's field of view, which makes the board appear translated and rotated in subsequent images, as shown in figure B. Because the board has moved, the original calibration axis no longer aligns with the corner of the board. Therefore, measurements made using this calibration axis are inaccurate.

Use the information about how much the stage has moved to determine the new location of the corner of the board in the image. Use the Set Calibration function to update the calibration axis to reflect the new position, as illustrated in figure C. The origin of the updated calibration axis becomes the new pixel location of the corner of the board, and the angle of the calibration axis is the angle by which the stage has rotated.

Moving Coordinate System

Calibration Quality Information

Distortion is specified in relative terms. For example, a lens which exhibits 2 percent barrel radial distortion over a given field will image a point in the corner of the field 2 percent too far from the optical axis. In the resulting image, a corner that should be 400 pixels from the optical axis measures 408 pixels away from the optical axis.

NI Vision calibration software provides a percentage distortion statistic to indicate the quality of a calibrated system. NI Vision software calculates the error divided by the distance from the optical axis for each pixel. The average result is presented as the percentage distortion statistic.

Use the percentage distortion statistic to determine whether the selected calibration algorithm is adequate for your application. For example, you may receive a high percentage distortion statistic if you use perspective calibration or a sparse calibration grid to correct an image exhibiting nonlinear or lens distortion. You can also use the percentage distortion statistic to determine whether there is a problem with the calibrated system. For example, if your lens introduces negligible distortion, a high percentage distortion statistic may indicate a problem such as a physically distorted calibration template.

Error Map

NI Vision calibration software computes an error map, along with the following error statistics:

  • Mean error
  • Maximum error
  • Standard deviation

The error map is an estimate of the positional error that you can expect when you convert a pixel coordinate into a real-world coordinate. The error map is a 2D array that contains the expected positional error for each pixel in the image.

The error value of the pixel coordinate (ij) indicates the largest possible location error for the estimated real-world coordinate (xy) as compared to the true real-world location. The following equation shows how to calculate the error value.

Error value calculation for coordinate (i,j)

The error value indicates the radial distance from the true real world position in which the estimated real world coordinates can exist. The error value has a confidence interval of 95%, which implies that the positional error of the estimated real-world coordinate is equal to or smaller than the error value 95% of the time. A pixel coordinate with a small error value indicates that its estimated real-world coordinate is computed very accurately. A large error value indicates that the estimated real-world coordinate for a pixel may not be accurate.

Use the error map to determine whether your imaging setup and calibration information satisfy the accuracy requirements of your inspection application. If the error values are greater than the positional errors that your application can tolerate, you need to improve your imaging setup. An imaging system with high lens distortion usually results in an error map with high values. If you are using a lens with considerable distortion, you can use the error map to determine the position of the pixels that satisfy the accuracy requirements of your application. Because the effect of lens distortion increases toward the image borders, pixels close to the center of the image have lower error values than the pixels at the image borders.

Image Correction

Image correction involves transforming a distorted image acquired in a calibrated setup into an image where perspective errors and lens distortion are corrected. NI Vision corrects an image by applying the transformation from pixel to real-world coordinates for each pixel in the input image. Then NI Vision applies simple shift and scaling transformations to position the real-world coordinates into a new image. NI Vision uses interpolation during the scaling process to generate the new image.

When you learn for correction, you have the option of constructing a correction table. The correction table is a lookup table, stored in memory, that contains the real-world location information of all the pixels in the image. The lookup table greatly increases the speed of image correction but requires more memory and increases your learning time. Use this option when you want to correct several images at a time in your vision application.

Tip Tip  Correcting images is a time-intensive operation. You may be able to get the measurements you need without image correction. For example, you can use NI Vision particle analysis functions to compute calibrated measurements directly from an image that contains calibration information but has not been corrected. Also, you can convert pixel coordinates returned by edge detection tools into real-world coordinates.

Correction Area

You can correct an entire image or regions in the image based on user-defined ROIs or the calibration ROI defined by the calibration software. The following figure illustrates the different image areas you can specify for correction. NI Vision learns calibration information for only the regions you specify.

1  Full Image 2  User or Calibration ROI 3  User ROI 4  User and Calibration ROI 5  Calibration ROI
  • Full Image—Corrects the entire image regardless of the calibration ROI and the user-defined ROI.
  • User or Calibration ROI—Corrects pixels in both the user-defined ROI and the calibration ROI.
  • User ROI—Corrects only the pixels inside the user-defined ROI specified during the learn calibration phase.
  • User and Calibration ROI—Corrects only the pixels that lie in the intersection of the user-defined ROI and the calibration ROI.
  • Calibration ROI—Corrects only the pixels inside the calibration ROI. The calibration ROI is computed by the calibration algorithm.

The valid coordinate indicates whether the pixel coordinate you are trying to map to a real-world coordinate lies within the image region you corrected. For example, if you corrected only the pixels within the calibration ROI but you try to map a pixel outside the calibration ROI to real-world coordinates, the Corrected Image Learn ROI parameter indicates an error.

Scaling Mode

The scaling mode defines how to scale a corrected image. Two scaling mode options are available: scale to fit and scale to preserve area. The following illustrates the scaling modes. Figure A shows the original image. With the scale to fit option, the corrected image is scaled to fit in an image the same size as the original image, as shown in figure B. With the scale to preserve area option, the corrected image is scaled such that features in the image retain the same area as they did in the original image, as shown in figure C. Images that are scaled to preserve area are usually larger than the original image. Because scaling to preserve the area increases the size of the image, the processing time for the function may increase.

Scaling Modes
Was this information helpful?

Help us improve your future ni.com experience.

Did you find the documentation you were looking for?

Submit