fishdist.point_correction_and_analysis

finalize_analysis_and_save_db(source_points, corrected_spots, target_points, tags, order=['x', 'y', 'z'], MASK=True, output_filename=None)

Compute distances between corrected points and a target set, save results, and generate plots.

This function performs a per-tag (or global) analysis of 3D points: - Groups points by tags (if MASK=True). - Computes 3D distances between corrected_spots and target_points. - Saves per-tag results in a database with one row per point pair. - Generates dimension-wise plots showing alignment before and after correction.

Parameters:
  • source_points (np.ndarray of shape (N, 3)) –

    Original points before correction.

  • corrected_spots (np.ndarray of shape (N, 3)) –

    Points after linear correction.

  • target_points (np.ndarray of shape (N, 3)) –

    Target points used for alignment.

  • tags (np.ndarray of shape (N,)) –

    Labels used to group points for per-tag analysis.

  • order (list of str, default: ['x', 'y', 'z'] ) –

    Dimension names for database columns. Default is ['x','y','z'].

  • MASK (bool, default: True ) –

    If True, perform per-tag analysis; otherwise, process all points together. Default is True.

  • output_filename (str, default: None ) –

    Optional output filename for the database.

Returns:
  • None

    Results are saved to per-tag databases, and plots are generated; no values are returned.

Example
import numpy as np

source = np.array([[1,2,3],[4,5,6]])
corrected = np.array([[1.1,2.0,2.9],[3.9,5.1,6.0]])
target = np.array([[1.0,2.0,3.0],[4.0,5.0,6.0]])
tags = np.array(['A','B'])

finalize_analysis_and_save_db(source, corrected, target, tags)

perform_correction(source_points, target_points, recenter=True)

Apply linear bias correction to 3D points by aligning one set of points to another.

This function performs a per-axis linear correction to reduce systematic biases between two sets of corresponding 3D points obtained from the same image. One set (source_points) is aligned to the other (target_points) using slope correction and optional recentering.

The procedure is as follows: 1. Compute the difference between each point in source_points and the corresponding point in target_points. 2. Subtract the mean difference to center the distribution at zero. 3. Fit a linear regression per axis to estimate scaling (slope) biases. 4. Adjust source_points using the per-axis slopes. 5. Optionally remove any residual global translation to recenter the corrected points.

Parameters:
  • source_points (np.ndarray of shape (N, 3)) –

    3D coordinates of the points to be corrected.

  • target_points (np.ndarray of shape (N, 3)) –

    3D coordinates of the points used for alignment.

  • recenter (bool, default: True ) –

    If True, subtracts residual translation to recenter the corrected points. Default is True.

Returns:
  • np.ndarray of shape (N, 3): Corrected 3D points after linear slope correction

  • and optional recentering.

Example
import numpy as np

source = np.array([[1.0, 2.0, 3.0],
                   [2.0, 3.0, 4.0]])
target = np.array([[0.9, 2.1, 2.9],
                   [2.1, 2.9, 4.1]])

corrected = perform_correction(source, target)
print(corrected)