VT-Python wrapper

vtImage wrapper

Add documentation to vt.vtImage class.

timagetk.third_party.vt_image.spatial_to_vt_image(sp_img)[source]

Convert a SpatialImage in a vtImage.

Parameters:

sp_img (timagetk.SpatialImage) – The SpatialImage object to convert as vtImage.

Returns:

vt.vtImage – The converted image.

Examples

>>> from timagetk.third_party.vt_image import vtImage
>>> from timagetk.third_party.vt_image import spatial_to_vt_image
>>> from timagetk.array_util import random_spatial_image
>>> # Initialize a random (uint8) 3D SpatialImage:
>>> img = random_spatial_image((3, 4, 5),voxelsize=[1., 0.51, 0.5],dtype='uint8')
>>> vt_im = spatial_to_vt_image(img)
>>> isinstance(vt_im, vtImage)
True
>>> import vt
>>> isinstance(vt_im, vt.vtImage)
True
class timagetk.third_party.vt_image.vtImage(image=None, voxelsize=None, **kwargs)[source]

Simple wrapper to add documentation to vt.vtImage.

Examples

>>> from timagetk.third_party.vt_image import vtImage
>>> from timagetk.array_util import random_array
>>> from timagetk.io.util import shared_data
>>> # EXAMPLE #1 - Initialize an EMPTY `vtImage` object:
>>> im = vtImage()
>>> # EXAMPLE #2 - Initialize from an array and a list of voxelsize:
>>> arr = random_array([3, 4, 5], dtype='uint8')
>>> arr.shape
[3, 4, 5]
>>> im = vtImage(arr, [0.31, 0.32, 0.33])
>>> im.shape()  # access image shape
[30, 40, 50]
>>> im.spacing()  # access image voxelsize
[0.3100000023841858, 0.3199999928474426, 0.33000001311302185]
>>> im.copy_to_array()  # return a copy of the numpy array
>>> # EXAMPLE #3 - Initialize from a shared image:
>>> im = vtImage(shared_data('p58-t0-a0.lsm', 'p58'))
>>> im.print()
image information:
  - dimensions [x y z] = 460 460 59
  - voxel size [x y z] = 0.200320 0.200320 1.000000
  - image type is: UCHAR
  - image geometry is: _BAL_HOMOTHETY_GEOMETRY_
  - conversion matrix voxel to real:
   0.200319543480873    0.000000000000000    0.000000000000000    0.000000000000000
   0.000000000000000    0.200319543480873    0.000000000000000    0.000000000000000
   0.000000000000000    0.000000000000000    1.000000000000000    0.000000000000000
   0.000000000000000    0.000000000000000    0.000000000000000    1.000000000000000
  - conversion matrix real to voxel:
   4.992024156122749    0.000000000000000    0.000000000000000    0.000000000000000
   0.000000000000000    4.992024156122749    0.000000000000000    0.000000000000000
   0.000000000000000    0.000000000000000    1.000000000000000    0.000000000000000
   0.000000000000000    0.000000000000000    0.000000000000000    1.000000000000000
  - qform_code: 0
  - sform_code: 0
  - min = 10 , max = 255 , mean = 52.492456
copy_to_array()[source]

Return the image array as a numpy.ndarray.

See also

self.to_array

Returns:

numpy.ndarray – The image array

set_spacing(spacing)[source]

Set the image voxelsize.

Parameters:

spacing (list of int) – A (Z)YX list of voxelsize.

Notes

This changes the image physical size!

Examples

>>> from timagetk.third_party.vt_image import vtImage
>>> from timagetk.array_util import random_array
>>> # - Initialize from generated random numpy array:
>>> arr = random_array((30, 40, 50), dtype='uint8')
>>> im = vtImage(arr)
>>> im.spacing()
[1., 1., 1.]
>>> im.set_spacing([0.31, 0.62, 0.63])
>>> im.spacing()
[0.3100000023841858, 0.6200000047683716, 0.6299999952316284]
shape()[source]

Return the image shape.

Returns:

list of int – (Z)YX sorted shape values.

spacing()[source]

Return the image voxelsize.

Returns:

list of float – (Z)YX sorted voxelsize values.

to_array()[source]

Return the image array as a numpy.ndarray and destroy the object.

See also

self.to_array

Returns:

numpy.ndarray – The image array

v_dim()[source]

Return the number of vector components in image.

If 1, it is a regular image. If 3, it is a non-liner transformation matrix.

Returns:

int – The number of vector components in the image.

write(filename)[source]

Save the image to the disk.

Parameters:

filename (str) – Name of the file to save.

Converter for VT CLI

Functions to convert objects between different data structures.

timagetk.third_party.vt_converter.attr_from_spatialimage(input_array, **kwargs)[source]

Override keyword arguments with known attributes of the SpatialImage instance.

We replace the keyword argument value by the attribute value, except if it is None. The list of compared attributes is:

  • axes_order

  • origin

  • unit

  • voxelsize

  • metadata

Parameters:
  • input_array (timagetk.SpatialImage) – SpatialImage from which the attribute should be compared against keyword arguments

  • origin (list, optional) – (Z)YX coordinates of the origin in the image, default is [0, 0] if 2D or [0, 0, 0] if 3D.

  • voxelsize (list, optional.) – (Z)YX image voxel size, default is [1.0, 1.0] if 2D or [1.0, 1.0, 1.0] if 3D.

  • axes_order (dict) – Dictionary of axes orders, e.g. {‘x’: 2, ‘y’: 1, ‘z’: 0} by default for 3D image.

  • unit (float) – The size unit, in International System of Units (meters), associated to the image.

  • metadata (dict, optional) – Dictionary of image metadata, default is an empty dict.

Returns:

dict – Updated keyword arguments dictionary

Example

>>> import numpy as np
>>> from timagetk.io import imread
>>> from timagetk.io.util import shared_dataset
>>> from timagetk import SpatialImage
>>> from timagetk.third_party.vt_converter import attr_from_spatialimage
>>> image_path = shared_dataset("p58", "intensity")[0]
>>> spim = imread(image_path)
>>> attr_from_spatialimage(spim)
timagetk.third_party.vt_converter.vt_to_spatial_image(vt_img)[source]

Convert a vtImage in a SpatialImage.

Parameters:

vt_img (vt.vtImage) – The vtImage object to convert as SpatialImage.

Returns:

timagetk.SpatialImage – The converted image.

Examples

