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 5b7f90f8 by Gustavo Pinzon

### Tests for spam.label.moveLabels()

parent 9d07e56c
Pipeline #50372 passed with stages
in 12 minutes and 42 seconds
 ... @@ -11,6 +11,7 @@ import spam.label ... @@ -11,6 +11,7 @@ import spam.label import spam.kalisphera import spam.kalisphera import spam.label.contacts as con import spam.label.contacts as con import spam.plotting import spam.plotting import skimage.morphology VERBOSE = True VERBOSE = True # small labelled volume is a 3x3x3 with a single 1 in the middle # small labelled volume is a 3x3x3 with a single 1 in the middle ... @@ -638,6 +639,74 @@ class TestFunctionLabel(unittest.TestCase): ... @@ -638,6 +639,74 @@ class TestFunctionLabel(unittest.TestCase): im = im.astype(' COM=iniCOM, vol = iniVol for no dilate and Phi = I transformation = {'t': [0, 0, 0]} PhiField[1] = spam.deformation.computePhi(transformation) imLab2 = spam.label.moveLabels(imLab, PhiField, boundingBoxes = boundingBoxes, centresOfMass = centresOfMass) # Compute Volume and COM newVol = spam.label.volumes(imLab2)[-1] newCOM = spam.label.centresOfMass(imLab2)[-1] self.assertEqual(0, numpy.sum(iniVol - newVol)) self.assertEqual(0, numpy.sum(iniCOM - newCOM)) # Test #2 -> COM=iniCOM, vol = +10% volIni for a dilation of 10% transformation = {'z': [1.1, 1, 1]} PhiField[1] = spam.deformation.computePhi(transformation) imLab2 = spam.label.moveLabels(imLab, PhiField, boundingBoxes = boundingBoxes, centresOfMass = centresOfMass) # Compute Volume and COM newVol = spam.label.volumes(imLab2)[-1] newCOM = spam.label.centresOfMass(imLab2)[-1] self.assertEqual(0, numpy.sum(iniCOM - newCOM)) self.assertAlmostEqual(1.1, newVol/iniVol, places = 1) # Test #3 -> COM=iniCOM and vol/ iniVol > 1 for dilate = 1 and Phi = I transformation = {'t': [0, 0, 0]} PhiField[1] = spam.deformation.computePhi(transformation) imLab2 = spam.label.moveLabels(imLab, PhiField, boundingBoxes = boundingBoxes, centresOfMass = centresOfMass, labelDilate=1) # Compute Volume and COM newVol = spam.label.volumes(imLab2)[-1] newCOM = spam.label.centresOfMass(imLab2)[-1] self.assertEqual(0, numpy.sum(iniCOM - newCOM)) self.assertGreater(newVol/iniVol, 1.0) # Test#4 -> vol=iniVol and COM follows the 5vox displacement transformation = {'t': [5, 5, 5]} PhiField[1] = spam.deformation.computePhi(transformation) imLab2 = spam.label.moveLabels(imLab, PhiField, boundingBoxes = boundingBoxes, centresOfMass = centresOfMass) # Compute Volume and COM newVol = spam.label.volumes(imLab2)[-1] newCOM = spam.label.centresOfMass(imLab2)[-1] self.assertEqual(0, numpy.sum(iniVol - newVol)) self.assertTrue(((newCOM - iniCOM) == 5).all()) # Test 5 -> move grain half out and check volume is near 0.5 transformation = {'t': [30, 0, 0,]} PhiField[1] = spam.deformation.computePhi(transformation) imLab2 = spam.label.moveLabels(imLab, PhiField, boundingBoxes = boundingBoxes, centresOfMass = centresOfMass) # Compute Volume and COM newVol = spam.label.volumes(imLab2)[-1] newCOM = spam.label.centresOfMass(imLab2)[-1] self.assertAlmostEqual(0.5, newVol/iniVol, places = 1) # Test 6A -> Check that it runs when the PhiField has less labels than the labelled image PhiField = numpy.zeros((1, 4, 4)) imLab2 = spam.label.moveLabels(imLab, PhiField, boundingBoxes = boundingBoxes, centresOfMass = centresOfMass) self.assertIsNotNone(imLab2) # Test 6B -> Check that it runs when the PhiField has more labels than the labelled image PhiField = numpy.zeros((3, 4, 4)) imLab2 = spam.label.moveLabels(imLab, PhiField, boundingBoxes = boundingBoxes, centresOfMass = centresOfMass) self.assertIsNotNone(imLab2) if __name__ == '__main__': if __name__ == '__main__': unittest.main() unittest.main()