skshapes.Image

class skshapes.Image(values, *, dim=None, dtype=None, device=None)

Bases: ImageStructure

A D-dimensional grid, with a K-dimensional value associated to each of its voxels.

An Image object can be created from torch.Tensors.

Parameters:
  • values (Float32[Tensor, '*_'] | Int64[Tensor, '*_']) – The value of the image at each pixel/voxel. For “classical” images (with scalar values at each pixel), values should be a tensor of shape (X_1,...,X_D). For vector/matricial images (with multidimensional values at each pixel), the tensor should be of shape (X_1,...,X_D,V_1,...,V_K) such that values[x1,...,xD] gives the value of the image at voxel (x1,...,xD). In this case, the dimension of the image should be provided.

  • dim (int | None) – The dimension of the image. It should be only provided when image is multivalued and values is a torch Tensor.

  • dtype (dtype | None) – The data type of the image values. If None it is inferred from the input.

  • 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.

Examples

import skshapes as sks
import torch

image = sks.Image(values=torch.ones(size=(3, 5, 7)))
print(image.shape)
(3, 5, 7)
image = sks.Image(values=torch.ones(size=(3, 5, 7, 2, 2)), dim=3)
print(image.shape)
(3, 5, 7)
print(image.dim)
3
print(image.values_shape)
(2, 2)
print(image.values_dim)
2
__init__(values, *, dim=None, dtype=None, device=None)

Methods

__init__(values, *[, dim, dtype, device])

apply_pointwise(operation[, other])

Apply a function at each point of the image.

apply_reduction(operation, *[, requires_count])

copy()

histogram(bins)

!-> cpu

isin(test_elements)

max()

min()

plot([backend])

to(device)

Copy the instance onto a given device.

unique()

Return the unique values pf the image.

values_at(*, query_indices[, flat_query_indices])

Get the values of the image at the indices specified in input.

zeros(shape, *[, values_shape, dtype, device])

Attributes

device

Device getter.

dim

The dimension D of the D-dimensional grid.

dtype

Dtype getter.

full_shape

The full shape of the image.

numel

The total number of voxels in the image.

shape

The shape of the D-dimensional grid.

values

The image values expressed as a tensor.

values_dim

The dimension of the value tensors

values_shape

For tensor-valued images, the shape of the value tensor.

unique()

Return the unique values pf the image.

Returns:

The Q unique values of the image, stored in a (Q,V_1,...,V_K) Tensor.

Return type:

torch.Tensor

property values: Float32[Tensor, '*_'] | Int64[Tensor, '*_']

The image values expressed as a tensor.