Plugins module

Linear Filtering

This module contains a generic implementation of several linear filtering algorithms.

plugins.linear_filtering.linear_filtering(image, method=None, **kwargs)[source]

Linear filtering plugin.

Valid method input are:
  • gaussian_smoothing
  • gradient
  • gradient_modulus
  • hessian
  • laplacian
  • gradient_hessian
  • gradient_laplacian
  • zero_crossings_hessian
  • zero_crossings_laplacian
Parameters:
  • image (SpatialImage) – input SpatialImage to filter
  • method (str, optional) – used method, default is ‘gaussian_smoothing’
Other Parameters:
 
  • std_dev (float, optional) – the standard deviation to apply for Gaussian smoothing, in
  • real (bool, optional) – define if the standard deviation (‘std_dev’) to apply is in real or voxel units, default is False
Returns:

image and metadata

Return type:

SpatialImage

Notes

Only ‘gaussian_smoothing’ get the keyword arguments.

Example

>>> from timagetk.util import data_path
>>> from timagetk.io import imread
>>> from timagetk.plugins import linear_filtering
>>> image_path = data_path('time_0_cut.inr')
>>> image = imread(image_path)
>>> gauss_image = linear_filtering(image, std_dev=2.0, method='gaussian_smoothing')
>>> grad_mod_image = linear_filtering(image, method='gradient_modulus')
>>> lap_image = linear_filtering(image, method='laplacian')
plugins.linear_filtering.list_linear_methods()[source]

List the available ‘methods’ to call with linear_filtering.

Returns:str
Return type:the list of available methods.

Grayscale Morphology

This module contain a generic implementation of several grayscale morphology algorithms.

plugins.morphology.morphology(image, method=None, **kwargs)[source]

Grayscale morphology plugin.

Valid method input are:
  • erosion
  • dilation
  • opening
  • closing
  • morpho_gradient
  • contrast
  • hat_transform
  • inverse_hat_transform
  • oc_alternate_sequential_filter
  • co_alternate_sequential_filter
  • coc_alternate_sequential_filter
  • oco_alternate_sequential_filter
Parameters:
  • image (SpatialImage) – input image to modify, should be a ‘grayscale’ (intensity) image
  • method (str, optional) – used method, by default ‘erosion’
Other Parameters:
 
  • radius (int, optional) – radius of the structuring element, default is 1
  • iterations (int, optional) – number of time to apply the morphological operation, default is 1
  • max_radius (int, optional) – maximum value reached by ‘radius’, starting from 1, when performing ‘sequential filtering’ methods, default is 3
  • connectivity (int, optional) – use it to override the default ‘sphere’ parameter for the structuring element, equivalent to ‘connectivity=18’
Returns:

image and metadata

Return type:

SpatialImage

Raises:
  • TypeError – if the given image is not a SpatialImage
  • NotImplementedError – if the given method is not defined in the list of possible methods POSS_METHODS

Example

>>> from timagetk.util import data_path
>>> from timagetk.io import imread
>>> from timagetk.plugins import morphology
>>> image_path = data_path('time_0_cut.inr')
>>> image = imread(image_path)
>>> dilation_image = morphology(image, radius=2, iterations=2, method='dilation')
>>> oc_asf_image = morphology(image, max_radius=3, method='oc_alternate_sequential_filter')

Averaging

This module contains a generic implementation of several averaging algorithms.

plugins.averaging.averaging(list_images, method=None, **kwargs)[source]

Averaging plugin.

Valid method input are:
  • mean_averaging
  • robust_mean_averaging
  • median_averaging
  • minimum_averaging
  • maximum_averaging
Parameters:
  • list_images (list) – list of SpatialImage to average
  • method (str, optional) – used method (by default: ‘mean_averaging’)
Returns:

transformed image with its metadata

Return type:

SpatialImage

Example

>>> from timagetk.util import data_path
>>> from timagetk.io import imread
>>> from timagetk.plugins import averaging
>>> image_path = data_path('time_0_cut.inr')
>>> image = imread(image_path)
>>> list_images = [image, image, image]
>>> rob_mean_image = averaging(list_images, method='robust_mean_averaging')
>>> mean_image = averaging(list_images, method='mean_averaging')

H-transform

This module contains a generic implementation of several h_transform algorithms.

plugins.h_transform.h_transform(image, method=None, **kwargs)[source]

h_transform plugin for local minima or maxima detection.

