pointset

Point-set structures

Imaging data are sampled at points in space, and these points can be described by coordinates. These structures are designed to enable operations on sets of points, as opposed to the data sampled at those points.

Abstractly, a point set is any collection of points, but there are two types that warrant special consideration in the neuroimaging context: grids and meshes.

A grid is a collection of regularly-spaced points. The canonical examples of grids are the indices of voxels and their affine projection into a reference space.

A mesh is a collection of points and some structure that enables adjacent points to be identified. A triangular mesh in particular uses triplets of adjacent vertices to describe faces.

CoordinateArray(*args, **kwargs)

Grid(coordinates[, affine, homogeneous])

A regularly-spaced collection of coordinates

GridIndices(shape[, dtype])

Class for generating indices just-in-time

Pointset(coordinates[, affine, homogeneous])

A collection of points described by coordinates.

CoordinateArray

class nibabel.pointset.CoordinateArray(*args, **kwargs)

Bases: Protocol

__init__(*args, **kwargs)
ndim: int
shape: tuple[int, int]

Grid

class nibabel.pointset.Grid(coordinates: CoordinateArray, affine: ndarray | None = None, homogeneous: bool = False)

Bases: Pointset

A regularly-spaced collection of coordinates

This class provides factory methods for generating Pointsets from SpatialImages and generating masks from coordinate sets.

__init__(coordinates: CoordinateArray, affine: ndarray | None = None, homogeneous: bool = False)
classmethod from_image(spatialimage: SpatialImage) Self
classmethod from_mask(mask: SpatialImage) Self
to_mask(shape=None) SpatialImage

GridIndices

class nibabel.pointset.GridIndices(shape, dtype=None)

Bases: object

Class for generating indices just-in-time

__init__(shape, dtype=None)
dtype
gridshape
ndim = 2
shape

Pointset

class nibabel.pointset.Pointset(coordinates: CoordinateArray, affine: ndarray | None = None, homogeneous: bool = False)

Bases: object

A collection of points described by coordinates.

Parameters:
coordsarray-like

(N, n) array with N being points and columns their n-dimensional coordinates

affinenumpy.ndarray

Affine transform to be applied to coordinates array

homogeneousbool

Indicate whether the provided coordinates are homogeneous, i.e., homogeneous 3D coordinates have the form (x, y, z, 1)

__init__(coordinates: CoordinateArray, affine: ndarray | None = None, homogeneous: bool = False)
affine: ndarray
coordinates: CoordinateArray
property dim: int

The dimensionality of the space the coordinates are in

get_coords(*, as_homogeneous: bool = False)

Retrieve the coordinates

Parameters:
as_homogeneousbool

Return homogeneous coordinates if True, or Cartesian coordinates if False.

namestr

Select a particular coordinate system if more than one may exist. By default, None is equivalent to “world” and corresponds to an RAS+ coordinate system.

homogeneous: bool = False
property n_coords: int

Number of coordinates

Subclasses should override with more efficient implementations.