Package ndimage :: Module morphology
[hide private]
[frames] | no frames]

Module morphology

source code

Functions [hide private]
 
_center_is_true(structure, origin) source code
 
iterate_structure(structure, iterations, origin=None)
Iterate a structure by dilating it with itself.
source code
 
generate_binary_structure(rank, connectivity)
Generate a binary structure for binary morphological operations.
source code
 
_binary_erosion(input, structure, iterations, mask, output, border_value, origin, invert, brute_force) source code
 
binary_erosion(input, structure=None, iterations=1, mask=None, output=None, border_value=0, origin=0, brute_force=False)
Multi-dimensional binary erosion with the given structure.
source code
 
binary_dilation(input, structure=None, iterations=1, mask=None, output=None, border_value=0, origin=0, brute_force=False)
Multi-dimensional binary dilation with the given structure.
source code
 
binary_opening(input, structure=None, iterations=1, output=None, origin=0)
Multi-dimensional binary opening with the given structure.
source code
 
binary_closing(input, structure=None, iterations=1, output=None, origin=0)
Multi-dimensional binary closing with the given structure.
source code
 
binary_hit_or_miss(input, structure1=None, structure2=None, output=None, origin1=0, origin2=None)
Multi-dimensional binary hit-or-miss transform.
source code
 
binary_propagation(input, structure=None, mask=None, output=None, border_value=0, origin=0)
Multi-dimensional binary propagation with the given structure.
source code
 
binary_fill_holes(input, structure=None, output=None, origin=0)
Fill the holes in binary objects.
source code
 
grey_erosion(input, size=None, footprint=None, structure=None, output=None, mode='reflect', cval=0.0, origin=0)
Calculate a grey values erosion.
source code
 
grey_dilation(input, size=None, footprint=None, structure=None, output=None, mode='reflect', cval=0.0, origin=0)
Calculate a grey values dilation.
source code
 
grey_opening(input, size=None, footprint=None, structure=None, output=None, mode='reflect', cval=0.0, origin=0)
Multi-dimensional grey valued opening.
source code
 
grey_closing(input, size=None, footprint=None, structure=None, output=None, mode='reflect', cval=0.0, origin=0)
Multi-dimensional grey valued closing.
source code
 
morphological_gradient(input, size=None, footprint=None, structure=None, output=None, mode='reflect', cval=0.0, origin=0)
Multi-dimensional morphological gradient.
source code
 
morphological_laplace(input, size=None, footprint=None, structure=None, output=None, mode='reflect', cval=0.0, origin=0)
Multi-dimensional morphological laplace.
source code
 
white_tophat(input, size=None, footprint=None, structure=None, output=None, mode='reflect', cval=0.0, origin=0)
Multi-dimensional white tophat filter.
source code
 
black_tophat(input, size=None, footprint=None, structure=None, output=None, mode='reflect', cval=0.0, origin=0)
Multi-dimensional black tophat filter.
source code
 
distance_transform_bf(input, metric='euclidean', sampling=None, return_distances=True, return_indices=False, distances=None, indices=None)
Distance transform function by a brute force algorithm.
source code
 
distance_transform_cdt(input, structure='chessboard', return_distances=True, return_indices=False, distances=None, indices=None)
Distance transform for chamfer type of transforms.
source code
 
distance_transform_edt(input, sampling=None, return_distances=True, return_indices=False, distances=None, indices=None)
Exact euclidean distance transform.
source code
Variables [hide private]
  __package__ = 'ndimage'

Imports: numpy, _ni_support, _nd_image, filters, types


Function Details [hide private]

iterate_structure(structure, iterations, origin=None)

source code 

Iterate a structure by dilating it with itself.

If origin is None, only the iterated structure is returned. If not, a tuple of the iterated structure and the modified origin is returned.

generate_binary_structure(rank, connectivity)

source code 

Generate a binary structure for binary morphological operations.

The inputs are the rank of the array to which the structure will be applied and the square of the connectivity of the structure.

binary_erosion(input, structure=None, iterations=1, mask=None, output=None, border_value=0, origin=0, brute_force=False)

source code 

Multi-dimensional binary erosion with the given structure.