>>> import numpy as np
>>> from timagetk.array_util import random_array
>>> from timagetk.third_party.vt_image import vtImage
>>> from timagetk import SpatialImage
>>> from timagetk.third_party.vt_converter import vt_to_spatial_image
>>> from timagetk.io.util import shared_data
>>> # - Image from a created 3D numpy array:
>>> arr = random_array((3, 4, 5), dtype='uint8')
>>> vt_img = vtImage(arr, [0.31, 0.32, 0.33])
>>> print(vt_img.spacing())
>>> print(vt_img.shape())
>>> sp_img = vt_to_spatial_image(vt_img)
>>> print(sp_img.voxelsize)
>>> print(sp_img.shape)
>>> np.testing.assert_array_equal(vt_img.copy_to_array(), sp_img)
>>> # - Image from a created 2D numpy array:
>>> arr = random_array((4, 5), dtype='uint8')
>>> print(arr.shape)
>>> vt_img = vtImage(arr, [0.32, 0.33, 1.])
>>> print(vt_img.spacing())
>>> print(vt_img.shape())
>>> sp_img = vt_to_spatial_image(vt_img)
>>> print(sp_img.voxelsize)
>>> print(sp_img.shape)
>>> np.testing.assert_array_equal(vt_img.copy_to_array(), sp_img)
>>> # - Image from a loaded 2D image:
>>> vt_img = vtImage(shared_data("random_io_2D.inr"))
>>> print(vt_img.spacing)
>>> print(vt_img.shape)
>>> sp_img = vt_to_spatial_image(vt_img)
>>> print(sp_img.voxelsize)
>>> print(sp_img.shape)
>>> np.testing.assert_array_equal(vt_img.copy_to_array(), sp_img)
>>> # - Image from a loaded 3D image:
>>> vt_img = vtImage(shared_data("random_io_3D.inr"))
>>> print(vt_img.spacing)
>>> print(vt_img.shape)
>>> sp_img = vt_to_spatial_image(vt_img)
>>> print(sp_img.voxelsize)
>>> print(sp_img.shape)
>>> np.testing.assert_array_equal(vt_img.copy_to_array(), sp_img)

vtCellProperty wrapper

This module is a wrapper for VT feature extraction algorithms.

It only works for 3D images!

timagetk.third_party.vt_features.get_area(image, labels=None, real=True)[source]

Get the labels’ area, from the labelled image.

Parameters:
  • image (timagetk.LabelledImage) – Labelled image to use for feature computation.

  • labels (int or list of int, optional) – If None (default), returns property for all labels found in image. Else, should be a label or a list of labels to filter with those found within the image.

  • real (bool, optional) – If True (default), returns the values in real world units. Else returns the values in voxel units.

Returns:

dict – Label indexed dictionary of areas.

Notes

If the image is not isometric, it will be resampled to the highest resolution possible prior to area computation.

References

Examples

>>> from timagetk.io import imread
>>> from timagetk.io.util import shared_dataset
>>> from timagetk import LabelledImage
>>> image = imread(shared_dataset("p58", "intensity")[0], LabelledImage, not_a_label=0)
>>> from timagetk.third_party.vt_features import get_area
>>> areas = get_area(image, real=False)
>>> print(areas[1001])
1652.550537109375
>>> areas = get_area(image)
>>> print(areas[1001])
265.254883042759
>>> from timagetk.third_party.vt_features import get_neighbor_areas
>>> neighbor_areas = get_neighbor_areas(image)
>>> print(sum(neighbor_areas[1001].values()))
265.25487967507445
>>> import numpy as np
>>> from math import pi
>>> from skimage.morphology import ball
>>> from timagetk import LabelledImage
>>> from timagetk.third_party.vt_features import get_area
>>> radius = 100
>>> image = LabelledImage(ball(radius)+1, voxelsize=(1., 0.5, 0.5), dtype='uint16', not_a_label=0)
>>> area = get_area(image, real=False)
>>> print(area[2])  # area of label 2 in voxel units
125663.53125
>>> print(4*pi*radius**2)  # area in voxel units
125663.70614359173
timagetk.third_party.vt_features.get_barycenter(image, labels=None, real=True)[source]

Get the labels’ barycenters coordinate, in voxels unit, from the labelled image.

Parameters:
  • image (timagetk.LabelledImage) – Labelled image to use for feature computation.

  • labels (int or list of int, optional) – If None (default), returns feature values of all labels found in image. Else, should be a label or a list of labels to filter with those found within the image.

  • real (bool, optional) – If True (default), returns the values in real world units. Else returns the values in voxel units.

Returns:

dict – Label indexed dictionary of XY(Z) ordered barycenters.

Examples

>>> from timagetk.array_util import dummy_labelled_image_2D
>>> from timagetk.third_party.vt_features import get_barycenter
>>> im = dummy_labelled_image_2D((0.2, 0.2))  # ZYX sorted voxel-sizes
>>> bary = get_barycenter(im, real=True)  # Get it in voxel units
>>> from timagetk.array_util import dummy_labelled_image_3D
>>> from timagetk.third_party.vt_features import get_barycenter
>>> im = dummy_labelled_image_3D((0.5, 0.2, 0.2))  # ZYX sorted voxel-sizes
>>> bary = get_barycenter(im, real=True)  # Get it in voxel units
>>> from timagetk.io import imread
>>> from timagetk.io.util import shared_dataset
>>> from timagetk import LabelledImage
>>> from timagetk.third_party.vt_features import get_barycenter
>>> image = imread(shared_dataset("p58", "intensity")[0], LabelledImage, not_a_label=0)
>>> bary = get_barycenter(image, real=False)  # Get it in voxel units
>>> print(bary[1001])
[ 79.60522556 161.90038783  96.72708716]
>>> bary = get_barycenter(image)  # Get it in real units
>>> print(bary[1001])
[31.89303843 64.86377314 38.75274125]
timagetk.third_party.vt_features.get_covariance(image, labels=None, real=True)[source]

Get the labels’ covariance matrix, from the labelled image.

Parameters:
  • image (timagetk.LabelledImage) – Labelled image to use for feature computation.

  • labels (int or list of int, optional) – If None (default), returns feature values of all labels found in image. Else, should be a label or a list of labels to filter with those found within the image.

  • real (bool, optional) – If True (default), returns the values in real world units. Else returns the values in voxel units.

Returns:

dict – Label indexed dictionary of XY(Z) ordered covariance matrices.

Examples

>>> from timagetk.third_party.vt_features import get_covariance
>>> from timagetk.synthetic_data.labelled_image import example_layered_sphere_labelled_image
>>> seg_img = example_layered_sphere_labelled_image()
>>> cov = get_covariance(seg_img, real=False)
>>> print(cov[2])
[[31.33552391  0.          0.        ]
 [ 0.         31.33552391  0.        ]
 [ 0.          0.         31.33552391]]
>>> import numpy as np
>>> from timagetk.algorithms.resample import resample
>>> seg_img = resample(seg_img, voxelsize=seg_img.get_voxelsize()*np.array([2., 1., 1.]))  # simulate lower resolution in Z
>>> cov = get_covariance(seg_img, real=False)
>>> print(cov[2])
[[ 3.06441101e+01  2.81051645e-02  7.76019855e-02]
 [ 2.81051645e-02  3.07476822e+01 -5.97015469e-02]
 [ 7.76019855e-02 -5.97015469e-02  3.34125876e+01]]
timagetk.third_party.vt_features.get_labels(image, labels=None)[source]

Get the list of labels from the labelled image.

Parameters:
  • image (timagetk.LabelledImage) – Labelled image to use for feature computation.

  • labels (int or list of int, optional) – If None (default), returns all labels found in image. Else, should be a label or a list of labels to filter with those found within the image.

Returns:

list – List of labels.

Examples

>>> from timagetk.io import imread
>>> from timagetk.io.util import shared_dataset
>>> from timagetk import LabelledImage
>>> image = imread(shared_dataset("p58", "intensity")[0], LabelledImage, not_a_label=0)
>>> from timagetk.third_party.vt_features import get_labels
>>> labels = get_labels(image)
timagetk.third_party.vt_features.get_neighbor_areas(image, labels=None, real=True)[source]

Get the areas between neighbors, from a labelled image.

