System designHow-to

Homography pixel coordinates: map points into a warped image

Map homography pixel coordinates into a warped image using explicit origin, pixel spacing and axis direction, with worked checks for scale errors.

LumaSpec Vision9 min read Share on LinkedIn

On this page 9 sections
  1. 011. Define the coordinate contract
  2. 022. Establish the forward plane mapping
  3. 033. Specify the output raster reference
    1. Pixel centers are not pixel edges
  4. 044. Calculate one point from source to raster
  5. 055. Verify the overlay before rounding
  6. 066. Diagnose the mismatch by its pattern
  7. 077. Match acquisition and processing to the task
  8. 088. Check the limits before releasing the mapping
  9. 09Questions

A perspective-corrected image can look right while transformed reference points appear at the wrong scale or location. Usually, the points and the displayed image use different coordinate systems: one describes a physical plane, while the other uses raster pixels. This procedure is for engineers building planar measurement, inspection or guidance systems. You will define both mappings explicitly, calculate a complete example, and separate geometry errors from display and indexing errors.

1. Define the coordinate contract

Before changing the transformation, label every coordinate pair entering and leaving your pipeline. Do not call everything an image coordinate.

Coordinate space Typical notation Units and convention
Source image x, y Continuous pixel coordinates; x is horizontal and y is vertical
Rectified physical plane X, Y Physical units, such as millimeters, with a defined origin and axis direction
Output raster c, r Continuous column and row coordinates in the warped image
Array element image[r, c] Integer indices, with the language's indexing convention

A homography maps between projective planes. Its destination coordinates are whatever you supplied during fitting. If your destination reference points were measured in millimeters, the transformed points are plane coordinates in millimeters—not automatically output array indices.

If you fitted directly to desired output pixel coordinates, the homography may already include the raster mapping. Do not apply an additional scale and offset afterward.

For the broader distinction between projective and rigid coordinate mappings, use the guide to homogeneous transformation matrices in camera-guided motion.

2. Establish the forward plane mapping

  1. Collect corresponding source-image points and known points on the target plane. Keep their ordering identical in both lists.
  2. Fit the mapping from source image coordinates to plane coordinates. Record that direction alongside the matrix.
  3. Transform the calibration points and compare them with their known plane positions before involving the warped image.
  4. Test additional points that were not used to fit the transformation.

A planar homography needs at least four suitable correspondences. For a minimal four-point set, no three points should be collinear. Spread the points across the working area rather than clustering them near the center. Additional correspondences allow an overdetermined fit and make residual checks more useful.

Using column vectors, define the forward mapping as:

q = H × [x, y, 1]^T q = [a, b, w]^T X = a / w Y = b / w

The division by w is homogeneous normalization. Without it, a projective transformation generally produces position-dependent errors rather than a consistent physical mapping.

Some software uses row vectors and a transposed matrix layout. Follow its documented convention; transposing a matrix and reversing a transformation are different operations.

3. Specify the output raster reference

  1. Set the output image dimensions, physical pixel spacing, origin and axis directions explicitly. Retrieve the actual output reference if the warper chooses these automatically.

Suppose the physical plane uses X increasing rightward and Y increasing upward. The output array uses columns increasing rightward and rows increasing downward. Let X0 and Y0 identify the physical position of the upper-left pixel center.

s_x = physical distance per output column s_y = physical distance per output row c = (X - X0) / s_x r = (Y0 - Y) / s_y

Here, c and r are zero-based continuous pixel coordinates. If physical Y also increases downward, use r = (Y - Y0) / s_y instead.

For the upward-positive physical convention, the raster mapping can be written as another homogeneous matrix:

B = [ 1/s_x 0 -X0/s_x ] [ 0 -1/s_y Y0/s_y ] [ 0 0 1 ] G = B × H [c, r, 1]^T is proportional to G × [x, y, 1]^T

Normalize the output of G by its final component. Composing the matrices gives the same coordinates as normalizing H's output and then applying B.

Pixel centers are not pixel edges

Some output references specify outer pixel edges instead of the first pixel center. With an upward-positive physical Y axis, an upper-left edge reference requires:

c = (X - X_left_edge) / s_x - 0.5 r = (Y_top_edge - Y) / s_y - 0.5

For one-based center coordinates, add one after calculating the zero-based coordinates. Do not mix this indexing adjustment with the half-pixel center-to-edge adjustment.