Valid method input are:
  • h_transform_min
  • h_transform_max
Parameters:
  • image (SpatialImage) – input image to transform
  • method (str, optional) – used method, by default ‘h_transform_min’
Other Parameters:
 

h (int, optional) – height value to use in transformation, default is 1

Returns:

transformed image with its metadata

Return type:

SpatialImage

Raises:
  • TypeError – if the given image is not a SpatialImage
  • NotImplementedError – if the given method is not defined in the list of possible methods POSS_METHODS

Example

>>> from timagetk.util import data_path
>>> from timagetk.io import imread
>>> from timagetk.plugins import h_transform
>>> img_path = data_path('filtering_src.inr')
>>> image = imread(img_path)
>>> reg_max_image = h_transform(image)
>>> reg_max_image = h_transform(image, h=3, method='h_transform_max')
>>> reg_min_image = h_transform(image, h=3, method='h_transform_min')

Region Labeling

This module contain implementation of region labeling algorithms

plugins.region_labeling.region_labeling(image, method=None, **kwargs)[source]

Region labeling plugin.

Valid method input are:
  • connected_components
Parameters:
  • image (SpatialImage) – input image to transform
  • method (str, optional) – used method, by default ‘erosion’
Other Parameters:
 
  • low_threshold (int, optional) – low threshold
  • high_threshold (int, optional) – high threshold
Returns:

transformed image with its metadata

Return type:

SpatialImage

Example

>>> from timagetk.util import data_path
>>> from timagetk.io import imread
>>> from timagetk.plugins import h_transform, region_labeling
>>> image_path = data_path('time_0_cut.inr')
>>> image = imread(image_path)
>>> reg_min_image = h_transform(image, h=3, method='h_transform_min')
>>> reg_lab_image = region_labeling(reg_min_image, low_threshold=1, high_threshold=3, method='connected_components')

Segmentation

This module contains a generic implementation of several segmentation algorithms.

plugins.segmentation.segmentation(image, seeds_image, method=None, **kwargs)[source]

Segmentation plugin..

Valid method input are:
  • seeded_watershed
Parameters:
  • image (SpatialImage) – input image to transform
  • seeds_image (SpatialImage) – seed image to use for initialisation of watershed algorithm
  • method (str, optional) – used method, by default ‘seeded_watershed’
Returns:

transformed image with its metadata

Return type:

SpatialImage

Example

>>> from timagetk.util import data_path
>>> from timagetk.io import imread
>>> from timagetk.plugins import linear_filtering, h_transform, region_labeling, segmentation
>>> image_path = data_path('segmentation_src.inr')
>>> image = imread(image_path)
>>> smooth_image = linear_filtering(image, std_dev=2.0, method='gaussian_smoothing')
>>> regext_image = h_transform(smooth_image, h=5, method='h_transform_min')
>>> seeds_image = region_labeling(regext_image, low_threshold=1, high_threshold=3, method='connected_components')
>>> segmented_image = segmentation(smooth_image, seeds_image, control='first', method='seeded_watershed')
plugins.segmentation.seeded_watershed(image, seeds_image, control=None, **kwargs)[source]

Seeded watershed algorithm

Parameters:
  • image (SpatialImage) – input image to transform
  • seeds_image (SpatialImage) – seed image to use for initialisation of watershed algorithm
  • control (str, optional) – used control to deal with watershed conflicts, default=’most’, ie. the most represented label
Returns:

transformed image with its metadata

Return type:

SpatialImage

Labels Post Processing

This module contain a generic implementation of labels post processing algorithms.

plugins.labels_post_processing.labels_post_processing(image, method=None, **kwargs)[source]

Labels post-processing algorithms.

Valid method input are:
  • labels_erosion
  • labels_dilation
  • labels_opening
  • labels_closing
Parameters:
  • image (SpatialImage) – input SpatialImage
  • method (str) – used method (example: ‘labels_erosion’)
Other Parameters:
 
  • radius (int, optional; default = 1) – radius of the structuring element
  • iterations (int, optional; default = 1) – number of iteration of the morphological operation
  • connectivity (value in 4|8|10|18 or 26, default = 18) – structuring element is among the 6-, 10-, 18- & 26-neighborhoods.
Returns:

transformed image with its metadata

Return type:

SpatialImage

Warning

If your images are not isometric, the morphological operation will not be the same in every directions!

Example