Parameters:
  • image (timagetk.LabelledImage) – Labelled image to use for property computation.

  • labels (int or list of int, optional) – If None (default), returns feature values of all labels found in image. Else, should be a label or a list of labels to filter with those found within the image.

  • real (bool, optional) – If True (default), returns the values in real world units. Else returns the values in voxel units.

Returns:

udict – Dictionary of wall areas between neighbors, indexed as {(label1, label2): wall_area}}.

Notes

If the image is not isometric, it will be resampled to the highest resolution possible prior to area computation.

References

Examples

>>> from timagetk.third_party.vt_features import get_neighbor_areas
>>> from timagetk.synthetic_data.labelled_image import example_layered_sphere_labelled_image
>>> seg_img = example_layered_sphere_labelled_image()
>>> neighborhood_area = get_neighbor_areas(seg_img, real=False)
>>> print(neighborhood_area[(2, 4)])
167.2568817138672
>>> print(neighborhood_area[(4, 2)])
167.2568817138672
>>> neighborhood_area = get_neighbor_areas(seg_img, real=True)
>>> print(neighborhood_area[(2, 4)])
60.212477416992186
>>> print(neighborhood_area[(4, 2)])
60.212477416992186
timagetk.third_party.vt_features.get_neighbors(image, labels=None)[source]

Get the labels’ neighbors from the labelled image.

Parameters:
  • image (timagetk.LabelledImage) – Labelled image to use for property computation.

  • labels (int or list of int, optional) – If None (default), returns feature values of all labels found in image. Else, should be a label or a list of labels to filter with those found within the image.

Returns:

dict – Label indexed dictionary of neighbors.

Examples

>>> from timagetk.io import imread
>>> from timagetk.io.util import shared_dataset
>>> from timagetk import LabelledImage
>>> image = imread(shared_dataset("p58", "intensity")[0], LabelledImage, not_a_label=0)
>>> from timagetk.third_party.vt_features import get_neighbors
>>> neighborhood = get_neighbors(image)
>>> print(neighborhood[1001])
[557, 39, 1, 888, 413, 949, 446, 399, 844, 836, 213, 467, 64, 161, 323]
>>> import time
>>> from timagetk.util import elapsed_time
>>> from timagetk.io import imread
>>> from timagetk import TissueImage3D
>>> image = imread("/data/FPS_paper/Old_Data/p194/watershed_segmentation/p194-t6-v2_SegXP.inr.gz", TissueImage3D, background=1, not_a_label=0)
>>> from vt import vtCellProperties
>>> ppty = vtCellProperties(image.to_vtimage())
>>> t_start = time.time()
>>> neighborhood = get_neighbors(image)
>>> elapsed_time(t_start)
timagetk.third_party.vt_features.get_volume(image, labels=None, real=True)[source]

Get the labels’ volumes, in voxels unit, from the labelled image.

Parameters:
  • image (timagetk.LabelledImage) – Labelled image to use for feature computation.

  • labels (int or list of int, optional) – If None (default), returns feature values of all labels found in image. Else, should be a label or a list of labels to filter with those found within the image.

  • real (bool, optional) – If True (default), returns the values in real world units. Else returns the values in voxel units.

Returns:

dict – Label indexed dictionary of volumes, in voxels unit.

Examples

>>> from timagetk.io import imread
>>> from timagetk.io.util import shared_dataset
>>> from timagetk import LabelledImage
>>> image = imread(shared_dataset("p58", "intensity")[0], LabelledImage, not_a_label=0)
>>> from timagetk.third_party.vt_features import get_volume
>>> volumes = get_volume(image, real=False)  # Get it in voxel units
>>> print(volumes[1001])
4899
>>> volumes = get_volume(image)  # Get it in real units
>>> print(volumes[1001])
315.0434075980686
timagetk.third_party.vt_features.get_vt_neighbor_areas(image, labels=None, real=True)[source]

Get the areas between neighbors, from a labelled image.

Parameters:
  • image (timagetk.LabelledImage) – Labelled image to use for property computation.

  • labels (int or list of int, optional) – If None (default), returns feature values of all labels found in image. Else, should be a label or a list of labels to filter with those found within the image.

  • real (bool, optional) – If True (default), returns the values in real world units. Else returns the values in voxel units.

Returns:

dict – Dictionary of wall areas between neighbors, oredered as {label: {label_neigbors: wall_area}}.

Notes

If the image is not isometric, it will be resampled to the highest resolution possible prior to area computation.

References

Examples

>>> from timagetk.third_party.vt_features import get_vt_neighbor_areas
>>> from timagetk.synthetic_data.labelled_image import example_layered_sphere_labelled_image
>>> seg_img = example_layered_sphere_labelled_image()
>>> neighborhood_area = get_vt_neighbor_areas(seg_img, real=False)
>>> print(neighborhood_area[2][4])
164.29844665527344
>>> print(neighborhood_area[4][2])
170.21531677246094
>>> neighborhood_area = get_vt_neighbor_areas(seg_img, real=True)
>>> print(neighborhood_area[2][4])
59.14744079589843
>>> print(neighborhood_area[4][2])
61.27751403808593

Parser for VT CLI

timagetk.third_party.vt_parser.AVERAGE_TRSFS = ['mean', 'robust-mean']

List of valid transformation averaging methods, to use with method in trsfs_averaging from timagetk.algorithms.trsf.

timagetk.third_party.vt_parser.AVERAGING_METHODS = ['mean', 'robust-mean', 'median', 'minimum', 'maximum', 'quantile', 'sum', 'var', 'stddev']

The list of available image averaging methods.

timagetk.third_party.vt_parser.BLOCKMATCHING_METHODS = ['similitude', 'rigid', 'affine', 'vectorfield']

List of valid blockmatching methods, to use with method in blockmatching from timagetk.algorithms.blockmatching.

timagetk.third_party.vt_parser.CONNECTIVITIES_2D = [4, 8]

Valid connectivity values for 2D structuring elements.

timagetk.third_party.vt_parser.CONNECTIVITIES_3D = [6, 10, 18, 26]

Valid connectivity values for 3D structuring elements.

timagetk.third_party.vt_parser.CREATE_TRSF = ['identity', 'random', 'sinus']

List of valid transformation creation methods, to use with trsf in create_trsf from timagetk.algorithms.trsf.

timagetk.third_party.vt_parser.DEFAULT_PARALLEL = 'default'

The default parallelism method.

timagetk.third_party.vt_parser.DEF_AVERAGE_TRSFS = 'mean'

Default transformation averaging method.

timagetk.third_party.vt_parser.DEF_AVG_METHOD = 'mean'

The default image averaging method.

timagetk.third_party.vt_parser.DEF_BM_METHOD = 'rigid'

The default blockmatching method used by blockmatching from timagetk.algorithms.blockmatching.

timagetk.third_party.vt_parser.DEF_CELL_BASED_SIGMA = 2

The default cell_based_sigma value:

timagetk.third_party.vt_parser.DEF_CONNECTIVITY_2D = 8

Default connectivity of the 2D structuring elements.

timagetk.third_party.vt_parser.DEF_CONNECTIVITY_3D = 26

Default connectivity of the 3D structuring elements.

timagetk.third_party.vt_parser.DEF_CREATE_TRSF = 'identity'

The default regional extrema method used by create_trsf from timagetk.algorithms.trsf.

timagetk.third_party.vt_parser.DEF_F_METHOD = 'smoothing'

The default filtering method used by linearfilter from timagetk.algorithms.linearfilter.

