src.utils.homography module

src.utils.homography module#

src.utils.homography.calc_homography_mat(src, dst)[source]#

Compute the homography matrix H such that dst ~ H * src.

Solved with the Direct Linear Transform (DLT) algorithm and SVD. Commonly used to map image pixel coordinates into real-world coordinates.

Parameters:
  • src (np.ndarray) – Four source-plane points. Shape: (4, 2)

  • dst (np.ndarray) – Four corresponding target-plane points. Shape: (4, 2)

Returns:

The computed 3x3 homography matrix.

Shape: (3, 3)

Return type:

np.ndarray

Raises:

ValueError – If the input points are not shaped (4, 2).

src.utils.homography.affine_transformation(src, H)[source]#

Transform point set src with homography matrix H.

Converts 2D points to homogeneous coordinates, applies the matrix multiplication, then converts back to Cartesian coordinates.

Parameters:
  • src (np.ndarray) – Source points to transform. Shape: (…, 2) where the last dimension is (x, y).

  • H (np.ndarray) – Homography matrix. Shape: (3, 3)

Returns:

Transformed target points with the same shape as input.

Return type:

np.ndarray

src.utils.homography.image_to_world(src, H, dot_per_meter=5)[source]#

Transform image data into world coordinates and resample it onto a regular grid.

The function first maps image pixel coordinates into world coordinates, then uses bilinear interpolation via griddata to resample irregular points onto a grid with uniform physical spacing.

Parameters:
  • src (np.ndarray) – Input image data, e.g. a semantic map mask. Shape: (W, H, …), where the first dimension is x and the second is y.

  • H (np.ndarray) – Transformation matrix from image coordinates to world coordinates. Shape: (3, 3)

  • dot_per_meter (int, optional) – Output grid resolution in samples per meter.

Returns:

A tuple containing:
  • map (np.ndarray): Resampled rasterized map.

  • xmin (float): Lower x bound in world coordinates.

  • xmax (float): Upper x bound in world coordinates.

  • ymin (float): Lower y bound in world coordinates.

  • ymax (float): Upper y bound in world coordinates.

Return type:

tuple