skshapes.Mask

class skshapes.Mask(*, indices=None, flat_indices=None, shape, device=None)

Bases: GridStructure

A D-dimensional mask over a voxel grid.

A Mask object can be created from torch.Tensors indicating indices of the voxels contained in the mask. The shape of the mask must also be provided.

Masks are manipulated like sets of voxels. They are also used to select only a subset of the values of an image.

Parameters:
  • indices (Int64[Tensor, '*_'] | None) – The indices of the voxels that are included in the mask. It should be a tensor of shape (N,D) where N is the number of voxels present in the mask.

  • shape (tuple[int, ...]) – The shape of the original grid on which the mask is defined.

  • device (str | device | None) – The device on which the shape is stored (e.g. "cpu" or "cuda"). If None it is inferred from the input.

__init__(*, indices=None, flat_indices=None, shape, device=None)

Methods

__init__(*[, indices, flat_indices, device])

connected_components(*, offsets)

convolution(*, offsets[, kernel])

copy()

difference(other)

intersection(other)

masked_convolution(*[, mask, weights, ...])

plot([backend])

symmetric_difference(other)

to(device)

Copy the instance onto a given device.

to_image(*[, dtype, device])

to_sparseimage(*[, dtype, device])

union(other)

Attributes

device

Device getter.

dim

The dimension D of the D-dimensional grid.

indices

The indices of the voxels that are included in the mask, expressed as a tensor.

n_points

The number of voxels present in the mask.

numel

The total number of voxels in the image.

shape

The shape of the D-dimensional grid.

values

The mask expressed as a tensor.

property indices: Tensor

The indices of the voxels that are included in the mask, expressed as a tensor.

property n_points: int

The number of voxels present in the mask.

property values: Tensor

The mask expressed as a tensor.