timagetk.third_party.vt_parser.DEF_GRAY_INTERP_METHOD = 'linear'

The default interpolation method for grayscale images used by apply_trsf from timagetk.algorithms.trsf.

timagetk.third_party.vt_parser.DEF_HIGH_THRESHOLD = None

Default high threshold for connexe method, to use with high_threshold keyword argument.

timagetk.third_party.vt_parser.DEF_ITERS = 1

Default number of iterations during morphological operations.

timagetk.third_party.vt_parser.DEF_LABELCHOICE = 'first'

The default labelling conflict resolution method used by watershed from timagetk.algorithms.watershed.

timagetk.third_party.vt_parser.DEF_LABEL_INTERP_METHOD = 'cellbased'

The default interpolation method for labelled images used by apply_trsf from timagetk.algorithms.trsf.

timagetk.third_party.vt_parser.DEF_LOW_THRESHOLD = None

Default low threshold for timagetk.algorithms.connexe.connexe() method, to use with low_threshold keyword argument.

timagetk.third_party.vt_parser.DEF_MORPHO_METHOD = 'dilation'

The default morphological operation used by morphology & label_filtering from timagetk.algorithms.morphology.

timagetk.third_party.vt_parser.DEF_PM_ESTIMATOR = 'ls'

Default pointmatching estimator method.

timagetk.third_party.vt_parser.DEF_PROPAGATION_TYPE = 'skiz'

Default pointmatching propagation method.

timagetk.third_party.vt_parser.DEF_PY_HL = 5

Default pyramid_highest_level value.

timagetk.third_party.vt_parser.DEF_PY_LL = 2

Default pyramid_lowest_level value.

timagetk.third_party.vt_parser.DEF_RADIUS = 1

Default radius of the structuring elements.

timagetk.third_party.vt_parser.DEF_RE_METHOD = 'minima'

The default regional extrema method used by regionalext from timagetk.algorithms.regionalext.

timagetk.third_party.vt_parser.FILTERING_METHODS = ['smoothing', 'gradient', 'hessian', 'laplacian', 'zero-crossings-hessian', 'zero-crossings-laplacian', 'gradient-hessian', 'gradient-laplacian', 'gradient-extrema']

List of valid filtering methods, to use with method in linearfilter from timagetk.algorithms.linearfilter.

timagetk.third_party.vt_parser.GAUSSIAN_IMPLEMENTATION = ['deriche', 'fidrich', 'young-1995', 'young-2002', 'gabor-young-2002', 'convolution']

List of valid gaussian implementations, to use with gaussian_type keyword argument in linearfilter from timagetk.algorithms.linearfilter. Requires prior selection of ‘smoothing’ as method.

timagetk.third_party.vt_parser.GRAY_INTERPOLATION_METHODS = ['linear', 'cspline']

List of valid interpolation methods for grayscale images, to use with method in apply_trsf from timagetk.algorithms.trsf.

timagetk.third_party.vt_parser.INTENSITY_MORPHOLOGY_METHODS = ['dilation', 'erosion', 'closing', 'opening', 'hat-closing', 'closing-hat', 'hclo', 'hfer', 'hat-opening', 'opening-hat', 'hope', 'houv', 'contrast', 'gradient', 'oc_alternate_sequential_filter', 'co_alternate_sequential_filter', 'coc_alternate_sequential_filter', 'oco_alternate_sequential_filter']

List of valid morphological operations, to use with method in morphology from timagetk.algorithms.morphology.

timagetk.third_party.vt_parser.INTERPOLATION_METHODS = ['linear', 'cspline', 'cellbased', 'nearest']

List of all valid interpolation methods, to use with method in apply_trsf from timagetk.algorithms.trsf.

timagetk.third_party.vt_parser.LABELCHOICE_METHODS = ['first', 'min', 'most']

List of valid labelling conflict resolution methods, to use with labelchoice in watershed from timagetk.algorithms.watershed.

timagetk.third_party.vt_parser.LABELLED_MORPHOLOGY_METHODS = ['dilation', 'erosion', 'closing', 'opening', 'oc_alternate_sequential_filter', 'co_alternate_sequential_filter', 'coc_alternate_sequential_filter', 'oco_alternate_sequential_filter']

List of valid morphological operations, to use with method in label_filtering from timagetk.algorithms.morphology.

timagetk.third_party.vt_parser.LABEL_INTERPOLATION_METHODS = ['cellbased', 'nearest']

List of valid interpolation methods for labelled images, to use with method in apply_trsf from timagetk.algorithms.trsf.

timagetk.third_party.vt_parser.OMP_TYPE = ['default', 'static', 'dynamic-one', 'dynamic', 'guided']

List of valid OMP methods to use with omp_scheduling, requires parallel_type to be set to 'omp' or 'openmp'.

timagetk.third_party.vt_parser.PARALLEL_TYPE = ['default', 'openmp', 'omp', 'pthread', 'thread']

List of valid parallelism methods to use with parallel_type.

timagetk.third_party.vt_parser.PM_ESTIMATORS = ['wlts', 'lts', 'wls', 'ls']

List of valid pointmatching estimator methods, to use with method.

timagetk.third_party.vt_parser.PROPAGATION_TYPES = ['direct', 'skiz']

List of valid pointmatching propagation methods, to use with vector_propagation_type keyword argument.

timagetk.third_party.vt_parser.REGIONALEXT_METHODS = ['minima', 'maxima']

List of valid regional extrema methods, to use with method in regionalext from timagetk.algorithms.regionalext.

timagetk.third_party.vt_parser.apply_trsf_kwargs(image, method=None, **kwargs)[source]

Keyword argument parser for vt.apply_trsf.

Set parameters default values and make sure they are of the right type.

Parameters:
  • image (timagetk.SpatialImage or timagetk.LabelledImage) – Image to transform. The type is used to define default interpolation method.

  • method ({'linear', 'cspline', 'cellbased', 'nearest'}, optional) – The interpolation method to use for image resampling. It depends on the type of image to resample, see interpolate_kwargs.

  • isotropic_voxel (float) – If set, ignore given trsf & template_img and performs isometric resampling to given voxelsize.

  • cell_based_sigma (float) – Required when using “cellbased” interpolation method, sigma for cell-based interpolation. In voxel units!

Returns:

  • str – Formatted parameters for vt.apply_trsf CLI.

  • dict – Remaining keyword arguments after parsing.

Raises:

ValueError – If cell_based_sigma is not defined when using 'cellbased' method.

Notes

Have a look at interpolate_kwargs for more keyword arguments.

Examples

>>> # Calling the keyword argument parser function you can get the default parameters:
>>> from timagetk.array_util import random_spatial_image
>>> from timagetk.array_util import dummy_labelled_image_3D
>>> from timagetk.third_party.vt_parser import apply_trsf_kwargs
>>> apply_trsf_kwargs(random_spatial_image((3,5,5)))[0]
' -interpolation linear'
>>> apply_trsf_kwargs(random_spatial_image((3,5,5)), isotropic_voxel=0.3)[0]
' -isotropic-voxel 0.3 -interpolation linear'
>>> apply_trsf_kwargs(dummy_labelled_image_3D((0.2, 0.5, 0.5)), isotropic_voxel=0.3)[0]
' -isotropic-voxel 0.3 -interpolation cellbased -cell-based-sigma 2'
timagetk.third_party.vt_parser.averaging_kwargs(method=None, **kwargs)[source]

