Coordinate matrices#

Pixel-coordinate mesh-grid generator.

meshgrid(width: int, height: int) tuple[ndarray, ndarray][source]#

Coordinate arrays for an image

Parameters:
  • width (int) – image width in pixels

  • height (int) – image height in pixels

Returns:

coordinate arrays

Return type:

ndarray(H,W), ndarray(H,W)

Returns arrays U and V such that U[v,u] = u and V[v,u] = v.

Warning

The order of the indices used for U and V is the NumPy order. Toolbox functions generally use indices in the order u then v. In general these index arrays are passed to OpenCV or NumPy which assume this index ordering.

This can be used to define a 2D-function, for example:

>>> from machinevisiontoolbox import Image
>>> im = Image.Random((3, 4))
>>> U, V = im.meshgrid()
>>> U
array([[0, 1, 2],
       [0, 1, 2],
       [0, 1, 2],
       [0, 1, 2]])
>>> V
array([[0, 0, 0],
       [1, 1, 1],
       [2, 2, 2],
       [3, 3, 3]])
>>> print(f"coord (1,2), {U[2,1]}, {V[2,1]}")
coord (1,2), 1, 2
>>> Z = U**2 + V**2 # z=u^2 + v^2
>>> Z
array([[ 0,  1,  4],
       [ 1,  2,  5],
       [ 4,  5,  8],
       [ 9, 10, 13]])
Seealso:

Image.warp meshgrid

spherical_rotate(Phi: ndarray, Theta: ndarray, R: Any) tuple[ndarray, ndarray][source]#

Rotate coordinate matrices for a spherical image

Parameters:
  • Phi (ndarray(H,W)) – coordinate array for azimuth

  • Theta (ndarray(H,W)) – coordinate array for colatitude

  • R (spatialmath.pose3d.SO3) – an SO(3) rotation matrix

Returns:

transformed coordinate arrays

Return type:

ndarray(H,W), ndarray(H,W)

The coordinates of points in a spherical image can be represented by a pair of coordinate matrices that describe azimuth \(\phi \in [0, 2\pi]\) and colatitude \(\theta \in [0, \pi]\) for each pixel: Phi[u,v] \(=\phi_{u,v}\), Theta[u,v] \(=\theta_{u,v}\).

This function rotates the spherical image about its centre by transforming the coordinate arrays

\[\begin{split}\begin{pmatrix} \phi^\prime_{u,v} \\ \theta^\prime_{u,v} \end{pmatrix} = \mat{R} \begin{pmatrix} \phi_{u,v} \\ \theta_{u,v} \end{pmatrix}, \forall u, v\end{split}\]
Seealso:

spatialmath.pose3d.SO3