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 c0269bb0 authored by Edward Andò's avatar Edward Andò
Browse files

commenting getLabel

parent 1eab193f
......@@ -178,51 +178,66 @@ class TestFunctionLabel(unittest.TestCase):
def test_getLabel(self):
# No-option get label
gl = spam.label.getLabel(threeCubedLabelVol, 1)
self.assertEqual(numpy.array([[[1]]], dtype=bool), gl['subvol'].tolist())
self.assertEqual(gl['slice'][0].start, 1)
self.assertEqual(gl['slice'][0].stop, 2)
self.assertEqual(gl['slice'][1].start, 1)
self.assertEqual(gl['slice'][1].stop, 2)
self.assertEqual(gl['slice'][2].start, 1)
self.assertEqual(gl['slice'][2].stop, 2)
gottenLabel = spam.label.getLabel(threeCubedLabelVol, 1)
self.assertEqual(numpy.array([[[1]]], dtype=bool), gottenLabel['subvol'].tolist())
self.assertEqual(gottenLabel['slice'][0].start, 1)
self.assertEqual(gottenLabel['slice'][0].stop, 2)
self.assertEqual(gottenLabel['slice'][1].start, 1)
self.assertEqual(gottenLabel['slice'][1].stop, 2)
self.assertEqual(gottenLabel['slice'][2].start, 1)
self.assertEqual(gottenLabel['slice'][2].stop, 2)
self.assertEqual(gottenLabel['boundingBox'][0], 1)
self.assertEqual(gottenLabel['boundingBox'][1], 1)
self.assertEqual(gottenLabel['boundingBox'][2], 1)
self.assertEqual(gottenLabel['boundingBox'][3], 1)
self.assertEqual(gottenLabel['boundingBox'][4], 1)
self.assertEqual(gottenLabel['boundingBox'][5], 1)
COM = spam.label.centresOfMass(threeCubedLabelVol)
self.assertEqual(COM[1].tolist(), gl['centreOfMassABS'].tolist())
self.assertEqual((COM[1] - numpy.array((1, 1, 1))).tolist(), gl['centreOfMassREL'].tolist())
self.assertEqual(gl['volumeInitial'], 1)
self.assertEqual(COM[1].tolist(), gottenLabel['centreOfMassABS'].tolist())
self.assertEqual((COM[1] - numpy.array((1, 1, 1))).tolist(), gottenLabel['centreOfMassREL'].tolist())
self.assertEqual(gottenLabel['volumeInitial'], 1)
BB = spam.label.boundingBoxes(threeCubedLabelVol)
# With extract cube
gl = spam.label.getLabel(threeCubedLabelVol, 1, boundingBoxes=BB, centresOfMass=COM, extractCube=True)
self.assertEqual(gl['sliceCube'][0].start, 1)
self.assertEqual(gl['sliceCube'][0].stop, 2)
self.assertEqual(gl['sliceCube'][1].start, 1)
self.assertEqual(gl['sliceCube'][1].stop, 2)
self.assertEqual(gl['sliceCube'][2].start, 1)
self.assertEqual(gl['sliceCube'][2].stop, 2)
# print gl['slice']
gottenLabel = spam.label.getLabel(threeCubedLabelVol, 1, boundingBoxes=BB, centresOfMass=COM, extractCube=True)
self.assertEqual(gottenLabel['sliceCube'][0].start, 1)
self.assertEqual(gottenLabel['sliceCube'][0].stop, 2)
self.assertEqual(gottenLabel['sliceCube'][1].start, 1)
self.assertEqual(gottenLabel['sliceCube'][1].stop, 2)
self.assertEqual(gottenLabel['sliceCube'][2].start, 1)
self.assertEqual(gottenLabel['boundingBoxCube'][0], 1)
self.assertEqual(gottenLabel['boundingBoxCube'][1], 1)
self.assertEqual(gottenLabel['boundingBoxCube'][2], 1)
self.assertEqual(gottenLabel['boundingBoxCube'][3], 1)
self.assertEqual(gottenLabel['boundingBoxCube'][4], 1)
self.assertEqual(gottenLabel['boundingBoxCube'][5], 1)
# print gottenLabel['slice']
COM = spam.label.centresOfMass(threeCubedLabelVol)
self.assertEqual(COM[1].tolist(), gl['centreOfMassABS'].tolist())
self.assertEqual((COM[1] - numpy.array((1, 1, 1))).tolist(), gl['centreOfMassREL'].tolist())
self.assertEqual(gl['volumeInitial'], 1)
self.assertEqual(COM[1].tolist(), gottenLabel['centreOfMassABS'].tolist())
self.assertEqual((COM[1] - numpy.array((1, 1, 1))).tolist(), gottenLabel['centreOfMassREL'].tolist())
self.assertEqual(gottenLabel['volumeInitial'], 1)
# Asking for a label that is not there
gl = spam.label.getLabel(threeCubedLabelVol, 100, boundingBoxes=BB, centresOfMass=COM, extractCube=True)
self.assertEqual(gl, None)
gottenLabel = spam.label.getLabel(threeCubedLabelVol, 100, boundingBoxes=BB, centresOfMass=COM, extractCube=True)
self.assertEqual(gottenLabel, None)
# 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=2, labelDilate=2)
volRef = gl['volumeInitial']
gottenLabel = spam.label.getLabel(threeCubedLabelVol, 1, boundingBoxes=BB, centresOfMass=COM, extractCube=True, extractCubeSize=10)
gottenLabel = spam.label.getLabel(threeCubedLabelVol, 1, boundingBoxes=BB, centresOfMass=COM, extractCube=True, extractCubeSize=0)
gottenLabel = spam.label.getLabel(threeCubedLabelVol, 1, boundingBoxes=BB, centresOfMass=COM, margin=1, labelDilate=-2)
gottenLabel = spam.label.getLabel(threeCubedLabelVol, 1, boundingBoxes=BB, centresOfMass=COM, margin=2, labelDilate=2)
volRef = gottenLabel['volumeInitial']
# 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['volumeDilated'] > volRef, True)
gottenLabel = spam.label.getLabel(threeCubedLabelVol2, 1, boundingBoxes=BB, centresOfMass=COM, margin=2, labelDilate=2, labelDilateMaskOtherLabels=True)
#print(gottenLabel['volume'], volRef)
self.assertEqual(gottenLabel['volumeDilated'] > volRef, True)
def test_labelsOnEdges(self):
labelled = numpy.zeros((5, 5, 5), dtype="<u2")
......
......@@ -473,24 +473,36 @@ def getLabel(labelledVolume, label, boundingBoxes=None, centresOfMass=None, marg
subvol : 3D array of bools or ints
subvolume from labelled image
slice: tuple of 3*slices
slice : tuple of 3*slices
Slice used to extract subvol for the bounding box mode
sliceCube: tuple of 3*slices
sliceCube : tuple of 3*slices
Slice used to extract subvol for the cube mode, warning,
if the label is near the edge, this is the slice up to the edge,
and so it will be smaller than the returned cube
boundingBox : 1D numpy array of 6 ints
Bounding box, including margin, in bounding box mode. Contains:
[Zmin, Zmax, Ymin, Ymax, Xmin, Xmax]
Note: uses the same convention as spam.label.boundingBoxes, so
if you want to use this to extract your subvolume, add +1 to max
boundingBoxCube : 1D numpy array of 6 ints
Bounding box, including margin, in cube mode. Contains:
[Zmin, Zmax, Ymin, Ymax, Xmin, Xmax]
Note: uses the same convention as spam.label.boundingBoxes, so
if you want to use this to extract your subvolume, add +1 to max
centreOfMassABS : 3*float
Centre of mass with respect to ``labelVolume``
centreOfMassREL : 3*float
Centre of mass with respect to ``subvol``
volumeInitial: int
volumeInitial : int
Volume of label (before dilating)
volumeDilated: int
volumeDilated : int
Volume of label (after dilating, if requested)
"""
......@@ -558,11 +570,13 @@ def getLabel(labelledVolume, label, boundingBoxes=None, centresOfMass=None, marg
int(comRound[1] + offset + 1),
int(comRound[2] + offset + 1)])
#sliceLimited, sliceOffset = _checkSlice(topOfSlice, botOfSlice, [0, 0, 0], numpy.array(labelledVolume.shape))
labSubVol = spam.helpers.slicePadded(labelledVolume, [topOfSlice[0], botOfSlice[0], topOfSlice[1], botOfSlice[1], topOfSlice[2], botOfSlice[2]])
#output['sliceCube'] = sliceLimited
output['sliceCube'] = (slice(topOfSlice[0], botOfSlice[0]), slice(topOfSlice[1], botOfSlice[1]), slice(topOfSlice[2], botOfSlice[2]))
output['sliceCube'] = (slice(topOfSlice[0], botOfSlice[0]),
slice(topOfSlice[1], botOfSlice[1]),
slice(topOfSlice[2], botOfSlice[2]))
output['boundingBoxCube'] = numpy.array([topOfSlice[0], botOfSlice[0]-1, topOfSlice[1], botOfSlice[1]-1, topOfSlice[2], botOfSlice[2]-1])
output['centreOfMassREL'] = com - topOfSlice
......@@ -575,13 +589,13 @@ def getLabel(labelledVolume, label, boundingBoxes=None, centresOfMass=None, marg
int(bbo[3] + margin + 1),
int(bbo[5] + margin + 1)])
#sliceLimited = (slice(max(int(bbo[0] - margin), 0), min(int(bbo[1] + 1 + margin), labelledVolume.shape[0])),
#slice(max(int(bbo[2] - margin), 0), min(int(bbo[3] + 1 + margin), labelledVolume.shape[1])),
#slice(max(int(bbo[4] - margin), 0), min(int(bbo[5] + 1 + margin), labelledVolume.shape[2])))
labSubVol = spam.helpers.slicePadded(labelledVolume, [topOfSlice[0], botOfSlice[0], topOfSlice[1], botOfSlice[1], topOfSlice[2], botOfSlice[2]])
output['slice'] = (slice(topOfSlice[0], botOfSlice[0]), slice(topOfSlice[1], botOfSlice[1]), slice(topOfSlice[2], botOfSlice[2]))
output['slice'] = (slice(topOfSlice[0], botOfSlice[0]),
slice(topOfSlice[1], botOfSlice[1]),
slice(topOfSlice[2], botOfSlice[2]))
output['boundingBox'] = numpy.array([topOfSlice[0], botOfSlice[0]-1, topOfSlice[1], botOfSlice[1]-1, topOfSlice[2], botOfSlice[2]-1])
output['centreOfMassREL'] = com - topOfSlice
......@@ -1386,7 +1400,7 @@ def fixUndersegmentation(imLab, imGrey, listLabels, a, c, numVect = 100, vect =
return
#Compute boundingBixes if needed
#Compute boundingBoxes if needed
if boundingBoxes is None:
boundingBoxes = spam.label.boundingBoxes(imLab)
if centresOfMass is None:
......
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