An automatically chosen output extent can introduce translation even when the geometric mapping is correct. The related guide to undistortion scaling and cropping versus field of view explains a similar distinction between transformed geometry and the chosen output view.

4. Calculate one point from source to raster

Consider an illustrative calibration that maps source pixel coordinates into a plane measured in millimeters. These values describe an example application, not a camera specification.

H = [ 0.1 0 0 ] [ 0 0.1 0 ] [ 0.001 0 1 ] Source point: x = 300, y = 200 q = H × [300, 200, 1]^T = [30, 20, 1.3]^T X = 30 / 1.3 = 23.0769 mm Y = 20 / 1.3 = 15.3846 mm

Now define the output raster independently:

  • Upper-left pixel center: X0 = -10 mm and Y0 = 40 mm.
  • Physical spacing: s_x = s_y = 0.2 mm per pixel.
  • Physical Y increases upward; raster rows increase downward.
  • Output dimensions: 400 columns and 300 rows.

Apply the plane-to-raster mapping:

c = (23.0769 - (-10)) / 0.2 = 165.3846 r = (40 - 15.3846) / 0.2 = 123.0769

The transformed point belongs at approximately column 165.38, row 123.08 in zero-based continuous coordinates. It is not located at column 23.08, row 15.38: those numbers describe its physical plane position.

The composed calculation provides a useful cross-check:

B = [ 5 0 50 ] [ 0 -5 200 ] [ 0 0 1 ] B × q = [215, 160, 1.3]^T c = 215 / 1.3 = 165.3846 r = 160 / 1.3 = 123.0769

For a zero-based nearest-pixel lookup, rounding gives column 165 and row 123. For a one-based array, the corresponding nearest element is column 166 and row 124. Keep the fractional coordinates for interpolation, geometric calculations and overlays that support subpixel placement.

5. Verify the overlay before rounding

  1. Transform every reference point through the complete source-to-raster mapping. Draw the overlays on the exact output image produced by the warper.
  2. Check point identity, ordering and output bounds before converting coordinates into array indices.
  3. Compare independent check points throughout the image, including positions near the edges.

A useful verification sequence starts with the fitted points, but it must not end there. An exact four-point fit can reproduce those four correspondences while remaining sensitive to inaccurate point selection or poor geometry.

Measure residuals in the coordinate system relevant to the task:

Pixel residual = sqrt((c_pred - c_meas)^2 + (r_pred - r_meas)^2) For equal spacing s: Plane-equivalent residual = s × pixel residual

For example, a 0.6 pixel residual at 0.2 mm per pixel corresponds to 0.12 mm on the rectified plane. This conversion describes the residual; it is not a complete measurement uncertainty budget.

Check center-coordinate bounds against 0 through N_cols - 1 and 0 through N_rows - 1. Interpolation near image boundaries may still require a border-handling policy.

If an overlay is transposed or reflected despite correct numeric values, review coordinate indexing that prevents overlay errors. The same horizontal-versus-vertical distinction applies beyond code reading.

6. Diagnose the mismatch by its pattern

The error pattern often identifies the missing operation faster than repeatedly refitting the homography.

Observed mismatch Likely cause Practical test
Correct geometry, uniformly wrong size Physical coordinates treated as pixels, or incorrect output spacing Compare a known distance in plane units and output pixels
Correct size, constant translation Missing output-origin offset, crop offset or index-base adjustment Compare displacement vectors at several points
Vertical reflection Physical Y and raster row directions disagree Follow a point with increasing physical Y
Horizontal and vertical coordinates exchanged x/y confused with row/column Test an asymmetric point, such as column 40, row 120
Position-dependent distortion Wrong transform direction, missing normalization or incorrect calibration Inspect w and test held-out points
Consistent half-pixel displacement Pixel-edge and pixel-center references mixed Inspect the output reference definition
Points align centrally but drift near boundaries Lens distortion, weak calibration geometry or nonplanar features Check the original image and target geometry

Do not use a resize operation to hide a coordinate mismatch. Correct the physical-to-raster mapping, then address sampling separately. If rectification reduces local image detail, follow the guide to antialiasing when downsampling or warping images.

