tomosipo.geometry.volume module

class tomosipo.geometry.volume.VolumeGeometry(shape=(1, 1, 1), pos=0, size=None)[source]

Bases: object

A volume geometry

A VolumeGeometry describes a 3D axis-aligned cuboid that is divided into voxels.

The number of voxels in each dimension determine the object’s shape. The voxel size is thus determined by the size of the object and its shape.

A VolumeGeometry cannot move in time and cannot be arbitrarily oriented. To obtain a moving volume geometry, convert the object to a vector representation using .to_vec().

property corners

Returns a vector with the corners of the volume

For consistency with the volume vector geometry, the returned array has leading dimension 1.

Returns:

np.array Array with shape (1, 8, 3), describing the 8 corners of volume orientation in (Z, Y, X)-coordinates.

Return type:

np.array

property extent

The extent of the volume in each dimension

Returns:

((min_z, max_z), (min_y, max_y), (min_x, max_x))

Return type:

((scalar, scalar), (scalar, scalar), (scalar, scalar))

property lower_left_corner

Returns a vector with the positions of the lower-left corner the object

For consistency with the volume vector geometry, the returned array has leading dimension 1.

Returns:

np.array Array with shape (1, 3), describing the position of the lower-left corner of the volume in (Z, Y, X)-coordinates.

Return type:

np.array

multiply(scale)[source]

Scales the volume including its position.

Does not affect the shape (voxels) of the volume. Use reshape to change the shape.

Parameters:

scale – tuple or np.float By how much to scale the volume.

Returns:

Return type:

property num_steps

The number of orientations and positions of this volume

A VolumeGeometry always has only a single step.

property pos
reshape(new_shape)[source]

Reshape the VolumeGeometry

Parameters:

new_shapeint or (int, int, int) The new shape that the volume must have

Returns:

A new volume with the required shape

Return type:

VolumeGeometry

scale(scale)[source]

Scales the volume around its center.

The position of the volume does not change. This transformation does not affect the shape (voxels) of the volume. Use reshape to change the shape.

Parameters:

scale – tuple or np.float By how much to scale the volume.

Returns:

Return type:

property shape
property size

Returns the absolute size of the volume

Returns:

the size in each dimension of the volume

Return type:

(scalar, scalar, scalar)

property sizes

Returns the absolute sizes of the volume

For consistency with vector geometries, sizes is an array with shape (1, 3).

Returns:

a numpy array of shape (1, 3) describing the size of the object.

Return type:

to_astra()[source]

Return an Astra volume geometry.

Returns:

Return type:

to_vec()[source]

Returns a vector representation of the volume

Returns:

Return type:

VolumeVectorGeometry

translate(t)[source]
property u
untranslate(ts)[source]
property v
property voxel_size

The voxel size of the volume

Returns:

the size in each dimension of the volume

Return type:

(scalar, scalar, scalar)

property voxel_sizes

The voxel sizes of the volume

Note: For consistency with vector geometries, voxel_sizes

is an array with shape (1, 3).

Returns:

a numpy array of shape (1, 3) describing the voxel size of the volume.

Return type:

np.array

property w
with_voxel_size(voxel_size)[source]

Returns a new volume with the specified voxel size

When the voxel_size does not cleanly divide the size of the volume, a volume is returned that is - centered on the origin; - fits inside the original volume;

Parameters:

voxel_size

Returns:

Return type:

tomosipo.geometry.volume.from_astra(astra_vol_geom)[source]

Converts an ASTRA 3D volume geometry to a VolumeGeometry

Parameters:

astra_vol_geomdict A dictionary created by astra.create_vol_geom that describes a 3D volume geometry.

Returns:

a tomosipo volume geometry

Return type:

VolumeGeometry

tomosipo.geometry.volume.is_volume(g)[source]

Determine if a geometry is a volume geometry

The object can be a fixed volume geometry or a vector volume geometry.

Parameters:

g – a geometry object

Returns:

True if g is a volume geometry

Return type:

bool

tomosipo.geometry.volume.random_volume()[source]

Generates a random volume geometry

Returns:

a random volume geometry

Return type:

VolumeGeometry

tomosipo.geometry.volume.volume(*, shape=(1, 1, 1), pos=None, size=None, extent=None)[source]

Create an axis-aligned volume geometry

A VolumeGeometry is an axis-aligned cuboid centered on pos.

You may provide a combination of arguments to create a new volume geometry:

  • shape (size will equal shape)

  • shape and pos (size will equal shape)

  • shape and size (volume will be centered on the origin)

  • shape, pos, and size.

  • shape and extent

Parameters:
  • shape (int | Tuple[int, int, int] | Iterable[int]) – Shape of the voxel grid underlying the volume.

  • pos (float | Collection[float]) – Position of the center of the volume. By default, the volume is placed on the origin.

  • size (float | Tuple[float, float, float] | Iterable[float]) – The size of the volume in physical units. This determines the shape. If not provided, the size will equal the shape.

  • extent (Tuple[float, float] | Tuple[Tuple[float, float], Tuple[float, float], Tuple[float, float]]) – The minimal and maximal value of the volume in the (z, y, x) coordinate space. If only one minimal and maximal value is provided, then it is applied to all coordinates.

Returns:

An axis-aligned volume geometry.

Return type:

VolumeGeometry

Examples

>>> ts.volume()
ts.volume(
    shape=(1, 1, 1),
    pos=(0.0, 0.0, 0.0),
    size=(1.0, 1.0, 1.0),
)
>>> ts.volume(shape=1, size=2.0, pos=(1, 1, 1))
ts.volume(
    shape=(1, 1, 1),
    pos=(1.0, 1.0, 1.0),
    size=(2.0, 2.0, 2.0),
)