spam.filters package#

Submodules#

spam.filters.distanceField module#

spam.filters.distanceField.distanceField(phases, phaseID=1)[source]#

This function tranforms an array/image of integers into a continuous field. It works for segmented binary/trinary 3D images or arrays of integers. It has to be run for each phase seperately.

It uses of the Distance Transform Algorithm. For every voxel belonging to a phase a value indicating the distance (in voxels) of that point to the nearest background point is computed. The DTA is computed for the inverted image as well and the computed distances are setting to negative values. The 2 distance fields are merged into the final continuuos distance field where:

- positive numbers: distances from the phase to the nearest background
voxel
- negative values: distances from the background to the nearest phase
voxel
- zero values: the interface between the considered phase and the
background
Parameters:
  • phases (array) – The input image/array (each phase should be represented with only one number)

  • phaseID (int, default=1) – The integer indicating the phase which distance field you want to calculate

Returns:

distance field of the phase

Return type:

array

Example

>>> import tifffile
>>> import spam.filters
>>> im = tifffile.imread( "mySegmentedImage.tif" )
In this image the inclusions are labelled 1 and the matrix 0
>>> di = spam.filters.distanceField( im, phase=1 )
The resulting distance field is made of float between -1 and 1

spam.filters.morphologicalOperations module#

Library of SPAM morphological functions. Copyright (C) 2020 SPAM Contributors

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

spam.filters.morphologicalOperations.greyDilation(im, nBytes=1)[source]#

This function applies a dilation on a grey scale image

Parameters:
  • im (numpy array) – The input image (greyscale)

  • nBytes (int, default=1) – Number of bytes used to substitute the values on the border.

Returns:

The dilated image

Return type:

numpy array

spam.filters.morphologicalOperations.greyErosion(im, nBytes=1)[source]#

This function applies a erosion on a grey scale image

Parameters:
  • im (numpy array) – The input image (greyscale)

  • nBytes (int, default=1) – Number of bytes used to substitute the values on the border.

Returns:

The eroded image

Return type:

numpy array

spam.filters.morphologicalOperations.greyMorphologicalGradient(im, nBytes=1)[source]#

This function applies a morphological gradient on a grey scale image

Parameters:
  • im (numpy array) – The input image (greyscale)

  • nBytes (int, default=1) – Number of bytes used to substitute the values on the border.

Returns:

The morphologycal gradient of the image

Return type:

numpy array

spam.filters.morphologicalOperations.binaryDilation(im, sub=False)[source]#

This function applies a dilation on a binary scale image

Parameters:
  • im (numpy array) – The input image (greyscale)

  • sub (bool, default=False) – Subtitute value.

Returns:

The dilated image

Return type:

numpy array

spam.filters.morphologicalOperations.binaryErosion(im, sub=False)[source]#

This function applies a erosion on a binary scale image

Parameters:
  • im (numpy array) – The input image (greyscale)

  • sub (bool, default=False) – Substitute value.

Returns:

The eroded image

Return type:

numpy array

spam.filters.morphologicalOperations.binaryMorphologicalGradient(im, sub=False)[source]#

This function applies a morphological gradient on a binary scale image

Parameters:
  • im (numpy array) – The input image (greyscale)

  • nBytes (int, default=False) – Number of bytes used to substitute the values on the border.

Returns:

The morphologycal gradient of the image

Return type:

numpy array

spam.filters.morphologicalOperations.binaryGeodesicReconstruction(im, marker, dmax=None, verbose=False)[source]#

Calculate the geodesic reconstruction of a binary image with a given marker

Parameters:
  • im (numpy.array) – The input binary image

  • marker (numpy.array or list) – If numpy array: direct input of the marker (must be the size of im) If list: description of the plans of the image considered as the marker | [1, 0] plan defined by all voxels at x1=0 | [0, -1] plan defined by all voxels at x0=x0_max | [0, 0, 2, 5] plans defined by all voxels at x0=0 and x2=5

  • dmax (int, default=None) – The maximum geodesic distance. If None, the reconstruction is complete.

  • verbose (bool, default=False) – Verbose mode

Returns:

The reconstructed image

Return type:

numpy.array

spam.filters.morphologicalOperations.directionalErosion(bwIm, vect, a, c, nProcesses=12, verbose=False)[source]#

This functions performs direction erosion over the binarized image using an ellipsoidal structuring element over a range of directions. It is highly recommended that the structuring element is slightly smaller than the expected particle (50% smaller in each axis is a fair guess)

Parameters:
  • bwIm (3D numpy array) – Binarized image to perform the erosion

  • vect (list of n elements, each element correspond to a 1X3 array of floats) – List of directional vectors for the structuring element

  • a (int or float) – Length of the secondary semi-axis of the structuring element in px

  • c (int or float) – Lenght of the principal semi-axis of the structuring element in px

  • nProcesses (integer (optional, default = nProcessesDefault)) – Number of processes for multiprocessing Default = number of CPUs in the system

  • verbose (boolean, optional (Default = False)) – True for printing the evolution of the process False for not printing the evolution of process