Keyword argument parser for vt.mean_images.

Set parameters default values and make sure they are of the right type.

Parameters:
  • method ({'mean', 'robust-mean', 'median', 'minimum', 'maximum', "quantile", "sum", "var", "stddev"}) – The image averaging method to use, should be in AVERAGING_METHODS, DEF_AVG_METHOD by default.

  • window (list) – Window size for processing, default is [1, 1(, 1)].

  • quantile_value (float in [0, 1]) – Quantile of the retained value. See the “Notes” section for a detailled explanations.

  • lts_fraction (float in [0, 1]) – Fraction of points to be kept for the computation of the robust mean (trimmed estimation).

Returns:

  • str – Formatted parameters for vt.mean_images CLI.

  • dict – Remaining keyword arguments after parsing.

Raises:

ValueError – If method is not in AVERAGING_METHODS, if not None. If lts_fraction is not defined, if method is 'robust_mean'. If lts_fraction is not a float in [0, 1], if method is 'robust_mean'. If quantile_value is not defined, if method is 'quantile'. If quantile_value is not a float in [0, 1], if method is 'quantile'. If window is not a length-2 (2D image) or length-3 (3D image), if not None.

Notes

Definition of available AVERAGING_METHODS values:

  • mean, compute the mean value for each voxel;

  • robust-mean, compute the trimmed mean keeping only given fraction of values for each voxel;

  • median, compute the median value for each voxel;

  • minimum, keep the minimum value for each voxel;

  • maximum, keep the maximum value for each voxel;

  • quantile, retain only the given quantile_value for each voxel;

  • sum, compute the sum for each voxel;

  • var, compute the variance for each voxel;

  • stddev, compute the standard deviation for each voxel.

Explanations for quantile_value parameters:

  • 0: minimum value, equivalent to “min” method

  • 0.5: median value, equivalent to “median” method

  • 1: maximum value, equivalent to “max” method

Examples

>>> from timagetk.third_party.vt_parser import averaging_kwargs
>>> averaging_kwargs()[0]
' -mean'
>>> averaging_kwargs("robust_mean", lts_fraction=0.3)[0]
' -robust_mean -lts-fraction 0.3'
>>> averaging_kwargs("quantile", quantile_value=0.3)[0]
' -quantile -quantile-value 0.3'
>>> averaging_kwargs(window=[1, 1, 1])[0]
' -mean -window 1 1 1'
timagetk.third_party.vt_parser.blockmatching_kwargs(method='rigid', **kwargs)[source]

Keyword argument parser for vt.blockmatching.

Set parameters default values and make sure they are of the right type.

Parameters:
  • method ({'similitude', 'rigid', 'affine', 'vectorfield'}, optional) – The registration method to use, should be in BLOCKMATCHING_METHODS, DEF_BM_METHOD by default.

  • pyramid_lowest_level (int, optional) – Lowest level at which to compute deformation, default is DEF_PY_LL (min is 0).

  • pyramid_highest_level (int, optional) – Highest level at which to compute deformation, default is DEF_PY_HL (max is 5).

  • estimator ({'wlts', 'lts', 'wls', 'ls'}, optional) – Transformation estimator. ‘wlts’ by default.

  • elastic_sigma (float, optional) – Transformation regularization, sigma for elastic regularization (only for vector field). This is equivalent to a gaussian filtering of the final deformation field

  • fluid_sigma (float, optional) – Sigma for fluid regularization ie field interpolation and regularization for pairings (only for vector field) This is equivalent to a gaussian filtering of the incremental deformation field

  • lts_fraction (float, optional) – If defined, set the fraction of pairs that are kept, used with trimmed estimations. 0.5 by default.

  • lts_deviation (float, optional) – If defined, set the threshold to discard pairings, used with trimmed estimations. See the “Notes” section for a detailled explanations.

  • lts_iterations (int, optional) – If defined, set the maximal number of iterations, used with trimmed estimations. 100 by default.

  • pyramid_gaussian_filtering (bool, optional) – Before subsampling, the images are filtered (_*i.e.*_ smoothed) by a gaussian kernel. False by default

  • floating_low_threshold (int, optional) – Intensity values inferior or equal to low threshold are not considered in block selection, minimum by default.

  • floating_high_threshold (int, optional) – Intensity values superior or equal to high threshold are not considered in block selection, maximum by default.

  • reference_low_threshold (int, optional) – Intensity values inferior or equal to low threshold are not considered in block selection, minimum by default.

  • reference_high_threshold (int, optional) – Intensity values superior or equal to high threshold are not considered in block selection, maximum by default.

Returns:

  • str – Formatted parameters for vt.blockmatching CLI.

  • dict – Remaining keyword arguments after parsing.

Raises:

ValueError – If method is not in BLOCKMATCHING_METHODS (if not None).

Notes

Definitions of available estimator values:

  • wlts: weighted least trimmed squares (default);

  • lts: least trimmed squares;

  • wls: weighted least squares;

  • ls: least squares.

Parameter lts_deviation is used in the formulae:

threshold = average + lts_deviation * standard_deviation

Examples

>>> from timagetk.third_party.vt_parser import blockmatching_kwargs
>>> blockmatching_kwargs()[0]
' -trsf-type rigid -pyramid-lowest-level 2 -pyramid-highest-level 5'
>>> blockmatching_kwargs(fluid_sigma=0.55)[0]
' -trsf-type rigid -pyramid-lowest-level 2 -pyramid-highest-level 5'
>>> blockmatching_kwargs(method='vectorfield', fluid_sigma=0.55)[0]
' -trsf-type vectorfield -pyramid-lowest-level 2 -pyramid-highest-level 5 -fluid-sigma 0.55'
>>> blockmatching_kwargs(method='vectorfield', floating_low_threshold=1, reference_low_threshold=1)[0]
' -trsf-type vectorfield -floating-low-threshold 1 -reference-low-threshold 1 -pyramid-lowest-level 2 -pyramid-highest-level 5'
>>> blockmatching_kwargs(method='vectorfield', pyramid_gaussian_filtering=True)[0]
' -trsf-type vectorfield -pyramid-gaussian-filtering -pyramid-lowest-level 2 -pyramid-highest-level 5'
>>> blockmatching_kwargs(method='vectorfield', estimator="wlts", lts_fraction=0.55)[0]
' -trsf-type vectorfield -pyramid-lowest-level 2 -pyramid-highest-level 5 -estimator wlts -lts-fraction 0.55'
timagetk.third_party.vt_parser.cellfilter_kwargs(**kwargs)[source]

Keyword argument parser for vt.cellfilter.

Set parameters default values and make sure they are of the right type.

Returns:

  • str – Formatted parameters for vt.mean_images CLI.

  • dict – Remaining keyword arguments after parsing.

Raises:

ValueError – If connectivity is not in CONNECTIVITIES_2D for a 2D image, if not None. If connectivity is not in CONNECTIVITIES_3D for a 3D image, if not None.

Notes

Have a look at structuring_element_kwargs for more keyword arguments.

Examples

>>> # Calling the keyword argument parser function you can get the default parameters:
>>> from timagetk.third_party.vt_parser import cellfilter_kwargs
>>> cellfilter_kwargs(ndim=2)[0]  # for 2D images
' -radius 1 -iterations 1 -connectivity 8'
>>> cellfilter_kwargs(ndim=3)[0]  # for 3D images
' -radius 1 -iterations 1 -connectivity 26'
timagetk.third_party.vt_parser.connexe_kwargs(**kwargs)[source]

