Commit fafcf3a1 authored by Gustavo Pinzon's avatar Gustavo Pinzon
Browse files

Test for spam.labels.convexFillHoles()

parent da829e7c
Pipeline #50628 passed with stages
in 12 minutes and 49 seconds
......@@ -758,5 +758,42 @@ class TestFunctionLabel(unittest.TestCase):
newCOM = spam.label.centresOfMass(imLab2)[-1]
self.assertEqual(0, numpy.sum(iniCOM - newCOM))
self.assertGreater(1.0, newVol/iniVol)
def convexFillHoles(self):
# Generate two spheres
grain1 = spam.label.label.Spheroid(15, 15, numpy.asarray([0,1,0])).digitize()
grain1 = numpy.pad(grain1, (5), 'constant', constant_values=(0))
grain1 = numpy.where(grain1, 1, 0)
grain2 = spam.label.label.Spheroid(15, 15, numpy.asarray([0,1,0])).digitize()
grain2 = numpy.pad(grain2, (5), 'constant', constant_values=(0))
grain2 = numpy.where(grain2, 2, 0)
grainIm = numpy.concatenate((grain1,grain2))
grainIm = numpy.zeros(grainIm.shape)
grainIm[:grain1.shape[0]-1,:,:] = grain1[:grain1.shape[0]-1,:,:]
grainIm[grain2.shape[0]-5:-5,:,:] = grainIm[grain2.shape[0]-5:-5,:,:] + grain2[:,:,:]
grainIm = grainIm.astype(int)
# Compute initial volume & COM
COM = spam.label.centresOfMass(grainIm)
iniVol = spam.label.volumes(grainIm).astype(int)
# Dry run of the function
res1 = spam.label.convexFillHoles(grainIm)
# Compute new volume
res1Vol = spam.label.volumes(res1).astype(int)
# Test#1 -> Check that the volumes are the same
self.assertEqual(res1Vol[1], iniVol[1])
self.assertEqual(res1Vol[2], iniVol[2])
# Add a marker in the center of one of the labels
grainIm[COM[1][0].astype(int), COM[1][1].astype(int), COM[1][2].astype(int)] = 2
# Run again
res2 = spam.label.convexFillHoles(grainIm)
# Compute final volume
endVol = spam.label.volumes(res2).astype(int)
# Compare volumes
normVol1 = (endVol[1] - iniVol[1]) / iniVol[1]
normVol2 = (endVol[2] - iniVol[2]) / iniVol[2]
# Test#2 -> Check that Vol1 is the same and Vol2 increased
self.assertAlmostEqual(normVol1, 0, places = 3)
self.assertGreater(normVol2, 0)
if __name__ == '__main__':
unittest.main()
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