hypso.rgb.registration#

Registering HYPSO-2’s RGB camera image to the HSI capture (TODO 4e).

The camera image has no georeferencing. Registration is never run when an image is read (hypso.rgb.read_camera_image() only reads and demosaics); call register_camera() explicitly. It registers the image to the HSI capture’s own geolocation:

  1. the HSI product (georeferenced L1B or L1C, three bands near red, green and blue) is regridded onto a UTM map - a true map plane, unlike the pushbroom swath;

  2. SIFT keypoints are matched between that map and the (downsampled) camera image (scikit-image; ratio test and cross-check);

  3. RANSAC fits a homography from camera pixels to map coordinates - for a frame camera looking at nearly flat ground, the right model;

  4. the fit is checked: enough inliers, spread over enough of the camera image (a fit anchored in one corner is unreliable elsewhere), and a small enough residual. A capture that fails is left unregistered, with the reason.

On three test captures (Ariake, Venice, Annapolis) this gave residuals of about 190-220 m on a 150 m map, well below the HSI’s 876 x 108 m pixels, in about 40 s each (REFACTOR_PROGRESS.md ×83).

Examples

>>> from hypso.rgb import find_camera_image, read_camera_image
>>> camera = read_camera_image(find_camera_image(capture_dir))
>>> reg = register_camera(camera, l1c)
>>> geo = georeference_camera(camera, reg, l1c)       # per-pixel latitude/longitude

Classes#

Functions#

camera_lonlat(registration, shape)

Latitude and longitude (degrees, float32) of every camera pixel centre,

camera_to_hsi_pixels(registration, hsi, shape[, ...])

For every camera pixel, the nearest HSI pixel (line, sample) (-1

georeference_camera(camera, registration[, hsi])

The camera image in its own frame with per-pixel geolocation.

hsi_to_camera_pixels(registration, hsi, shape)

For every HSI pixel, the fractional camera (row, col) it falls on

register_camera(camera, hsi[, resolution, downsample, ...])

Register a camera image to an HSI capture.

Module Contents#

class hypso.rgb.registration.CameraRegistration[source]#

Result of register_camera().

attrs()[source]#

The registration as NetCDF attributes (provenance).

Return type:

dict

hypso.rgb.registration.camera_lonlat(registration, shape)[source]#

Latitude and longitude (degrees, float32) of every camera pixel centre, (rows, cols) arrays for an image of shape.

Parameters:

registration (CameraRegistration)

Return type:

tuple

hypso.rgb.registration.camera_to_hsi_pixels(registration, hsi, shape, max_distance_m=None)[source]#

For every camera pixel, the nearest HSI pixel (line, sample) (-1 where it is farther than max_distance_m, default the HSI’s resolution, i.e. outside the swath). Arrays of the camera’s shape.

Parameters:
Return type:

tuple

hypso.rgb.registration.georeference_camera(camera, registration, hsi=None)[source]#

The camera image in its own frame with per-pixel geolocation.

Parameters:
Returns:

R, G, B (y, x), latitude, longitude, optionally in_hsi_swath, and the registration in the attributes; writable with to_netcdf.

Return type:

xarray.Dataset

hypso.rgb.registration.hsi_to_camera_pixels(registration, hsi, shape)[source]#

For every HSI pixel, the fractional camera (row, col) it falls on (via the inverse homography; exact for the model), NaN outside the camera image of shape. Arrays of the HSI’s spatial shape.

Parameters:

registration (CameraRegistration)

Return type:

tuple

hypso.rgb.registration.register_camera(camera, hsi, resolution=150.0, downsample=0.25, min_inliers=30, min_coverage=0.25, max_rms_m=500.0, ratio=0.8, ransac_threshold_px=3.0, seed=0)[source]#

Register a camera image to an HSI capture.

Parameters:
  • camera (xarray.DataArray) – (y, x, channel) image from hypso.rgb.read_camera_image() (demosaiced, rotated as the ground processing does).

  • hsi (hypso.Product) – The capture’s georeferenced L1B or L1C product (needs geolocation).

  • resolution (float, default 150) – Pixel size (m) of the UTM map the camera is matched against.

  • downsample (float, default 0.25) – Scale of the camera image used for matching.

  • min_inliers (int) – Quality check: at least this many RANSAC inliers, covering at least this fraction of the camera image (convex hull), with at most this residual RMS (m).

  • min_coverage (float) – Quality check: at least this many RANSAC inliers, covering at least this fraction of the camera image (convex hull), with at most this residual RMS (m).

  • max_rms_m (float) – Quality check: at least this many RANSAC inliers, covering at least this fraction of the camera image (convex hull), with at most this residual RMS (m).

  • ratio (float, default 0.8) – Lowe’s ratio test for descriptor matching.

  • ransac_threshold_px (float, default 3) – RANSAC inlier threshold, in map pixels.

  • seed (int, default 0) – RANSAC random seed (reproducible results).

Return type:

CameraRegistration