phathom.registration package

Submodules

phathom.registration.pcloud module

The pcloud module contains functions related to point cloud generation and matching

phathom.registration.pcloud.augment(pts)
phathom.registration.pcloud.augmented_matrix(pts)
phathom.registration.pcloud.average_residual(pts1, pts2)
phathom.registration.pcloud.build_neighbors(X, n_neighbors=1, radius=1.0, algorithm='auto', n_jobs=1)

Instantiate a NearestNeighbors classifier and fit it to points

Parameters:
  • X (ndarray) – (N, D) array of D-dimensional data points
  • n_neighbors (int) – number of neighbors to use for kneighbor queries by default
  • radius (float) – range of parameter space to use for radius_neighbor queries by default
  • algorithm ({'auto', 'ball_tree', 'kd_tree', 'brute'}, optional) – algorithm used to calculate the nearest neighbors
  • n_jobs (int) – number of parallel jobs used to run for kneighbors searches. -1 uses all CPU cores.
Returns:

nbrs – NearestNeighbors object containing a built kd-tree

Return type:

NearestNeighbors

phathom.registration.pcloud.calculate_image_dimensions(shape, voxel_dims)
phathom.registration.pcloud.check_distance(dists, max_dist)

Check whether or not dists are less than max_dist

Parameters:
  • dists (ndarray) – (N,) array with input distances to check
  • max_dist (float) – maximum Euclidean distance for a candidate point to be considered close
Returns:

close – tuple of coordinate arrays for those points that are close.

Return type:

tuple

phathom.registration.pcloud.check_prominence(prom, threshold)

Check which prominences in prom are below a given threshold

Parameters:
  • prom (ndarray) – (N,) array of prominences
  • threshold (float) – maximum prominence value for a point to be considered “prominent”
Returns:

prominent – a tuple of coordinate arrays for the found prominent points

Return type:

tuple

phathom.registration.pcloud.coord_mapping(fixed_coords, c, matches_stationary, smoothing)

Apply 3D thin-plate spline mapping to fixed_coords.

The RBF keypoints are given in matches_stationary. Smoothing is a surface energy regularization parameter.

Parameters:
  • fixed_coords (ndarray) – (N, 3) array of points to warp
  • c (ndarray) – (M, 3) array of spline coefficients for z, y, and x axes
  • matches_stationary (ndarray) – (M, 3) array of keypoint coordinates
  • smoothing (float) – surface energy regularization parameter
Returns:

moving_coords – (N, 3) array of warped points

Return type:

ndarray

phathom.registration.pcloud.estimate_affine(batch_stationary, batch_moving, mode='ransac', min_samples=4, residual_threshold=None)

Estimate an affine transformation from fixed to moving points

Parameters:
  • batch_stationary (array) – array (N, 3) of matched fixed points
  • batch_moving (array) – array (N, 3) of matched moving points
  • mode (str) – Either ‘ransac’ or ‘lstsq’
  • min_samples (int) – int for the number of samples to use for RANSAC
  • residual_threshold (float) – float for the inlier-outlier cutoff residual
Returns:

model – ransac or affine matrix

Return type:

linear_model or array

phathom.registration.pcloud.feature_matching(feat_fixed, feat_moving, max_fdist=None, prom_thresh=None, algorithm='auto', n_jobs=-1)

Find moving point matches for all fixed points based on feature distance and prominence

Parameters:
  • feat_fixed (ndarray) – (N, D) array of D dimensional features for N fixed points
  • feat_moving (ndarray) – (M, D) array of D dimensional features for M moving points
  • max_fdist (float) – maximum allowed Euclidean distance in feature space to be considered a match
  • prom_thresh (float) – maximum allowed prominence ratio to be considered a match
  • algorithm ({'auto', 'ball_tree', 'kd_tree', 'brute'}, optional) – algorithm used to compute the nearest neighbors
  • n_jobs (int, optional) – number of parallel processes to use for kneighbors queries. Default uses the number of CPU cores
Returns:

  • idx_fixed (ndarray) – indices of fixed point matches. Empty if no matches are found
  • idx_moving (ndarray) – indices of moving point matches. Empty if no matches are found

phathom.registration.pcloud.flatten(pts)
phathom.registration.pcloud.generate_3d_image(size, center, sigma)
phathom.registration.pcloud.geometric_features(pts, nb_workers)

Extract the geometric hash for each point in a point cloud