An output array can optionally be provided. The origin parameter controls the placement of the filter. If no structuring element is provided an element is generated with a squared connectivity equal to one. The border_value parameter gives the value of the array outside the border. The erosion operation is repeated iterations times. If iterations is less than 1, the erosion is repeated until the result does not change anymore. If a mask is given, only those elements with a true value at the corresponding mask element are modified at each iteration.

binary_dilation(input, structure=None, iterations=1, mask=None, output=None, border_value=0, origin=0, brute_force=False)

source code 

Multi-dimensional binary dilation with the given structure.

An output array can optionally be provided. The origin parameter controls the placement of the filter. If no structuring element is provided an element is generated with a squared connectivity equal to one. The dilation operation is repeated iterations times. If iterations is less than 1, the dilation is repeated until the result does not change anymore. If a mask is given, only those elements with a true value at the corresponding mask element are modified at each iteration.

binary_opening(input, structure=None, iterations=1, output=None, origin=0)

source code 

Multi-dimensional binary opening with the given structure.

An output array can optionally be provided. The origin parameter controls the placement of the filter. If no structuring element is provided an element is generated with a squared connectivity equal to one. The iterations parameter gives the number of times the erosions and then the dilations are done.

binary_closing(input, structure=None, iterations=1, output=None, origin=0)

source code 

Multi-dimensional binary closing with the given structure.

An output array can optionally be provided. The origin parameter controls the placement of the filter. If no structuring element is provided an element is generated with a squared connectivity equal to one. The iterations parameter gives the number of times the dilations and then the erosions are done.

binary_hit_or_miss(input, structure1=None, structure2=None, output=None, origin1=0, origin2=None)

source code 

Multi-dimensional binary hit-or-miss transform.

An output array can optionally be provided. The origin parameters controls the placement of the structuring elements. If the first structuring element is not given one is generated with a squared connectivity equal to one. If the second structuring element is not provided, it set equal to the inverse of the first structuring element. If the origin for the second structure is equal to None it is set equal to the origin of the first.

binary_propagation(input, structure=None, mask=None, output=None, border_value=0, origin=0)

source code 

Multi-dimensional binary propagation with the given structure.

An output array can optionally be provided. The origin parameter controls the placement of the filter. If no structuring element is provided an element is generated with a squared connectivity equal to one. If a mask is given, only those elements with a true value at the corresponding mask element are.

This function is functionally equivalent to calling binary_dilation with the number of iterations less then one: iterative dilation until the result does not change anymore.

binary_fill_holes(input, structure=None, output=None, origin=0)

source code 

Fill the holes in binary objects.

An output array can optionally be provided. The origin parameter controls the placement of the filter. If no structuring element is provided an element is generated with a squared connectivity equal to one.

grey_erosion(input, size=None, footprint=None, structure=None, output=None, mode='reflect', cval=0.0, origin=0)

source code 

Calculate a grey values erosion.

Either a size or a footprint, or the structure must be provided. An output array can optionally be provided. The origin parameter controls the placement of the filter. The mode parameter determines how the array borders are handled, where cval is the value when mode is equal to 'constant'.

grey_dilation(input, size=None, footprint=None, structure=None, output=None, mode='reflect', cval=0.0, origin=0)

source code 

Calculate a grey values dilation.

Either a size or a footprint, or the structure must be provided. An output array can optionally be provided. The origin parameter controls the placement of the filter. The mode parameter determines how the array borders are handled, where cval is the value when mode is equal to 'constant'.

grey_opening(input, size=None, footprint=None, structure=None, output=None, mode='reflect', cval=0.0, origin=0)

source code 

Multi-dimensional grey valued opening.

Either a size or a footprint, or the structure must be provided. An output array can optionally be provided. The origin parameter controls the placement of the filter. The mode parameter determines how the array borders are handled, where cval is the value when mode is equal to 'constant'.

grey_closing(input, size=None, footprint=None, structure=None, output=None, mode='reflect', cval=0.0, origin=0)

source code 

Multi-dimensional grey valued closing.

