Template

Template images.

Templates are reference arrays used to resample images, as their shape and voxel-size are used as references.

timagetk.algorithms.template.iso_template(image, method='max')[source]

Return the isometric template of the image.

Parameters:
  • image (timagetk.SpatialImage or timagetk.LabelledImage) – The image to resample.

  • method ({'min', 'max', float}, optional) – Change voxelsize to ‘min’, ‘max’ (default) of original voxelsize or to a given value.

Returns:

timagetk.SpatialImage – Isometric SpatialImage template.

Examples

>>> from timagetk.algorithms.template import iso_template
>>> from timagetk.io import imread
>>> from timagetk.io.util import shared_dataset
>>> # Loading an example grayscale image and show info:
>>> img = imread(shared_dataset("p58")[0])
>>> print(f"Original image ZYX shape: {img.get_shape()}")
Original image ZYX shape: [59, 460, 460]
>>> print(f"Original image ZYX voxelsize: {img.get_voxelsize()}")
Original image ZYX voxelsize: [1.0, 0.20031953747828882, 0.20031953747828882]
>>> # Example #1 - Compute the smallest isometric template w.r.t. voxel-size (smallest shape, maximal voxel-size)
>>> small_template = iso_template(img, method="max")
>>> print(f"Small template image ZYX shape: {small_template.get_shape()}")
Small template image ZYX shape: [59, 92, 92]
>>> print(f"Small template image ZYX voxelsize: {small_template.get_voxelsize()}")
Small template image ZYX voxelsize: [1.0, 1.0, 1.0]
>>> # Example #2 - Compute the largest isometric template w.r.t. voxel-size (biggest shape, minimal voxel-size)
>>> large_template = iso_template(img, method="min")
>>> print(f"Large template image ZYX shape: {large_template.get_shape()}")
Large template image ZYX shape: [295, 460, 460]
>>> print(f"Large template image ZYX voxelsize: {large_template.get_voxelsize()}")
Large template image ZYX voxelsize: [0.20031953747828882, 0.20031953747828882, 0.20031953747828882]
>>> # Example #3 - Compute an isometric template to a given voxel-size:
>>> template = iso_template(img, method=0.5)
>>> print(f"Template image ZYX shape: {template.get_shape()}")
Template image ZYX shape: [116, 184, 184]
>>> print(f"Template image ZYX voxelsize: {template.get_voxelsize()}")
Template image ZYX voxelsize: [0.5, 0.5, 0.5]