Commit 0b03fdc3 authored by Gustavo Pinzon's avatar Gustavo Pinzon
Browse files

Morphological reconstruction over greyscale images with test

parent 7b83a76b
Pipeline #46418 passed with stages
in 29 minutes and 23 seconds
......@@ -169,6 +169,15 @@ class testAll(unittest.TestCase):
#Test that it makes sense
self.assertGreater(numpy.sum(im), numpy.sum(res))
def test_morphologicalreconstruction(self):
#Generate single sphere
im1 = numpy.zeros((20, 20, 20), dtype="<f8")
spam.kalisphera.makeSphere(im1, [10, 10, 10], 5)
res = spam.filters.morphologicalOperations.morphologicalReconstruction(im1)
#Test that it work without problem
if __name__ == '__main__':
......@@ -22,6 +22,7 @@ import multiprocessing
import progressbar
import spam.label.label
import scipy.ndimage
import skimage.morphology
# operations on greyscale images
def greyDilation(im, nBytes=1):
......@@ -409,3 +410,37 @@ def directionalErosion(bwIm, vect, a, c, NumberOfThreads=1, verbose = False):
return imEroded
def morphologicalReconstruction(im, selem = None):
This functions performs a complete morphological reconstruction (reconstruction
by dilation followed by a reconstruction by erosion. The ouput image presents less
variability in the greyvalues inside each phase, without modifying the original
shape of the objects of the image.
im : 3D numpy array
Greyscale image to perform the reconstuction
selem : structuring element, optional
Structuring element
Default = None
imReconstructed : 3D boolean array
Greyscale image after the reconstuction
#Create the seed for the dilation
imErosion = skimage.morphology.erosion(im,selem = selem)
#Dilate the seed until it reaches the mask
imOpening = skimage.morphology.reconstruction(seed = imErosion, mask = im, method = 'dilation')
#Create the seed for the dilation
imDilation = skimage.morphology.dilation(imOpening, selem = selem)
#Erode the seed until it reaches the mask
imReconstructed = skimage.morphology.reconstruction(seed = imDilation, mask = imOpening, method='erosion')
return imReconstructed
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment