Vous avez reçu un message "Your GitLab account has been locked ..." ? Pas d'inquiétude : lisez cet article https://docs.gricad-pages.univ-grenoble-alpes.fr/help/unlock/

Commit 93f6ce0e authored by Edward Andò's avatar Edward Andò
Browse files

Add mode for masking labels again after label dilate + test

parent 7db1289f
......@@ -211,10 +211,16 @@ class TestFunctionLabel(unittest.TestCase):
# Just run the remaining cases
gl = spam.label.getLabel(threeCubedLabelVol, 1, boundingBoxes=BB, centresOfMass=COM, extractCube=True, extractCubeSize=10)
gl = spam.label.getLabel(threeCubedLabelVol, 1, boundingBoxes=BB, centresOfMass=COM, extractCube=True, extractCubeSize=0)
gl = spam.label.getLabel(threeCubedLabelVol, 1, boundingBoxes=BB, centresOfMass=COM, margin=1, labelDilate=2)
gl = spam.label.getLabel(threeCubedLabelVol, 1, boundingBoxes=BB, centresOfMass=COM, margin=1, labelDilate=-2)
gl = spam.label.getLabel(threeCubedLabelVol, 1, boundingBoxes=BB, centresOfMass=COM, margin=2, labelDilate=2)
volRef = gl['volume']
# New case for "labelDilateMaskOtherLabels"
threeCubedLabelVol2 = threeCubedLabelVol.copy()
threeCubedLabelVol2[0,1,1] = 2
gl = spam.label.getLabel(threeCubedLabelVol2, 1, boundingBoxes=BB, centresOfMass=COM, margin=2, labelDilate=2, labelDilateMaskOtherLabels=True)
#print(gl['volume'], volRef)
self.assertEqual(gl['volume'] < volRef, True)
def test_labelsOnEdges(self):
labelled = numpy.zeros((5, 5, 5), dtype="<u2")
......
......@@ -411,7 +411,7 @@ def _checkSlice(topOfSlice, botOfSlice, topLimit, botLimit):
return returnSliceLimited, returnSliceOffset
def getLabel(labelledVolume, label, boundingBoxes=None, centresOfMass=None, margin=None, extractCube=False, extractCubeSize=None, maskOtherLabels=True, labelDilate=0):
def getLabel(labelledVolume, label, boundingBoxes=None, centresOfMass=None, margin=None, extractCube=False, extractCubeSize=None, maskOtherLabels=True, labelDilate=0, labelDilateMaskOtherLabels=True):
"""
Helper function to extract labels from a labelled image/volume.
A dictionary is returned with the a subvolume around the particle.
......@@ -460,6 +460,11 @@ def getLabel(labelledVolume, label, boundingBoxes=None, centresOfMass=None, marg
Requires ``maskOtherLabels``.
Default = 0
labelDilateMaskOtherLabels : bool, optional
Strictly cut the other labels out of the dilated image of the requested label?
Only pertinent for positive labelDilate values.
Default = False
Returns
-------
Dictionary containing:
......@@ -571,20 +576,24 @@ def getLabel(labelledVolume, label, boundingBoxes=None, centresOfMass=None, marg
# if we should mask, just return the mask.
if maskOtherLabels:
# labSubVol[ numpy.logical_not( maskLab ) ] = 0
# Just overwrite "labSubVol"
labSubVol = maskLab
# 2019-09-07 EA: changing dilation/erosion into a single pass by a spherical element, rather than repeated
# iterations of the standard.
if labelDilate > 0:
if labelDilate >= margin:
print("\tlabel.toolkit.getLabel(): labelDilate requested with a margin smaller than or equal to the number of times to dilate. I hope you know what you're doing!")
strucuringElement = spam.mesh.structuringElement(radius=labelDilate, order=2, dim=3)
labSubVol = scipy.ndimage.morphology.binary_dilation(labSubVol, structure=strucuringElement, iterations=1)
maskLab = scipy.ndimage.morphology.binary_dilation(maskLab, structure=strucuringElement, iterations=1)
if labelDilateMaskOtherLabels:
# remove voxels that are neither our label nor pore
maskLab[numpy.logical_and(labSubVol!=label, labSubVol!=0)] = 0
if labelDilate < 0:
strucuringElement = spam.mesh.structuringElement(radius=-1*labelDilate, order=2, dim=3)
labSubVol = scipy.ndimage.morphology.binary_erosion( labSubVol, structure=strucuringElement, iterations=1)
maskLab = scipy.ndimage.morphology.binary_erosion( maskLab, structure=strucuringElement, iterations=1)
# Just overwrite "labSubVol"
labSubVol = maskLab
# Update volume output
volume = numpy.sum(maskLab)
return {'subvol': labSubVol,
'slice': sliceLimited,
......
Markdown is supported
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