Returns:

imEroded – Booean array with the result of the erosion

Return type:

3D boolean array

spam.filters.morphologicalOperations.morphologicalReconstruction(im, selem=array([[[0, 0, 0], [0, 1, 0], [0, 0, 0]], [[0, 1, 0], [1, 1, 1], [0, 1, 0]], [[0, 0, 0], [0, 1, 0], [0, 0, 0]]], dtype=uint8))[source]#

This functions performs a morphological reconstruction (greyscale opening followed by greyscale closing). The ouput image presents less variability in the greyvalues inside each phase, without modifying the original shape of the objects of the image. -

Parameters:
  • im (3D numpy array) – Greyscale image to perform the reconstuction

  • selem (structuring element, optional) – Structuring element Default = None

Returns:

imReconstructed – Greyscale image after the reconstuction

Return type:

3D boolean array

spam.filters.movingFilters module#

Library of SPAM filters. Copyright (C) 2020 SPAM Contributors

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

spam.filters.movingFilters.average(im, structEl=array([[[0., 0., 0.], [0., 1., 0.], [0., 0., 0.]], [[0., 1., 0.], [1., 2., 1.], [0., 1., 0.]], [[0., 0., 0.], [0., 1., 0.], [0., 0., 0.]]], dtype=float32))[source]#

This function calculates the average map of a grey scale image over a structuring element It works for 3D and 2D images

Parameters:
  • im (3D or 2D numpy array) – The grey scale image for which the average map will be calculated

  • structEl (3D or 2D numpy array, optional) – The structural element defining the local window-size of the operation Note that the value of each component is considered as a weight (ponderation) for the operation (see spam.mesh.structured.structuringElement for details about the structural element) Default = radius = 1 (3x3x3 array), order = 1 (diamond shape)

Returns:

imFiltered – The averaged image

Return type:

3D or 2D numpy array

spam.filters.movingFilters.variance(im, structEl=array([[[0., 0., 0.], [0., 1., 0.], [0., 0., 0.]], [[0., 1., 0.], [1., 2., 1.], [0., 1., 0.]], [[0., 0., 0.], [0., 1., 0.], [0., 0., 0.]]], dtype=float32))[source]#

” This function calculates the variance map of a grey scale image over a structuring element It works for 3D and 2D images

Parameters:
  • im (3D or 2D numpy array) – The grey scale image for which the variance map will be calculated

  • structEl (3D or 2D numpy array, optional) – The structural element defining the local window-size of the operation Note that the value of each component is considered as a weight (ponderation) for the operation (see spam.mesh.structured.structuringElement for details about the structural element) Default = radius = 1 (3x3x3 array), order = 1 (diamond shape)

Returns:

imFiltered – The variance image

Return type:

3D or 2D numpy array

spam.filters.movingFilters.hessian(im)[source]#

This function computes the hessian matrix of grey values (matrix of second derivatives) and returns eigenvalues and eigenvectors of the hessian matrix for each voxel… I hope you have a lot of memory!

Parameters:

im (3D numpy array) – The grey scale image for which the hessian will be calculated

Returns:

List 1: contains 3 different 3D arrays (same size as im):

Maximum, Intermediate, Minimum eigenvalues

List 2: contains 9 different 3D arrays (same size as im):

Components Z, Y, X of Maximum Components Z, Y, X of Intermediate Components Z, Y, X of Minimum eigenvalues

Return type:

list containing two lists

Module contents#

spam.filters.distanceField(phases, phaseID=1)[source]#

This function tranforms an array/image of integers into a continuous field. It works for segmented binary/trinary 3D images or arrays of integers. It has to be run for each phase seperately.

It uses of the Distance Transform Algorithm. For every voxel belonging to a phase a value indicating the distance (in voxels) of that point to the nearest background point is computed. The DTA is computed for the inverted image as well and the computed distances are setting to negative values. The 2 distance fields are merged into the final continuuos distance field where:

- positive numbers: distances from the phase to the nearest background
voxel
- negative values: distances from the background to the nearest phase
voxel
- zero values: the interface between the considered phase and the
background
Parameters:
  • phases (array) – The input image/array (each phase should be represented with only one number)

  • phaseID (int, default=1) – The integer indicating the phase which distance field you want to calculate

Returns:

distance field of the phase

Return type:

array

Example

>>> import tifffile
>>> import spam.filters
>>> im = tifffile.imread( "mySegmentedImage.tif" )
In this image the inclusions are labelled 1 and the matrix 0
>>> di = spam.filters.distanceField( im, phase=1 )
The resulting distance field is made of float between -1 and 1