Camera calibration & rectification

These tools correct problems introduced by the camera and lens — distortion and misalignment — before the PIV analysis runs. They're different from Spatial calibration (px → mm), which just converts pixel units to physical units after the fact.

ToolCorrects
Camera calibration (undistortion)Lens distortion (barrel/pincushion effects) using a photographed marker board.
Image rectificationMisalignment between the camera's image plane and your target coordinate system / laser sheet.
Two cameras: stereo-PIV After Import images of two cameras, each camera gets its own lens calibration and its own board image in the light sheet. The panels work on the camera that is shown; switch it with the CAM 1 / CAM 2 button at the bottom left. The stereo calibration then replaces the 2D rectification. See Stereo-PIV (2D3C).

Setting up a marker board

Both calibration and rectification are done by photographing a printed ChArUco board (a checkerboard combined with ArUco markers). Configure it via Image settings → Camera calibration → Setup / define / generate marker board:

FieldMeaning
Board typeCurrently only ChArUco DICT_4X4_1000.
Origin colorColor of the top-left checker (Black/White) — must match your printed board.
Rows / ColumnsCheckerboard dimensions (default 14 × 21; with the default 12 mm checkers, the board fits A4 landscape).
Checker size / Marker sizePhysical size of the checkers and the ArUco markers printed on them.

Click Guess parameters to have PIVlab estimate these from a photo, or Generate Charuco board to produce a printable board matching your settings. Save it as TIFF (300 dpi) or as print-ready PDF. In the PDF, all checkers and markers have their exact size in mm. Print either file at 100 % scaling.

The PDF also suits printing on transparent material, e.g. an acrylic plate that is seen from both sides in stereo PIV.

What to tell the print shop reference

The PDF is in CMYK (black = 100 % K) with 5 mm bleed. White is the spot colour weiss (overprint) in the top layer weiss; it does not overlap the other colours. The suggested file name contains the board size, e.g. …_300x290mm_plus_5mm_bleed.pdf.

A generated board carries a QR code in place of the central 2 × 2 checkers that holds all of these parameters. It is also read when the board is seen from behind. With the Calibration overlay of the image acquisition, PIVlab reads that code from the live image and fills the fields above by itself, so the board's dimensions and scale do not have to be entered by hand.

The left and bottom margins show the axes of the results (default axes of the calibration, also for stereo PIV), as seen from camera 1 with the board upright in the image: x points to the right, y up and z out of the board, toward the camera (⊙). The two ticks and the 0 mark the row and the column line through the inner checker corner at the bottom left. The board only sets the directions: the origin of the results is the bottom left of the image. Seen from behind, the board and its axes appear mirrored.

PIVlab Marker board setup panel
The Marker board setup panel.
A generated printable ChArUco board: a checkerboard with ArUco markers in the white squares, a QR code in the centre, labelled with its dictionary and dimensions, and the axes x (right), y (up) and z (out of the board) in the bottom left margin
A board produced by Generate Charuco board with the default settings — print it out and photograph it to calibrate. The header and the QR code in the centre record its exact parameters (dictionary, rows × columns, checker/marker sizes) so PIVlab can detect it.

Choosing the checker size

How large the checkers should be, and the limits tips

Design the board for the camera image, not for the paper: the board should fill the camera image, and one checker should cover about 60–130 pixels in the image. More and smaller checkers do not make the calibration more accurate — in tests with synthetic images of a real camera, a board with about 120 corners calibrated as well as one with 1700. Small checkers only make the marker detection fail.

c ≈ 60…130 × W / N

where c is the checker size [mm], W the width of the field of view [mm] and N the image width [px].

Example: a camera with 1936 px image width looking at a 520 mm wide field of view has 0.27 mm/px, so the checkers should be about 16–35 mm, i.e. a board with about 15–30 columns.

Checker in the imageDetection
below about 20 pxMarkers are not detected.
20–60 pxWorks with sharp images. With blur or image noise the marker detection becomes unreliable.
60–130 pxRecommended. Reliable also with slightly blurred or noisy images.
above about 200 pxStill accurate, but each image has only few corners. Keep at least about 6 × 9 checkers on the board.
Limitations of the ChArUco detection
  • A board can have at most 2000 checkers (rows × columns); the generator refuses larger boards. A board that fills the image therefore cannot have arbitrarily small checkers. On cameras with more than about 30 megapixels this forces checkers larger than 130 px, which is fine.
  • The board may extend beyond the image edges: each corner is identified by its neighbouring markers, so partly visible boards are used.

Camera calibration (lens undistortion)

Open via Image settings → Camera calibration → Camera calibration (undistortion).

PIVlab Camera calibration panel
The Camera calibration panel.
  1. Click Load target images and select several photos of your marker board from different angles/positions.
  2. If your camera uses a Scheimpflug adapter (tilted sensor), enable Scheimpflug, tilt (deg) first and enter the tilt angle of the adapter (tilt about the vertical image axis, without sign). With 0, PIVlab estimates the tilt from the target images, which is usually inaccurate.
  3. Click Estimate cam parameters to detect the markers and compute the lens model.
  4. Save parameters to reuse this calibration later, or Load parameters to bring back a previous one.

Checking the result

ButtonShows
Show reprojection errorsHow well the model fits — should be below 1 pixel for a valid calibration.
Show camera positionsWhere the camera was relative to the board in each calibration image.
Show lens distortionA visualization of the detected lens distortion.
A visualization of the lens distortion: a colour map showing how far pixels are displaced, smallest in the centre and growing toward the corners, with profile curves along the edges
Show lens distortion — how far each pixel is displaced by the lens. It's smallest at the centre and grows toward the corners, the classic radial distortion pattern being corrected.
A 3D scene: the calibration board as printed, with the x, y, z axes of the results at its origin, and around it twelve numbered camera symbols, one per calibration image, each with a dashed line to the board centre and a line down to a grid on the floor
Show camera positions — where the camera was relative to the board in each calibration image, numbered as the images. Drag to rotate the view, right-drag to pan, use the wheel to zoom.

Applying it

Set Output image size — undistorting an image curves its straight edges, so you choose how to handle the resulting black borders: Cut away black borders, keep the Same size as input image, or Include black borders in full. Then tick Enable camera calibration to actually apply the undistortion to your images.

Image rectification

Open via Image settings → Camera calibration → Image rectification / alignment (you need images loaded first). Rectification aligns the image with your target coordinate system by photographing the marker board positioned inside the laser sheet, aligned with the plane you actually want to measure.

PIVlab Image rectification panel
The Image rectification panel.
  1. Click Load target image and select that photo.
  2. Use Show detected markers, Show rectified board and Show camera position to check the detection before committing.
  3. Set Upscaling (1× or 2×) — upscaling reduces artifacts from image interpolation during rectification, at the cost of slower analysis.
  4. Tick Enable image rectification to apply it.
A calibration-target image after undistortion and rectification: originally straight edges now bow outward, showing the geometric correction that has been applied so the image plane matches the target
A target image after undistortion and rectification. The curved outline shows the geometric correction PIVlab applies so the image plane lines up with your target coordinate system.
Both can be used together Calibration (undistortion) and rectification address different problems and can be enabled at the same time: undistortion first removes lens artifacts, then rectification aligns the corrected image with your coordinate system.
Using the calibration in a script Save a session (or the camera parameters) after the calibration. A MATLAB script then applies the same undistortion and rectification with pivlab.preprocess(imgs, Camera="my_session.mat") — see Command line (API).