Keyword argument parser for vt.connexe.

Set parameters default values and make sure they are of the right type.

Parameters:
  • low_threshold (int or float) – Low threshold to binarize input image.

  • high_threshold (int or float) – High threshold to binarize input image.

  • max (bool) – If True keep the largest connected component (implies binary output) Else all detected components are kept. Equivalent to ‘max_number_cc=1’.

  • min_size_cc (int) – Minimal size, in voxels, of the connected component. Otherwise, all detected components are kept by default.

  • max_number_cc (int) – Maximal number of connected components to keep, the largest are kept first. Otherwise, all detected components are kept by default.

  • connectivity ({4, 6, 8, 10, 18, 26}) – The connectivity of the structuring elements, see structuring_element_kwargs.

  • binary_output (bool) – If True all valid connected components have the same value (1). Else each detected components have their own label (default).

  • label (bool) – If True (default) returns one label per connected component.

  • size (bool) – If True the value attributed to points of a connected component is the size of the connected components This allows to select w.r.t to size afterwards.

  • sort_sizes (bool) – If True the labels are ordered by decreasing size of connected components, implies label=True (unless changed afterwards).

Returns:

  • str – Formatted parameters for vt.connexe CLI.

  • dict – Remaining keyword arguments after parsing.

Raises:

ValueError – If connectivity is not in CONNECTIVITIES_2D for a 2D image, if not None. If connectivity is not in CONNECTIVITIES_3D for a 3D image, if not None.

Notes

Have a look at structuring_element_kwargs for more keyword arguments.

Examples

>>> # Calling the keyword argument parser function you can get the default parameters:
>>> from timagetk.third_party.vt_parser import connexe_kwargs
>>> connexe_kwargs(ndim=2)[0]  # for 2D images
' -connectivity 8 -labels'
>>> connexe_kwargs(ndim=3)[0]  # for 3D images
' -connectivity 26 -labels'
>>> connexe_kwargs(ndim=3, max=True)[0]
timagetk.third_party.vt_parser.create_trsf_kwargs(method='identity', **kwargs)[source]

Keyword argument parser for vt.create_trsf.

Set parameters default values and make sure they are of the right type.

Parameters:
  • method ({"identity", "random", "sinus"}) – The generation method to use for transformation creation, should be in CREATE_TRSF.

  • trsf_type ({"rigid", "affine", "vectorfield"}) – Type of transformation to create, default is affine.

  • seed (int) – Seed use in random generator, can be useful to reproduce some tests. Limited to “rigid” & “affine” tranformations.

  • angle_range ([float, float]) – Angle range of the linear tranformation, expressed in radian. Limited to “rigid” & “affine” tranformations.

  • translation_range ([float, float]) – Angle range of the linear tranformation, expressed in ??? FIXME. Limited to “rigid” & “affine” tranformations.

  • shear_range ([float, float]) – Shear range of the linear tranformation, expressed in ??? FIXME. Limited to “affine” tranformations.

  • scale_range ([float, float]) – Scale range of the linear tranformation, expressed in ??? FIXME. Limited to “affine” tranformations.

  • sinusoid_amplitude ([float, [float, [float]]]) – Sinusoid amplitude of the non-linear tranformation, expressed in radian. Limited to “vectorfield” tranformations.

  • sinusoid_period ([float, [float, [float]]]) – Sinusoid period of the non-linear tranformation, expressed in radian. Limited to “vectorfield” tranformations.

Returns:

  • str – Formatted parameters for vt.create_trsf CLI.

  • dict – Remaining keyword arguments after parsing.

Raises:

Examples

>>> # Calling the keyword argument parser function you can get the default parameters:
>>> from timagetk.third_party.vt_parser import create_trsf_kwargs
>>> create_trsf_kwargs()[0]
' -transformation-value identity -trsf-type affine'
timagetk.third_party.vt_parser.default_interpolation_method(image)[source]

Define correct interpolation method to use depending on image type.

Parameters:

image (Image type) – The image to interpolate.

Returns:

str – The default method to use with this type of image.

Notes

If given image is a LabelledImage instance, use DEF_LABEL_INTERP_METHOD by default or check it is in LABEL_INTERPOLATION_METHODS. If given image is a SpatialImage instance, use DEF_GRAY_INTERP_METHOD by default or check it is in LABEL_INTERPOLATION_METHODS.

Examples

>>> import numpy as np
>>> from timagetk.third_party.vt_parser import default_interpolation_method
>>> from timagetk import SpatialImage
>>> from timagetk import LabelledImage
>>> # EXAMPLE 1: Get default SpatialImage image interpolation method:
>>> default_interpolation_method(SpatialImage(np.ones((3,3,3))))
'linear'
>>> # EXAMPLE 2: Get default LabelledImage interpolation method:
>>> default_interpolation_method(LabelledImage(np.ones((3,3,3))))
'cellbased'
timagetk.third_party.vt_parser.general_kwargs(**kwargs)[source]

Keyword argument parser for VT general parameters.

Parameters:
  • param (bool, optional) – If True, default False, print the used parameters

  • verbose (bool, optional) – If True, default False, increase code verbosity

  • time (bool, optional) – If True, default False, print the CPU & USER elapsed time

  • debug (bool, optional) – If True, default False, print the debug parameters

  • quiet (bool, optional) – If True, default False, no prints from C algorithm

Returns:

str_param (str) – Formatted “general parameters” for VT CLI.

Examples

>>> from timagetk.third_party.vt_parser import general_kwargs
>>> general_kwargs()
''
>>> general_kwargs(param=True, time=True, quiet=True)
' -param -time'
timagetk.third_party.vt_parser.interpolate_kwargs(image, method=None)[source]

Check or define correct interpolation method to use with apply_trsf.

Parameters:
  • image (Image type) – The image to interpolate.

  • method (str in INTERPOLATION_METHODS, optional) – If None (default) try to guess the interpolation method from image type. Else check if it is an adequate or defined method.

Returns:

str – The string to use with params in apply_trsf.

Notes

If given image is a LabelledImage, use DEF_LABEL_INTERP_METHOD by default or check it is in LABEL_INTERPOLATION_METHODS. If given image is a SpatialImage, use DEF_GRAY_INTERP_METHOD by default or check it is in LABEL_INTERPOLATION_METHODS.

Examples

>>> from timagetk.third_party.vt_parser import interpolate_kwargs
>>> from timagetk.io.util import shared_data
>>> from timagetk.io import imread
>>> # EXAMPLE 1: Get default grayscale image interpolation method:
>>> ref_path = shared_dataset("p58")[0]
>>> image = imread(ref_path)
>>> interpolate_kwargs(image)
' -interpolation linear'
>>> interpolate_kwargs(image, "nearest")
>>> # EXAMPLE 2: Get default labelled image interpolation method:
>>> from timagetk import LabelledImage
>>> lab_image = LabelledImage(image)
>>> interpolate_kwargs(lab_image)
' -interpolation cellbased'
timagetk.third_party.vt_parser.inv_trsf_kwargs(**kwargs)[source]

Keyword argument parser for vt.inv_trsf.

Set parameters default values and make sure they are of the right type.

Parameters:
  • error (float) – Absolute error (in real world unit) to determine convergence.

  • iteration (int) – Maximal number of iterations to reach convergence.