A point with a homogeneous denominator approaching zero lies near the mapping's projective horizon. Reject invalid coordinates before indexing. Because a homography matrix can be multiplied by an arbitrary nonzero scale, a denominator threshold needs a defined matrix normalization and numerical policy.

7. Match acquisition and processing to the task

A correct mapping cannot recover detail that was blurred, clipped or poorly illuminated during acquisition. Choose area scan cameras around the smallest feature, field of view, motion and interface requirements. The camera finder helps narrow those acquisition choices; output rectification size alone does not determine the required sensor resolution.

The LS-CMR-0166 is a USB3 area scan camera with a rolling shutter. If considering it for a planar station, evaluate motion during exposure and readout before relying on one geometric mapping across the frame.

Area scan cameras12 MP USB3 area scan camera, IMX226, 1/1.7" rolling shutter, 30 fps, 4000 × 3000 resolution (LS-CMR-0166)LS-CMR-0166
Sensor format
1/1.7"
Interface
USB3
Resolution
12 MP
Shutter
Rolling
$560.00View partBuild a system with it

For processing hardware, compare vision controllers against the acquisition interface, software runtime, memory demand and required cycle time. The MV-VC2140-128G40-1T is a candidate to assess against those requirements; verify compatibility rather than assuming a particular image-processing package is included.

Vision controllersHikrobot MV-VC2140-128G40-1T VC2100 Vision Controller, N97, 8GB+128G SSD+ 1THDDMV-VC2140-128G40-1T
LAN ports
3-4 LAN ports
USB 3 ports
2 USB 3 ports
Light outputs
4 built-in channels
Memory
8 GB
$1,679.00View partBuild a system with it

Benchmark acquisition, rectification, inspection and output communication together. A fast point transformation does not establish the throughput of the full raster-warping pipeline.

8. Check the limits before releasing the mapping

A single homography applies to one plane under the projective camera model. Raised features, varying part height and curved surfaces generally introduce errors that a planar mapping cannot remove. For planar motion guidance, the planar pick-and-place system selection guide explains why the working-plane assumption matters.

Lens distortion also needs separate treatment when significant. If calibration used undistorted points, apply the homography to points in that same undistorted coordinate system—not directly to the original distorted pixel coordinates.

Before release, record this short checklist with the inspection configuration:

  • [ ] Source and destination point definitions match the fitted transform direction.
  • [ ] Matrix layout and homogeneous normalization are documented.
  • [ ] Output origin identifies either pixel centers or pixel edges explicitly.
  • [ ] Pixel spacing, axis directions and image dimensions are fixed or retrieved at runtime.
  • [ ] Crop offsets, display scaling and index-base conversions are handled deliberately.
  • [ ] Independent check points meet the application's error budget across the working area.
  • [ ] Nonfinite, out-of-bounds and near-horizon coordinates are rejected before sampling.
  • [ ] Calibration is rechecked after changes to focus, camera pose or target-plane position.

For a new station, start with the camera configuration step. For help reviewing an existing mapping, send the source and destination point definitions, output reference settings and error measurements through applications support.

Questions

Why do transformed points have the right shape but the wrong scale?

Your transformation may produce physical plane coordinates while the displayed image uses raster coordinates. Convert using the output image's physical origin, distance per pixel and axis directions. If the homography was fitted directly to destination pixel coordinates, check for an unintended second scaling operation instead.

Should reference points use the forward or inverse homography?

Use the forward mapping when moving a source-image point into the destination coordinate system. Image warpers often use an inverse mapping internally to determine where each output pixel samples the source. That sampling strategy does not reverse the direction required for your point overlays.

Are four reference points enough for a reliable mapping?

Four correspondences can determine a homography when their geometry is suitable, but they provide little redundancy for detecting selection errors. Use well-distributed points and reserve additional positions for independent verification. Set the acceptance threshold from the inspection's error budget rather than the fit alone.

What causes a half-pixel shift in the warped-image overlay?

Check whether the output reference describes pixel centers or outer pixel edges. Those conventions differ by half a pixel along each axis. Also inspect interpolation and display conventions before modifying calibration points; changing the fit can conceal the mismatch without correcting its cause.

Can one homography correct objects at different heights?

A planar homography describes a single plane, not arbitrary surface height. Features above or below the calibration plane generally retain perspective-related position errors. If those errors exceed your tolerance, constrain the working height or use a calibrated three-dimensional measurement approach.