Either a size or a footprint, or the structure must be provided. An output array can optionally be provided. The origin parameter controls the placement of the filter. The mode parameter determines how the array borders are handled, where cval is the value when mode is equal to 'constant'.

morphological_gradient(input, size=None, footprint=None, structure=None, output=None, mode='reflect', cval=0.0, origin=0)

source code 

Multi-dimensional morphological gradient.

Either a size or a footprint, or the structure must be provided. An output array can optionally be provided. The origin parameter controls the placement of the filter. The mode parameter determines how the array borders are handled, where cval is the value when mode is equal to 'constant'.

morphological_laplace(input, size=None, footprint=None, structure=None, output=None, mode='reflect', cval=0.0, origin=0)

source code 

Multi-dimensional morphological laplace.

Either a size or a footprint, or the structure must be provided. An output array can optionally be provided. The origin parameter controls the placement of the filter. The mode parameter determines how the array borders are handled, where cval is the value when mode is equal to 'constant'.

white_tophat(input, size=None, footprint=None, structure=None, output=None, mode='reflect', cval=0.0, origin=0)

source code 

Multi-dimensional white tophat filter.

Either a size or a footprint, or the structure must be provided. An output array can optionally be provided. The origin parameter controls the placement of the filter. The mode parameter determines how the array borders are handled, where cval is the value when mode is equal to 'constant'.

black_tophat(input, size=None, footprint=None, structure=None, output=None, mode='reflect', cval=0.0, origin=0)

source code 

Multi-dimensional black tophat filter.

Either a size or a footprint, or the structure must be provided. An output array can optionally be provided. The origin parameter controls the placement of the filter. The mode parameter determines how the array borders are handled, where cval is the value when mode is equal to 'constant'.

distance_transform_bf(input, metric='euclidean', sampling=None, return_distances=True, return_indices=False, distances=None, indices=None)

source code 

Distance transform function by a brute force algorithm.

This function calculates the distance transform of the input, by replacing each background element (zero values), with its shortest distance to the foreground (any element non-zero). Three types of distance metric are supported: 'euclidean', 'city_block' and 'chessboard'.

In addition to the distance transform, the feature transform can be calculated. In this case the index of the closest background element is returned along the first axis of the result.

The return_distances, and return_indices flags can be used to indicate if the distance transform, the feature transform, or both must be returned.

Optionally the sampling along each axis can be given by the sampling parameter which should be a sequence of length equal to the input rank, or a single number in which the sampling is assumed to be equal along all axes. This parameter is only used in the case of the euclidean distance transform.

This function employs a slow brute force algorithm, see also the function distance_transform_cdt for more efficient city_block and chessboard algorithms.

the distances and indices arguments can be used to give optional output arrays that must be of the correct size and type (float64 and int32).

distance_transform_cdt(input, structure='chessboard', return_distances=True, return_indices=False, distances=None, indices=None)

source code 
Distance transform for chamfer type of transforms.

The structure determines the type of chamfering that is done. If
the structure is equal to 'cityblock' a structure is generated
using generate_binary_structure with a squared distance equal to
1. If the structure is equal to 'chessboard', a structure is
generated using generate_binary_structure with a squared distance
equal to the rank of the array. These choices correspond to the
common interpretations of the cityblock and the chessboard
distance metrics in two dimensions.

In addition to the distance transform, the feature transform can
be calculated. In this case the index of the closest background
element is returned along the first axis of the result.

The return_distances, and return_indices flags can be used to
indicate if the distance transform, the feature transform, or both
must be returned.

The distances and indices arguments can be used to give optional
output arrays that must be of the correct size and type (both int32).

distance_transform_edt(input, sampling=None, return_distances=True, return_indices=False, distances=None, indices=None)

source code 

Exact euclidean distance transform.

In addition to the distance transform, the feature transform can be calculated. In this case the index of the closest background element is returned along the first axis of the result.

The return_distances, and return_indices flags can be used to indicate if the distance transform, the feature transform, or both must be returned.

Optionally the sampling along each axis can be given by the sampling parameter which should be a sequence of length equal to the input rank, or a single number in which the sampling is assumed to be equal along all axes.

the distances and indices arguments can be used to give optional output arrays that must be of the correct size and type (float64 and int32).