This module implements Morphological 1D Operators.

class Musica.Math.Morphomath.BallStructuringElement(radius)[source]

Bases: Musica.Math.Morphomath.StructuringElement

This class implements a ball structuring element.

The domain of the structuring element is [-radius, radius].

class Musica.Math.Morphomath.Domain(inf, sup)[source]

Bases: object

This class implements a functional 1D domain defined by the range [inf, sup].

The size of the domain defined by sup - inf +1 is given by the function len().

To test if x is in the domain, use:

x in domain

Test if x is in the domain.


Return the size of the domain.


Return a backward iterator over the domain.


Return a forward iterator over the domain.


Return the list of values in the domain.

class Musica.Math.Morphomath.Function(values)[source]

Bases: object

This class implements a 1D function.

The parameters values is an iterable that define the initial values of the function.

The function domain is set to [0, len(values) -1].

__add__(a, b)[source]

Return sum of a with b.


Test if the functions are equal.


Return the function value at i.


Add a function.


Subtract a function.


Return the size of the function domain.

__setitem__(i, value)[source]

Set the function value at i.

__sub__(a, b)[source]

Return the subtraction of a with b.

_pointwise_rank(other, rank_operator)[source]

This method implements a point-wise rank filter.

The function is modified in-place.

_rank_filter(structuring_element, rank_operator)[source]

This method implements a rank filter.

The function is modified in-place.

_rank_filter_vhgw(radius, rank_operator)[source]

This method implements a rank filter using the Van Herk & Gill-Werman algorithm.

This algorithm comes from C. Clienti, M. Bilodeau, and S. Beucher, An Efficient Hardware Architecture without Line Memories for Morphological Image Processing. In Proceedings of ACIVS. 2008, 147-156.


return a Numpy zero array of the same size than the function domain.


Add a function.


Return a copy of the function.


Return a function defined on the same domain with values set to zero.


Perform an closing.


Perform a dilation.


Perform a dilation using the WHGW algorithm.


Perform an erosion.


Perform an erosion using the WHGW algorithm.


Perform a geodesic reconstruction.


Perform an H-dome operation.


Return the sup of the function.


Return the inf of the function.


Perform an opening.


Perform the point-wise max of the function with another function.


Perform the point-wise min of the function with another function.


Subtract a function.

Negative values are set to zero.


Perform an top-hat.

translate(offset, padd_inf=True)[source]

Translate the function.

If the parameter padd_inf is set to True then the padding value is set to zero else to the sup of the function.

__hash__ = None
unit_ball = <Musica.Math.Morphomath.BallStructuringElement object>
class Musica.Math.Morphomath.StructuringElement(offsets)[source]

Bases: object

This class implements a structuring element.

The parameter offsets is an iterable that contains the offsets of the pixels on of the structuring element.

The neighbor set \(N_G^+\) and \(N_G^-\) is defined in the article: Morphological Grayscale Reconstruction in Image Analysis: Applications and Efficient Algorithms, Luc Vincent, IEEE Transactions on image processing, Vol. 2, No. 2, April 1993.


Iterate over the offset from the reference location.


Iterate over the offset up to the reference location.

class Musica.Math.Morphomath.StructuringElementIterator(structuring_element, domain)[source]

Bases: object

This class implements a structuring element iterator.

The parameter structuring_element defines the structuring element and the parameter domain defines the domain of the lattice.

iterate_at(location, sub_domain=None)[source]

Iterate over the structuring element positioned at a location.

The parameter sub_domain is used to restrict the domain of the structuring element, set to ‘+’ to restrict to the positive domain and to ‘-‘ for the negative domain, respectively.


Test if n is even


Test if n is odd

Musica.Math.Morphomath.unit_ball = <Musica.Math.Morphomath.BallStructuringElement object>

Unit ball structuring element.