skshapes.Image
- class skshapes.Image(values, *, dim=None, dtype=None, device=None)
Bases:
ImageStructureA D-dimensional grid, with a K-dimensional value associated to each of its voxels.
An
Imageobject 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),valuesshould 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 thatvalues[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 whenimageis 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
deviceDevice getter.
dimThe dimension D of the D-dimensional grid.
dtypeDtype getter.
full_shapeThe full shape of the image.
numelThe total number of voxels in the image.
shapeThe shape of the D-dimensional grid.
The image values expressed as a tensor.
values_dimThe dimension of the value tensors
values_shapeFor 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.