prysm.coordinates#

Coordinate conversions.

prysm.coordinates.optimize_xy_separable(x, y)#

Optimize performance for downstream operations.

Parameters:
  • x (numpy.ndarray) – 2D or 1D array

  • y (numpy.ndarray) – 2D or 1D array

Returns:

optimized arrays (x as 1D row, y as 1D column)

Return type:

x, y

Notes

If a calculation is separable in x and y, performing it on a meshgrid of x/y takes 2N^2 operations, for N= the linear dimension (the 2 being x and y). If the calculation is separable, this can be reduced to 2N by using numpy broadcast functionality and two 1D calculations.

prysm.coordinates.broadcast_1d_to_2d(x, y)#

Broadcast two (x,y) vectors to 2D.

Parameters:
  • x (numpy.ndarray) – ndarray of shape (n,)

  • y (numpy.ndarray) – ndarray of shape (m,)

Returns:

  • xx (numpy.ndarray) – ndarray of shape (m, n)

  • yy (numpy.ndarray) – ndarray of shape (m, n)

prysm.coordinates.cart_to_polar(x, y, vec_to_grid=True)#

Return the (rho,phi) coordinates of the (x,y) input points.

Parameters:
  • x (numpy.ndarray or number) – x coordinate

  • y (numpy.ndarray or number) – y coordinate

  • vec_to_grid (bool, optional) – if True, convert a vector (x,y) input to a grid (r,t) output

Returns:

  • rho (numpy.ndarray or number) – radial coordinate

  • phi (numpy.ndarray or number) – azimuthal coordinate

prysm.coordinates.polar_to_cart(rho, phi)#

Return the (x,y) coordinates of the (rho,phi) input points.

Parameters:
  • rho (numpy.ndarray or number) – radial coordinate

  • phi (numpy.ndarray or number) – azimuthal coordinate

Returns:

  • x (numpy.ndarray or number) – x coordinate

  • y (numpy.ndarray or number) – y coordinate

prysm.coordinates.uniform_cart_to_polar(x, y, data)#

Interpolate data uniformly sampled in cartesian coordinates to polar coordinates.

Parameters:
  • x (numpy.ndarray) – sorted 1D array of x sample pts

  • y (numpy.ndarray) – sorted 1D array of y sample pts

  • data (numpy.ndarray) – data sampled over the (x,y) coordinates

Returns:

  • rho (numpy.ndarray) – samples for interpolated values

  • phi (numpy.ndarray) – samples for interpolated values

  • f(rho,phi) (numpy.ndarray) – data uniformly sampled in (rho,phi)

prysm.coordinates.resample_2d(array, sample_pts, query_pts, kind='cubic')#

Resample 2D array to be sampled along queried points.

Parameters:
  • array (numpy.ndarray) – 2D array

  • sample_pts (tuple) – pair of numpy.ndarray objects that contain the x and y sample locations, each array should be 1D

  • query_pts (tuple) – points to interpolate onto, also 1D for each array

  • kind (str, {'linear', 'cubic', 'quintic'}) – kind / order of spline to use

Returns:

array resampled onto query_pts

Return type:

numpy.ndarray

prysm.coordinates.make_xy_grid(shape, *, dx=0, diameter=0, grid=True)#

Create an x, y grid from -1, 1 with n number of samples.

Parameters:
  • shape (int or tuple of int) – number of samples per dimension. If a scalar value, broadcast to both dimensions. Order is numpy axis convention, (row, col)

  • dx (float) – inter-sample spacing, ignored if diameter is provided

  • diameter (float) – diameter, clobbers dx if both given

  • grid (bool, optional) – if True, return meshgrid of x,y; else return 1D vectors (x, y)

Returns:

  • x (numpy.ndarray) – x grid

  • y (numpy.ndarray) – y grid

prysm.coordinates.make_rotation_matrix(zyx, radians=False)#

Build a rotation matrix.

Parameters:
  • zyx (tuple of float) – Z, Y, X rotation angles in that order

  • radians (bool, optional) – if True, abg are assumed to be radians. If False, abg are assumed to be degrees.

Returns:

3x3 rotation matrix

Return type:

numpy.ndarray

prysm.coordinates.promote_3d_transformation_to_homography(M)#

Convert a 3D transformation to 4D homography.

prysm.coordinates.drop_z_3d_transformation(M)#

Drop the Z entries of a 3D homography.

Drops the third row and third column of 4D transformation matrix M.

Parameters:

M (numpy.ndarray) – 4x4 ndarray for (x, y, z, w)

Returns:

3x3 array, (x, y, w)

Return type:

numpy.ndarray

prysm.coordinates.pack_xy_to_homographic_points(x, y)#

Pack (x, y) vectors into a vector of coordinates in homogeneous form.

Parameters:
  • x (numpy.ndarray) – x points

  • y (numpy.ndarray) – y points

Returns:

3xN array (x, y, w)

Return type:

numpy.ndarray

prysm.coordinates.solve_for_planar_homography(src, dst)#

Find the planar homography that transforms src -> dst.

Parameters:
  • src (numpy.ndarray) – (N, 2) shaped array

  • dst (numpy.ndarray) – (N, 2) shaped ndarray

Returns:

3x3 array containing the planar homography such that H * src = dst

Return type:

numpy.ndarray

prysm.coordinates.warp(img, xnew, ynew)#

Warp an image, via “pull” and not “push”.

Parameters:
  • img (numpy.ndarray) – 2D ndarray

  • xnew (numpy.ndarray) – 2D array containing x or column coordinates to look up in img

  • ynew (numpy.ndarray) – 2D array containing y or row coordinates to look up in img

Returns:

“pulled” warped image

Return type:

numpy.ndarray

Notes

The meaning of pull is that the indices of the output array indices are the output image coordinates, in other words xnew/ynew specify the coordinates in img, at which each output pixel is looked up

this is a dst->src mapping, aka “pull” in common image processing vernacular