Parameters:
  • pts (ndarray) – 2D array (N, 3) of points
  • nb_workers (int) – number of processes to calculate features in parallel
Returns:

features – (N, 6) array of geometric features

Return type:

ndarray

phathom.registration.pcloud.geometric_hash(center, vectors)

Calculates the geometric hash of a set of vectors around center

The geometric hash is a rotation invariant descriptor of the relative positions of the vectors with respect to center

Parameters:
  • center (ndarray) – coorindates of the center point
  • vectors (ndarray) – a (3, 3) array of neighboring point coordinates as rows
Returns:

features – a (6,) array of the geometric hashing result

Return type:

array

phathom.registration.pcloud.get_chunk_index(chunk_shape, chunk_idx)
phathom.registration.pcloud.get_nb_chunks(img)
phathom.registration.pcloud.index_to_um_tup(pts, voxel_dims)
phathom.registration.pcloud.main()
phathom.registration.pcloud.ncc(fixed, registered)

Calculate the normalized cross-correlation between two images

Parameters:
  • fixed (array) – array of first image to be compared
  • registered (array) – array of second image to be compared
phathom.registration.pcloud.pcloud_density_registration(fixed_img, moving_img, fixed_pts, moving_pts, bin_size_um, sigma_density, niter, voxel_dims)
phathom.registration.pcloud.pcloud_hist(pts, dimensions, bin_size)

Compute the histogram of a 3D point cloud

Parameters:
  • pts (array) – 2D array (N, D) of points
  • dimensions (tuple or array) – overall dimensions of the histogram (image bounds)
  • bin_size (float) – the physical dimension of each bin
phathom.registration.pcloud.prominence(d1, d2)

Calculate the prominence of set of points based on the two nearest neighbor distances

Prominence is defined as the ratio of nearest and 2nd nearest neighbor distances. Lower prominence values indicate nearest neighbors that “stand out” more. This function doesn’t verify that all d1 values are less than or equal to d2 values.

Parameters:
  • d1 (ndarray) – (N,) array containing the distances of the nearest neighbors
  • d2 (ndarray) – (N,) array containing the distance of the 2nd-nearest neighbors
Returns:

prom – (N,) array of calculated prominences for each point

Return type:

ndarray

phathom.registration.pcloud.radius_matching(points_fixed, points_moving, feat_fixed, feat_moving, radius, nb_workers=None, batch_size=None, matching_kwargs=None)

Match fixed points to moving points within a search radius

Parameters:
  • points_fixed (ndarray) – (N, D) array of the D spatial coordinates of N fixed points
  • points_moving (ndarray) – (M, D) array of the D spatial coordinates of M fixed points
  • feat_fixed (ndarray) – (N, F) array of F features for N fixed points
  • feat_moving (ndarray) – (M, F) array of F features for M moving points
  • radius (float) – maximum distance to search for moving match around each fixed point
  • nb_workers (int, optional) – number of processes to perform neighborhood search in parallel. Defaults to cpu_count()
  • batch_size (int, optional) – number of fixed points to consider at a time. Defaults to N // nb_workers
  • matching_kwargs (dict, optional) – keyword arguments to pass to feature_matching for filtering the candidate matches. The n_jobs kwarg will be respected by each neighborhood worker, so the default is 1.
Returns:

  • idx_fixed (ndarray) – indices of fixed point matches. Empty if no matches are found
  • idx_moving (ndarray) – indices of moving point matches. Empty if no matches are found

phathom.registration.pcloud.register_pts(pts, linear_model)
phathom.registration.pcloud.rigid_transformation(t, r, pts)

Apply rotation and translation (rigid transformtion) to a set of points

Parameters:
  • t (array) – 1D array representing the translation vector
  • r (array) – 2D array representing the rotation matrix
phathom.registration.pcloud.rotate(points, thetas, center=None)

Rotate points in 3D

Parameters:
  • points (tuple) – tuple of coordiante arrays for points to be rotated
  • thetas (array-like) – angles (in radians) to rotate the points for each axis
  • center (array-like) – coordinates for the center of rotation
Returns:

rotated – tuple of coordinate arrays for rotated points

Return type:

tuple

phathom.registration.pcloud.rotation_matrix(thetas)

Create a 3D rotation matrix given rotations about each axis

Parameters:thetas (array-like) – array-like with 3 rotation angles in radians
phathom.registration.pcloud.unflatten(pts_vector)

phathom.registration.registration module

Module contents