| Customize Help

Pixel and real-world units

In MIL, there are two types of units that you can use for setting information and retrieving results: pixel units and real-world units (for example, inches or centimeters). Real-world units are called world units for simplicity. Pixel units are directly related to the image and are always available; however, to work in world units, you must perform camera calibration to establish the relationship between the pixel coordinate system and the real world.

Note that MIL-Lite does not support world units.

Pixel units and the pixel coordinate system

When working in pixel units, you are using the pixel coordinate system. The center of the top-left pixel of the image corresponds to the origin (0,0). The X-axis follows the first row of pixels, and the Y-axis follows the first column of pixels. The following image shows the pixel coordinate system; the dots indicate the center of the pixels.

For MIL modules that support subpixel accuracy, it is important to keep in mind that since the center of the pixel is used as its reference position, the top-left corner of the first pixel is considered (-0.5, -0.5), and the bottom-right corner of the last pixel is (sizeX - 0.5, sizeY - 0.5).

When working in pixel units, angles are interpreted and measured in degrees with respect to the pixel coordinate system; positive angles are always interpreted to be in a counter-clockwise direction from the initial side.

Note that since the Y-axis of an image is oriented downwards, the angles in MIL are inverted from mathematical convention. In certain cases, you might want to convert angles from MIL convention to mathematical convention: the negative value of an angle in MIL convention is the true value of the same angle in mathematical convention. For example, 45° in MIL convention is the same as -45° in mathematical convention.

For more information on the pixel coordinate system, using subpixel accuracy, and angle conventions in MIL, see the Pixel conventions and subpixel accuracy section of Chapter 21: Data buffers.

World units and world coordinate systems

In MIL, you can set and retrieve positional information in real-world units (for example, inches or centimeters). To do so, you must specify the relationship between the pixel coordinate system and the real world through camera calibration. This involves choosing a fixed location (that is, a position and orientation) in the real world from which to make this mapping, and the distance that will represent one unit. Together, these define the absolute real-world coordinate system (or for simplicity, the absolute coordinate system). You can then map pixels to the location that they represent in the real world with reference to the absolute coordinate system.

After calibrating, you should further specify a reference in the absolute coordinate system, known as the relative coordinate system, from which you want to specify settings and retrieve results. Unlike the absolute coordinate system, which is immoveable, you can move the relative coordinate system to any required location. This allows you to specify settings and retrieve information with respect to any required location.

Moving the relative coordinate system can be useful, for example, if an object appears at a number of different positions in your image, and you want to apply the same measurement or inspection process to every instance of the object. You can fix the relative coordinate system with respect to each object in succession, and apply your process to every instance of the object. This process is known as fixturing; for more information, see the Fixturing an object with the relative coordinate system subsection of the Child buffers, regions of interest, and fixturing section later in this chapter.

If you then need to transform results with respect to a location in the real world other than the absolute coordinate system (for example, the camera), MIL allows you to define other coordinate systems in the real world and transform locations between them. For more information, see the Coordinate systems section of Chapter 26: Calibrating your camera setup.

Most MIL modules support real-world units and can take settings and return results with respect to the relative coordinate system. For a complete list of MIL modules that support this functionality, see the Working with real-world units section of Chapter 26: Calibrating your camera setup.

Camera calibration

Camera calibration relates pixels to real locations and distances. For example, you can create the following relationship between a pixel and its size and location in the real world.

Uniform camera calibration is the simplest technique that you can use to calibrate your camera setup. To use this technique, each pixel in the image should represent the same sized area in the real world, your camera should be placed directly above the subject in the image, and lens distortion should be negligible. To perform a uniform camera calibration, use McalUniform(). This mapping can be any combination of scaling, rotation, and translation.

The following illustrations show the position of the pixel and absolute coordinate systems after three example uniform camera calibrations. Note that the pixel coordinate system is defined with respect to the absolute coordinate system (not vice versa) because the absolute coordinate system is fixed in the world.

To handle more complex setups and various types of distortion, MIL supports a variety of different camera calibration modes, including 3D-based camera calibration modes. For more information on camera calibration, see the Uniform camera calibration and other camera calibration modes section of Chapter 26: Calibrating your camera setup.