>>> from timagetk.util import data_path
>>> from timagetk.io import imread
>>> from timagetk.plugins import labels_post_processing
>>> image_path = data_path('segmentation_seeded_watershed.inr')
>>> segmented_image = imread(image_path)
>>> ero_image = labels_post_processing(segmented_image, radius=2, iterations=1, method='labels_erosion')
>>> open_image = labels_post_processing(segmented_image, method='labels_opening')

Registration

This module contains a generic implementation of several registration algorithms.

plugins.registration.registration(floating_img, reference_img, method=None, **kwargs)[source]

Registration plugin.

Valid method input are:
  • rigid_registration
  • affine_registration
  • deformable_registration
Parameters:
  • floating_img (SpatialImage) – floating SpatialImage, ie. image to register
  • reference_img (SpatialImage) – reference SpatialImage for registration
  • method ({'rigid', 'affine', 'deformable'}, optional) – used method, eg. ‘rigid_registration’ (default)
Other Parameters:
 
  • pyramid_lowest_level (int, optional) – lowest level at which to compute deformation, default is 1 (min is 0)
  • pyramid_highest_level (int, optional) – highest level at which to compute deformation, default is 3 (max is 3)
Returns:

  • trsf_out (BalTrsf) – computed transformation
  • res_image (SpatialImage) – deformed image and metadata

Example

>>> from timagetk.util import data_path
>>> from timagetk.io import imread
>>> from timagetk.plugins import registration
>>> image_path = data_path('time_0_cut.inr')
>>> floating_image = imread(image_path)
>>> image_path = data_path('time_1_cut.inr')
>>> reference_image = imread(image_path)
>>> trsf_rig, res_rig = registration(floating_image, reference_image, method='rigid_registration')
>>> trsf_aff, res_aff = registration(floating_image, reference_image, method='affine_registration')
>>> trsf_def, res_def = registration(floating_image, reference_image, method='deformable_registration')

Sequence registration

This module contains a generic implementation of several sequence registration algorithms.

Sequence registration is a backward registration of all images onto the last one of a time series. It allows to obtain a sequence fully registered on the same template, ie. same image frame (shape, extent, …).

plugins.sequence_registration.sequence_registration(list_images, method=None)[source]

Sequence registration plugin.

First compute T(n,n+1) transformations, ie. T(t_n -> t_n+1), then compose them to obtain the list [T(0,N); T(1, N); …; T(N-1,N)]. Finally apply the list of transformations to the images.

Valid method input are:
  • rigid
  • affine
  • deformable
Parameters:
  • list_images (list(SpatialImage)) – list of image to register
  • method (str, optional) – used method, by default ‘rigid’
Returns:

  • list_trsf (list(BalTrsf)) – list of BalTrsf, ie. transformation matrix or vectorfields
  • list_res_img (list(SpatialImage)) – list of sequentially registered SpatialImage

Example

>>> from timagetk.util import data_path
>>> from timagetk.io import imread
>>> from timagetk.plugins import sequence_registration
>>> times = [0, 1, 2]
>>> list_images = [imread(data_path('time_' + str(time) + '.inr')) for time in times]
>>> list_trsf, list_res_img = sequence_registration(list_images, method='rigid')
>>> list_trsf, list_res_img = sequence_registration(list_images, method='affine')

Fusion

plugins.fusion.fusion(list_images, iterations=5, man_trsf_list=None, mean_imgs_prefix='', **kwargs)[source]

Multiview reconstruction (registration).

Parameters:
  • list_images (list) – list of input SpatialImage
  • iterations (int, optional) – number of iterations (default=5)
  • man_trsf_list (list, optional) – list of input RIGID BalTrsf Use it to define initial rigid trsf matrix list obtained by manually registering all images (except the first) on the first one. They will be used as init_result_transformation for blockmatching initial iteration of rigid step. Should be in real units. Successively obtained rig_trsf will be used as init_result_transformation for blockmatching REMAINING iterations of rigid step.
  • mean_imgs_prefix (str, optional) – if set, filename prefix used to save the intermediary images at each iteration, else only the last one is saved
Returns:

transformed image with its metadata

Return type:

SpatialImage

Notes

kwargs are passed to registration functions.

Example

>>> from timagetk.util import data_path
>>> from timagetk.io import imread
>>> from timagetk.plugins import fusion
>>> views = [0, 1, 2]
>>> list_images = [imread(data_path('fusion_img_' + str(views) + '.inr'))
                   for vue in vues]
>>> fus_img = fusion(list_images)