Returns:

  • str – Formatted parameters for vt.inv_trsf CLI.

  • dict – Remaining keyword arguments after parsing.

Examples

>>> # Calling the keyword argument parser function you can get the default parameters:
>>> from timagetk.third_party.vt_parser import inv_trsf_kwargs
>>> inv_trsf_kwargs()[0]
''
>>> inv_trsf_kwargs(error=0.03)[0]
' -inversion-error 0.03'
>>> inv_trsf_kwargs(iteration=30)[0]
' -inversion-iteration 30'
timagetk.third_party.vt_parser.linfilter_kwargs(method='smoothing', **kwargs)[source]

Keyword argument parser for vt.linear_filter.

Set parameters default values and make sure they are of the right type.

Parameters:
  • method (str, optional) – The method to use for linear filtering, should be in FILTERING_METHODS, DEF_F_METHOD by default.

  • sigma (float or list of float, optional) – The sigma to apply for every axis if a float, for each axis if a list of floats

  • real (bool, optional) – Define if the sigma to apply is in voxel (default) or real units

  • gaussian_type (str, optional) – Implementation to use for gaussian smoothing. Should be in GAUSSIAN_IMPLEMENTATION.

  • positive (bool, optional) – If True (default), use a positive zero-crossing method. Requires method to be set to zero-crossings-*.

  • negative (bool, optional) – If True (default is False), use a negative zero-crossing method. Requires method to be set to zero-crossings-*.

Returns:

  • str – Formatted parameters for vt.linear_filter CLI.

  • dict – Remaining keyword arguments after parsing.

Raises:

ValueError – If method is not in FILTERING_METHODS, if not None.

Examples

>>> # Calling the keyword argument parser function you can get the default parameters:
>>> from timagetk.third_party.vt_parser import linfilter_kwargs
>>> linfilter_kwargs()[0]
' -smoothing -unit real -sigma 1.0'
>>> linfilter_kwargs("smoothing", sigma=0.5)[0]
' -smoothing -real-sigma 0.5'
>>> linfilter_kwargs("smoothing", sigma=2.0, real=False)[0]
' -smoothing -voxel-sigma 2.0'
timagetk.third_party.vt_parser.morphology_kwargs(method='dilation', methods_list=['dilation', 'erosion', 'closing', 'opening', 'hat-closing', 'closing-hat', 'hclo', 'hfer', 'hat-opening', 'opening-hat', 'hope', 'houv', 'contrast', 'gradient', 'oc_alternate_sequential_filter', 'co_alternate_sequential_filter', 'coc_alternate_sequential_filter', 'oco_alternate_sequential_filter'], **kwargs)[source]

Keyword argument parser for vt.morpho.

Set parameters default values and make sure they are of the right type.

Parameters:
  • method (str, optional) –

    The method to use for morphological filtering, should be in

    INTENSITY_MORPHOLOGY_METHODS, DEF_MORPHO_METHOD by default.

  • methods_list (list, optional) – List of valid methods.

  • connectivity ({4, 6, 8, 10, 18, 26}) – The connectivity of the structuring elements, see structuring_element_kwargs.

Returns:

  • str – Formatted parameters for vt.morpho CLI.

  • dict – Remaining keyword arguments after parsing.

Raises:

ValueError – If method is not in INTENSITY_MORPHOLOGY_METHODS, if not None.

Notes

Have a look at structuring_element_kwargs for more keyword arguments.

Examples

>>> # Calling the keyword argument parser function you can get the default parameters:
>>> from timagetk.third_party.vt_parser import morphology_kwargs
>>> morphology_kwargs(ndim=2)[0]  # for 2D images
' -dilation -radius 1 -iterations 1 -connectivity 8'
>>> morphology_kwargs(ndim=3)[0]  # for 3D images
' -dilation -radius 1 -iterations 1 -connectivity 26'
timagetk.third_party.vt_parser.parallel_kwargs(parallel=True, parallel_type='default', n_job=None, omp_scheduling=None, **kwargs)[source]

Keyword argument parser for VT parallelism parameters.

Parameters:
  • parallel (bool, optional) – If True (default), use parallelism -if available- for method in use.

  • parallel_type ({"default", "openmp", "omp", "pthread", "thread"}, optional) – Type of parallelism to use, should be in PARALLEL_TYPE, DEFAULT_PARALLEL by default.

  • n_job (int, optional) – Number of core to use for parallel computing, by default use the maximum number of available cores.

  • omp_scheduling ({"default", "static", "dynamic-one", "dynamic", "guided"}, optional) – Change ‘OpenMP’ scheduling option, should be in OMP_TYPE, default by default. Requires parallel_type to be set to 'omp' or 'openmp'.

Returns:

str – Formatted “parallelism parameters” for VT CLI.

Raises:

ValueError – If parallel_type is not in PARALLEL_TYPE, if not None.

Examples

>>> from timagetk.third_party.vt_parser import parallel_kwargs
>>> parallel_kwargs()
' -parallel -parallel-type default'
>>> parallel_kwargs(parallel_type='thread', n_job=8)
' -parallel -parallel-type thread -max-chunks 8'
timagetk.third_party.vt_parser.pointmatching_kwargs(method='rigid', **kwargs)[source]

Keyword argument parser for VT pointmatching parameters.

Set parameters default values and make sure they are of the right type.

Parameters:
  • method ({"wlts", "lts", "wls", "ls"}) – The estimation method to use, should be in PM_ESTIMATORS, DEF_PM_ESTIMATOR by default.

  • fluid_sigma (float or list of float) – Sigma for fluid regularization, i.e. field interpolation and regularization for pairings (only for vector field)

  • vector_propagation_distance (float) – Defines the propagation distance of initial pairings (i.e. displacements). This implies the same displacement for the spanned sphere. Restricted to vector-field. Distance is in world units (not voxels).

  • vector_fading_distance (float) – Area of fading for initial pairings (i.e. displacements). This allows progressive transition towards null displacements and thus avoid discontinuites. Restricted to vector-field. Distance is in world units (not voxels).

  • vector_propagation_type ({"direct", "skiz"}) – Defines how vector are propagated, should be in PROPAGATION_TYPES, DEF_PROPAGATION_TYPE by default. See notes for more details.

  • lts_fraction (float) – If defined, set the fraction of pairs that are kept, used with trimmed estimations.

  • lts_deviation (float) – If defined, set the threshold to discard pairings, used with trimmed estimations. See the “Notes” section for a detailled explanations.

  • lts_iterations (int) – If defined, set the maximal number of iterations, used with trimmed estimations.

  • real (bool, optional) – If True (default), given points are in real units else in voxels.

Returns:

  • str – Formatted parameters for vt.pointmatching CLI.

  • dict – Remaining keyword arguments after parsing.

Raises:

AssertionError – If method is not in BLOCKMATCHING_METHODS, if not None. If estimator_type is not in PM_ESTIMATORS, if not None. If “fluid_sigma”, “vector_propagation_distance” and “vector_fading_distance” are not defined when using “vectorield” as method. If “lts_fraction” or “lts_deviation” are not defined when using “wlts” or “lts” as method.

Notes

Definitions of available PM_ESTIMATORS values:

  • wlts: weighted least trimmed squares;

  • lts: least trimmed squares;

  • wls: weighted least squares;

  • ls: least squares.

Parameter lts_deviation is used in the formulae:

