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#
- 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 atx1=0|[0, -1]plan defined by all voxels atx0=x0_max|[0, 0, 2, 5]plans defined by all voxels atx0=0andx2=5dmax (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.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
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