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 import spam.kalisphera import spam.label.contacts as con import spam.plotting import skimage.morphology VERBOSE = True # small labelled volume is a 3x3x3 with a single 1 in the middle ... ... @@ -639,5 +640,73 @@ class TestFunctionLabel(unittest.TestCase): convexVol = spam.label.convexVolume(im) self.assertEqual(0, convexVol[-1]) def test_moveLabels(self): # Create the sphere imLab = skimage.morphology.ball(20) # Pad with zero at each boundaries imLab = numpy.pad(imLab, (10), 'constant', constant_values=(0)) # Compute initial volume iniVol = spam.label.volumes(imLab)[-1] # Compute initial COM iniCOM = spam.label.centresOfMass(imLab)[-1] # Compute boundingBoxes boundingBoxes = spam.label.boundingBoxes(imLab) # Compute centre of Mass centresOfMass = spam.label.centresOfMass(imLab) # Create empty PhiField PhiField = numpy.zeros((2, 4, 4)) # Test #1 -> 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__': unittest.main()
 ... ... @@ -32,6 +32,7 @@ import math import progressbar import spam.filters import multiprocessing import spam.DIC # Define a random colourmap for showing labels # This is taken from https://gist.github.com/jgomezdans/402500 ... ... @@ -1789,12 +1790,13 @@ def moveLabels(lab, PhiField, boundingBoxes = None, centresOfMass = None, margin #Create output label image labOut = numpy.zeros_like(lab, dtype=spam.label.labelType) #Get number of labels numberOfLabels = min(lab.max(), PhiField.shape[0]) numberOfLabels = min(lab.max()+1, PhiField.shape[0]) #Setting up queues q_jobs = multiprocessing.Queue() q_results = multiprocessing.Queue() #Adding jobs to queues for label in range(1, numberOfLabels+1): for label in range(1, numberOfLabels): q_jobs.put(label) for i in range(NumberOfThreads): q_jobs.put("STOP") ... ... @@ -1822,6 +1824,4 @@ def moveLabels(lab, PhiField, boundingBoxes = None, centresOfMass = None, margin nodes_processed += 1 widgets[0] = progressbar.FormatLabel("{}/{} ".format(nodes_processed, numberOfLabels)) pbar.update(nodes_processed) return labOut
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!