threshold = average + lts_deviation * standard_deviation

Definitions of available PROPAGATION_TYPES values:

  • direct: exact propagation (but slow);

  • skiz: approximate propagation (but faster).

Examples

>>> # Calling the keyword argument parser function you can get the default parameters:
>>> from timagetk.third_party.vt_parser import pointmatching_kwargs
>>> pointmatching_kwargs()[0]
' -trsf-type rigid -estimator-type ls -unit real'
>>> pointmatching_kwargs("vectorfield", fluid_sigma=5.0, vector_propagation_distance=20.0, vector_fading_distance=3.0)[0]
' -trsf-type vectorfield -fluid-sigma 5.0 -vector-propagation-distance 20.0 -vector-fading-distance 3.0 -estimator-type ls -unit real'
>>> pointmatching_kwargs("vectorfield", fluid_sigma=5.0, vector_propagation_distance=20.0, vector_fading_distance=3.0, estimator_type="lts", lts_deviation=1.5)[0]
' -trsf-type vectorfield -fluid-sigma 5.0 -vector-propagation-distance 20.0 -vector-fading-distance 3.0 -estimator-type lts -lts-deviation 1.5 -unit real'
timagetk.third_party.vt_parser.regionalext_kwargs(height, method='minima', **kwargs)[source]

Keyword argument parser for vt.regionalext.

Set parameters default values and make sure they are of the right type.

Parameters:
  • height (int) – The height of the extrema to detect.

  • method ({'minima', 'maxima'}, optional) – The method to use for regional extrema detection, should be in REGIONALEXT_METHODS, DEF_RE_METHOD by default.

  • connectivity ({4, 6, 8, 10, 18, 26}) – The connectivity of the structuring elements, see structuring_element_kwargs.

Returns:

  • str – Formatted parameters for vt.regionalext CLI.

  • dict – Remaining keyword arguments after parsing.

Raises:

ValueError – If method is not in REGIONALEXT_METHODS, if not None. If connectivity is not in CONNECTIVITIES_2D for a 2D image, if not None. If connectivity is not in CONNECTIVITIES_3D for a 3D image, if not None.

Examples

>>> # Calling the keyword argument parser function you can get the default parameters:
>>> from timagetk.third_party.vt_parser import regionalext_kwargs
>>> regionalext_kwargs(ndim=2)[0]  # for 2D images
' -minima -height 3 -radius 1 -iterations 1 -connectivity 8'
>>> regionalext_kwargs(ndim=3)[0]  # for 3D images
' -minima -height 3 -radius 1 -iterations 1 -connectivity 26'
timagetk.third_party.vt_parser.structuring_element_kwargs(ndim, radius=1, iterations=1, connectivity=None, sphere=False, **kwargs)[source]

Keyword argument parser for VT structuring element parameters.

Parameters:
  • ndim ({2, 3}) – Dimensionality of the structuring element to create. Used to define default connectivity value.

  • radius (int, optional) – Radius of the structuring element, default is DEF_RADIUS

  • iterations (int, optional) – Number of iterations to performs with this structuring element, DEF_ITERS by default.

  • connectivity (int, optional) – Defines the connectivity of the structuring element, default value depend on dimensionality.

  • sphere (bool, optional) – If True, the structuring element is the true euclidean sphere, equivalent to connectivity=18 False by default.

Returns:

str – Formatted “structuring element parameters” for VT CLI.

Raises:

ValueError – If connectivity is not in CONNECTIVITIES_2D for a 2D image, if not None. If connectivity is not in CONNECTIVITIES_3D for a 3D image, if not None.

Notes

‘-connectivity’ parameter override ‘-sphere’ parameter.

Connectivity is among the 4-, 6-, 8-, 18-, 26-neighborhoods. 4 and 8 are for 2D images, the others for 3D images.

Examples

>>> from timagetk.third_party.vt_parser import structuring_element_kwargs
>>> structuring_element_kwargs(2)  # for 2D images
' -radius 1 -iterations 1 -connectivity 8'
>>> structuring_element_kwargs(3)  # for 3D images
' -radius 1 -iterations 1 -connectivity 26'
timagetk.third_party.vt_parser.template_kwargs(shape=None, voxelsize=None, **kwargs)[source]

Keyword argument parser for VT template parameters.

Parameters:
  • shape (list, optional) – Shape of the template image.

  • voxelsize (list, optional) – Voxelsize of the template image.

Returns:

str – Formatted “template parameters” for VT CLI.

Examples

>>> from timagetk.third_party.vt_parser import template_kwargs
>>> template_kwargs([20, 50, 50], (0.5, 0.2 ,0.2))
' -template-dim 20 50 50 -template-voxel 0.5 0.2 0.2'
timagetk.third_party.vt_parser.trsfs_averaging_kwargs(method, trsf_type, **kwargs)[source]

Keyword argument parser for vt.mean_trsf.

Parameters:
  • method ({"mean", "robust-mean"}) – Transformations averaging method to use.

  • trsf_type ({"rigid", "affine", "vectorfield"}) – Type of transformation to create.

  • estimator_type ({"wlts", "lts", "wls", "ls"}) – Transformation estimator, see notes for more details.

  • lts_fraction (float) – If defined, set the fraction of pairs that are kept, used with trimmed estimations.

  • lts_deviation (float) – If defined, set the threshold to discard pairings (see notes), used with trimmed estimations.

  • lts_iterations (int) – If defined, set the maximal number of iterations, used with trimmed estimations.

  • fluid_sigma (float or list of float) – Sigma for fluid regularization, i.e. field interpolation and regularization for pairings (only for vector field)

Returns:

  • str – Formatted parameters for vt.mean_trsf CLI.

  • dict – Remaining keyword arguments after parsing.

Notes

Definitions for estimator_type:

  • wlts: weighted least trimmed squares;

  • lts: least trimmed squares;

  • wls: weighted least squares;

  • ls: least squares.

Parameter lts_deviation is used in the formulae:

threshold = average + lts_deviation * standard_deviation

Examples

>>> from timagetk.third_party.vt_parser import trsfs_averaging_kwargs
>>> trsfs_averaging_kwargs('mean', 'vectorfield')
(' -mean -trsf-type vectorfield -estimator-type ls', {})
timagetk.third_party.vt_parser.watershed_kwargs(**kwargs)[source]

Keyword argument parser for vt.watershed.

Set parameters default values and make sure they are of the right type.

Parameters:
  • labelchoice ({"first", "min", "most"}, optional) – How to deal with “labels conflicts”, i.e. where several labels meet. Should be in LABELCHOICE_METHODS, DEF_LABELCHOICE by default. See the “Notes” section for a detailled explanations.

  • max_iterations (int, optional) – Set a maximal number of iterations, stop the algorithm before convergence. 0 by default, i.e. wait for convergence.

Returns:

  • str – Formatted parameters for vt.watershed CLI.

  • dict – Remaining keyword arguments after parsing.

Raises:

ValueError – If labelchoice is not in LABELCHOICE_METHODS, if not None.

Notes

Explanations of available LABELCHOICE_METHODS values:

  • first: the first label wins;

  • min: the less represented label wins;

  • most: the most represented label wins;

Examples

>>> # Calling the keyword argument parser function you can get the default parameters:
>>> from timagetk.third_party.vt_parser import watershed_kwargs
>>> watershed_kwargs()[0]
' -labelchoice first'