linumpy.geometry.galvo#

Galvanometric XY shift detection and correction.

Functions#

detect_galvo_band_in_tile(tile_aip[, min_drop_ratio])

Detect a galvo return dark band in the AIP of a single assembled mosaic tile.

detect_galvo_shift(aip[, n_pixel_return])

Detect galvo shift artifact in an average intensity projection.

detect_galvo_for_slice(tiles, n_extra[, threshold, ...])

Detect galvo shift for a slice by sampling multiple tiles.

fix_galvo_shift(vol[, shift, axis])

Apply circular shift to move galvo return region to edge of volume.

Module Contents#

linumpy.geometry.galvo.detect_galvo_band_in_tile(tile_aip, min_drop_ratio=0.4)[source]#

Detect a galvo return dark band in the AIP of a single assembled mosaic tile.

Companion to detect_galvo_shift() for use when only the assembled OME-Zarr mosaic is available and the raw .bin tiles no longer exist. Each zarr chunk corresponds to one OCT tile (the zarr chunk shape equals the tile size), so this function can be run per chunk to detect and characterise any unfixed galvo artifact.

Parameters:
  • tile_aip (np.ndarray) – 2-D average intensity projection of a single tile, shape (n_alines, n_bscans).

  • min_drop_ratio (float) – Minimum relative intensity drop compared to the surrounding tissue baseline to be classified as a dark band. Default 0.40 (40 % drop).

Returns:

(band_start, band_width, confidence) – pixel coordinates of the detected band within the tile (along the A-line axis) and a confidence score in [0, 1]. Returns (0, 0, 0.0) when no band is detected.

Return type:

tuple

linumpy.geometry.galvo.detect_galvo_shift(aip, n_pixel_return=40)[source]#

Detect galvo shift artifact in an average intensity projection.

The galvo return region creates a dark horizontal band in OCT data. This function locates the band by finding gradient pairs separated by n_pixel_return pixels, then validates using dark band consistency.

Parameters:
  • aip (np.ndarray) – Average intensity projection of shape (n_alines, n_bscans).

  • n_pixel_return (int) – Width of galvo return region in pixels (from acquisition metadata).

Returns:

(shift, confidence) where shift is the circular shift needed to move the galvo region to the edge, and confidence (0-1) indicates detection reliability. Apply fix when confidence >= 0.5.

Return type:

tuple

linumpy.geometry.galvo.detect_galvo_for_slice(tiles, n_extra, threshold=0.6, n_samples=5, axial_resolution=None, min_intensity=20.0)[source]#

Detect galvo shift for a slice by sampling multiple tiles.

Parameters:
  • tiles (list) – List of tile paths for the slice.

  • n_extra (int) – Number of extra A-lines (galvo return pixels) from acquisition metadata.

  • threshold (float) – Confidence threshold for applying fix (default: 0.6).

  • n_samples (int) – Maximum number of tiles to sample (default: 5).

  • axial_resolution (float, optional) – Axial resolution for OCT loading.

  • min_intensity (float) – Minimum mean intensity for a tile to be considered valid.

Returns:

(shift, confidence) where shift is 0 if confidence < threshold.

Return type:

tuple

linumpy.geometry.galvo.fix_galvo_shift(vol, shift=0, axis=1)[source]#

Apply circular shift to move galvo return region to edge of volume.

Parameters:
  • vol (np.ndarray) – OCT volume data.

  • shift (int) – Number of pixels to shift.

  • axis (int) – Axis along which to shift (default: 1 for A-line axis).

Returns:

Shifted volume. Crop with vol[:, :n_alines, :] to remove galvo region.

Return type:

np.ndarray