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

Commented the function spam.label.fixUndersegmentation() and respective test

parent f00d05d3
Pipeline #50645 passed with stages
in 23 minutes and 43 seconds
......@@ -501,53 +501,53 @@ class TestFunctionLabel(unittest.TestCase):
res = spam.label.label.Spheroid(10, 20, dim = 3).digitize()
self.assertIsNotNone(res)
def _test_FixUnderSegmentation(self):
# Generate two prolate grains (rice-like)
grain1 = spam.label.label.Spheroid(10, 20, numpy.asarray([0,1,0])).digitize()
grain2 = spam.label.label.Spheroid(10, 20, numpy.asarray([0,1,0])).digitize()
# Create the bigger labelled image
grainIm = numpy.concatenate((grain1,grain2))
grainIm = numpy.zeros(grainIm.shape)
# Add the grains to the bigger image
grainIm[:grain1.shape[0]-1,:,:] = grain1[:grain1.shape[0]-1,:,:]
grainIm[grain2.shape[0]-5:-5,:,:] = grainIm[grain2.shape[0]-5:-5,:,:] + grain1[:,:,:]
# Set all the labels to 1
grainIm = numpy.where(grainIm >= 1, 3, grainIm)
# Pad a border
grainIm = numpy.pad(grainIm, pad_width=10, mode='constant', constant_values = 0)
# Create the 'greyScale' image
greyIm = numpy.where(grainIm == 3, 30000, 10000)
# Check that the greyscale image is normalized
res1 = spam.label.label.fixUndersegmentation(grainIm, greyIm, [3], 10*0.5, 20*0.5)
self.assertEqual(res1, None)
# Check that a or c is valid
res2 = spam.label.label.fixUndersegmentation(grainIm, greyIm, [3], numpy.nan, numpy.nan)
self.assertEqual(res2, None)
# Check that a or c are positive
res3 = spam.label.label.fixUndersegmentation(grainIm, greyIm, [3], -1, 10)
self.assertEqual(res3, None)
# Run fixUnderSegmentation
greyIm = numpy.where(grainIm == 3, 0.75, 0.25)
res4 = spam.label.label.fixUndersegmentation(grainIm, greyIm, [3], 10*0.8, 20*0.8, vect = [[0,1,0]])
# Check that there are two grains
self.assertEqual(numpy.max(numpy.unique(res4)), 2)
# Check that it runs even if the label does not exist
res5 = spam.label.label.fixUndersegmentation(grainIm, greyIm, [3], 10*0.8, 20*0.8, vect = [[0,1,0]])
self.assertIsNotNone(res5)
# Check for a vect that is not a list
res6 = spam.label.label.fixUndersegmentation(grainIm, greyIm, [3], 10*0.8, 20*0.8, vect = (0,1,0))
self.assertIsNone(res6)
# Check that it works without the input vect
res7 = spam.label.label.fixUndersegmentation(grainIm, greyIm, [3], 10*0.8, 20*0.8, numVect = 1)
self.assertIsNotNone(res7)
# Check that it works with verbose = True
res8 = spam.label.label.fixUndersegmentation(grainIm, greyIm, [3], 10*0.8, 20*0.8, numVect = 1, verbose = True)
self.assertIsNotNone(res8)
# Check that it works even for a non-existing label
res9 = spam.label.label.fixUndersegmentation(grainIm, greyIm, [5], 10*0.8, 20*0.8, numVect = 1)
self.assertIsNotNone(res9)
#def test_FixUnderSegmentation(self):
#Generate two prolate grains (rice-like)
#grain1 = spam.label.label.Spheroid(10, 20, numpy.asarray([0,1,0])).digitize()
#grain2 = spam.label.label.Spheroid(10, 20, numpy.asarray([0,1,0])).digitize()
#Create the bigger labelled image
#grainIm = numpy.concatenate((grain1,grain2))
#grainIm = numpy.zeros(grainIm.shape)
#Add the grains to the bigger image
#grainIm[:grain1.shape[0]-1,:,:] = grain1[:grain1.shape[0]-1,:,:]
#grainIm[grain2.shape[0]-5:-5,:,:] = grainIm[grain2.shape[0]-5:-5,:,:] + grain1[:,:,:]
#Set all the labels to 1
#grainIm = numpy.where(grainIm >= 1, 3, grainIm)
#Pad a border
#grainIm = numpy.pad(grainIm, pad_width=10, mode='constant', constant_values = 0)
#Create the 'greyScale' image
#greyIm = numpy.where(grainIm == 3, 30000, 10000)
#Check that the greyscale image is normalized
#res1 = spam.label.label.fixUndersegmentation(grainIm, greyIm, [3], 10*0.5, 20*0.5)
#self.assertEqual(res1, None)
#Check that a or c is valid
#res2 = spam.label.label.fixUndersegmentation(grainIm, greyIm, [3], numpy.nan, numpy.nan)
#self.assertEqual(res2, None)
#Check that a or c are positive
#res3 = spam.label.label.fixUndersegmentation(grainIm, greyIm, [3], -1, 10)
#self.assertEqual(res3, None)
#Run fixUnderSegmentation
#greyIm = numpy.where(grainIm == 3, 0.75, 0.25)
#res4 = spam.label.label.fixUndersegmentation(grainIm, greyIm, [3], 10*0.8, 20*0.8, vect = [[0,1,0]])
#Check that there are two grains
#self.assertEqual(numpy.max(numpy.unique(res4)), 2)
#Check that it runs even if the label does not exist
#res5 = spam.label.label.fixUndersegmentation(grainIm, greyIm, [3], 10*0.8, 20*0.8, vect = [[0,1,0]])
#self.assertIsNotNone(res5)
#Check for a vect that is not a list
#res6 = spam.label.label.fixUndersegmentation(grainIm, greyIm, [3], 10*0.8, 20*0.8, vect = (0,1,0))
#self.assertIsNone(res6)
#Check that it works without the input vect
#res7 = spam.label.label.fixUndersegmentation(grainIm, greyIm, [3], 10*0.8, 20*0.8, numVect = 1)
#self.assertIsNotNone(res7)
#Check that it works with verbose = True
#res8 = spam.label.label.fixUndersegmentation(grainIm, greyIm, [3], 10*0.8, 20*0.8, numVect = 1, verbose = True)
#self.assertIsNotNone(res8)
#Check that it works even for a non-existing label
#res9 = spam.label.label.fixUndersegmentation(grainIm, greyIm, [5], 10*0.8, 20*0.8, numVect = 1)
#self.assertIsNotNone(res9)
def test_contactOrientations(self):
......@@ -709,6 +709,32 @@ class TestFunctionLabel(unittest.TestCase):
imLab2 = spam.label.moveLabels(imLab, PhiField, boundingBoxes = boundingBoxes, centresOfMass = centresOfMass)
self.assertIsNotNone(imLab2)
# Test 7 -> Check that it runs for more than one grain....
# Create two grains
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)
# Create empty PhiField
PhiField = numpy.zeros((3, 4, 4))
# Compute initial volume & COM
COM = spam.label.centresOfMass(grainIm)
iniVol = spam.label.volumes(grainIm)
# Apply a displacement
transformation = {'t': [1, 1, 1]}
PhiField[1] = spam.deformation.computePhi(transformation)
transformation = {'t': [-1, -1, -1]}
PhiField[2] = spam.deformation.computePhi(transformation)
imLab2 = spam.label.moveLabels(grainIm, PhiField)
self.assertIsNotNone(imLab2)
def test_erodeLabels(self):
# Create the sphere
imLab = skimage.morphology.ball(20)
......
This diff is collapsed.
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