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

-rst implemented on spam-moveLabels and spam.labels.moveLabels

parent 390043dc
Pipeline #50905 passed with stages
in 23 minutes and 55 seconds
...@@ -46,7 +46,7 @@ args = spam.helpers.optionsParser.moveLabelsParser(parser) ...@@ -46,7 +46,7 @@ args = spam.helpers.optionsParser.moveLabelsParser(parser)
print("+-----------------------------+") print("+-----------------------------+")
print("| SPAM - Labelled mover |") print("| SPAM - Label mover |")
print("+-----------------------------+") print("+-----------------------------+")
print("\nCurrent Settings:") print("\nCurrent Settings:")
...@@ -56,9 +56,10 @@ for key in sorted(argsDict): ...@@ -56,9 +56,10 @@ for key in sorted(argsDict):
if args.RETURN_STATUS_THRESHOLD is None: if args.RETURN_STATUS_THRESHOLD is None:
DVC = spam.helpers.readCorrelationTSV(args.TSVFile.name, readConvergence=False) DVC = spam.helpers.readCorrelationTSV(args.TSVFile.name, readConvergence=False)
RS = None
else: else:
DVC = spam.helpers.readCorrelationTSV(args.TSVFile.name, readConvergence=True) DVC = spam.helpers.readCorrelationTSV(args.TSVFile.name, readConvergence=True)
RS = DVC['returnStatus']
# Read labelled image # Read labelled image
lab = tifffile.imread( args.LabFile.name ) lab = tifffile.imread( args.LabFile.name )
...@@ -73,6 +74,7 @@ lab = tifffile.imread( args.LabFile.name ) ...@@ -73,6 +74,7 @@ lab = tifffile.imread( args.LabFile.name )
labOut = spam.label.moveLabels(lab, labOut = spam.label.moveLabels(lab,
DVC['PhiField'], DVC['PhiField'],
returnStatus=RS,
margin=args.MARGIN, margin=args.MARGIN,
PhiCOM=args.PHICOM, PhiCOM=args.PHICOM,
threshold=args.THRESH, threshold=args.THRESH,
......
...@@ -519,7 +519,8 @@ class testAll(unittest.TestCase): ...@@ -519,7 +519,8 @@ class testAll(unittest.TestCase):
####################################################### #######################################################
exitCode = subprocess.call(["spam-moveLabels", exitCode = subprocess.call(["spam-moveLabels",
testFolder + "Lab0.tif", testFolder + "Lab0.tif",
testFolder + "Step0-Step1-discreteDVC.tsv"]) testFolder + "Step0-Step1-discreteDVC.tsv",
"-rst", "2"])
self.assertEqual(exitCode, 0) self.assertEqual(exitCode, 0)
# Load displaced labelled image # Load displaced labelled image
......
...@@ -1622,7 +1622,7 @@ def convexVolume(lab, boundingBoxes=None, centresOfMass=None, volumes=None, numb ...@@ -1622,7 +1622,7 @@ def convexVolume(lab, boundingBoxes=None, centresOfMass=None, volumes=None, numb
return convexVolume return convexVolume
def moveLabels(lab, PhiField, boundingBoxes=None, centresOfMass=None, margin=3, PhiCOM=True, threshold=0.5, labelDilate=0, numberOfThreads=1): def moveLabels(lab, PhiField, returnStatus = None, boundingBoxes=None, centresOfMass=None, margin=3, PhiCOM=True, threshold=0.5, labelDilate=0, numberOfThreads=1):
""" """
This function applies a discrete Phi field (from DDIC?) over a labelled image. This function applies a discrete Phi field (from DDIC?) over a labelled image.
...@@ -1634,6 +1634,11 @@ def moveLabels(lab, PhiField, boundingBoxes=None, centresOfMass=None, margin=3, ...@@ -1634,6 +1634,11 @@ def moveLabels(lab, PhiField, boundingBoxes=None, centresOfMass=None, margin=3,
PhiField : (multidimensional x 4 x 4 numpy array of floats) PhiField : (multidimensional x 4 x 4 numpy array of floats)
Spatial field of Phis Spatial field of Phis
returnStatus : lab.max()x1 array of ints, optional
Array with the return status for each label (usually returned by ``spam-ddic``)
If not defined (Default = None), all the labels will be moved
If returnStatus[i] == 2, the label will be moved, otherwise is omitted and erased from the final image
boundingBoxes : lab.max()x6 array of ints, optional boundingBoxes : lab.max()x6 array of ints, optional
Bounding boxes in format returned by ``boundingBoxes``. Bounding boxes in format returned by ``boundingBoxes``.
If not defined (Default = None), it is recomputed by running ``boundingBoxes`` If not defined (Default = None), it is recomputed by running ``boundingBoxes``
...@@ -1764,10 +1769,16 @@ def moveLabels(lab, PhiField, boundingBoxes=None, centresOfMass=None, margin=3, ...@@ -1764,10 +1769,16 @@ def moveLabels(lab, PhiField, boundingBoxes=None, centresOfMass=None, margin=3,
# Setting up queues # Setting up queues
q_jobs = multiprocessing.Queue() q_jobs = multiprocessing.Queue()
q_results = multiprocessing.Queue() q_results = multiprocessing.Queue()
numberOfLabelsToMove = 0
# Adding jobs to queues # Adding jobs to queues
for label in range(1, numberOfLabels+1): for label in range(1, numberOfLabels+1):
q_jobs.put(label) # Skip the particles if the returnStatus == 2 and returnStatus != None
if type(returnStatus) == numpy.ndarray and returnStatus[label] != 2:
pass
else: # Add the particles
q_jobs.put(label)
numberOfLabelsToMove += 1
for i in range(numberOfThreads): q_jobs.put("STOP") for i in range(numberOfThreads): q_jobs.put("STOP")
# Launching workers # Launching workers
for i in range(numberOfThreads): for i in range(numberOfThreads):
...@@ -1778,7 +1789,7 @@ def moveLabels(lab, PhiField, boundingBoxes=None, centresOfMass=None, margin=3, ...@@ -1778,7 +1789,7 @@ def moveLabels(lab, PhiField, boundingBoxes=None, centresOfMass=None, margin=3,
nodes_processed = 0 nodes_processed = 0
# Waiting for results # Waiting for results
widgets = [progressbar.FormatLabel(''), ' ', progressbar.Bar(), ' ', progressbar.AdaptiveETA()] widgets = [progressbar.FormatLabel(''), ' ', progressbar.Bar(), ' ', progressbar.AdaptiveETA()]
pbar = progressbar.ProgressBar(widgets=widgets, maxval=numberOfLabels) pbar = progressbar.ProgressBar(widgets=widgets, maxval=numberOfLabelsToMove)
pbar.start() pbar.start()
while finished_threads < numberOfThreads: while finished_threads < numberOfThreads:
...@@ -1791,7 +1802,7 @@ def moveLabels(lab, PhiField, boundingBoxes=None, centresOfMass=None, margin=3, ...@@ -1791,7 +1802,7 @@ def moveLabels(lab, PhiField, boundingBoxes=None, centresOfMass=None, margin=3,
if result[3] > 0: if result[3] > 0:
labOut[result[1]][result[2]] = result[3] labOut[result[1]][result[2]] = result[3]
nodes_processed += 1 nodes_processed += 1
widgets[0] = progressbar.FormatLabel("{}/{} ".format(nodes_processed, numberOfLabels)) widgets[0] = progressbar.FormatLabel("{}/{} ".format(nodes_processed, numberOfLabelsToMove))
pbar.update(nodes_processed) pbar.update(nodes_processed)
return labOut return labOut
......
...@@ -709,6 +709,19 @@ class TestFunctionLabel(unittest.TestCase): ...@@ -709,6 +709,19 @@ class TestFunctionLabel(unittest.TestCase):
imLab2 = spam.label.moveLabels(imLab, PhiField, boundingBoxes = boundingBoxes, centresOfMass = centresOfMass) imLab2 = spam.label.moveLabels(imLab, PhiField, boundingBoxes = boundingBoxes, centresOfMass = centresOfMass)
self.assertIsNotNone(imLab2) self.assertIsNotNone(imLab2)
# Test 7A -> Check that it works if the return status is equal to 2
transformation = {'t': [5, 5, 5]}
PhiField[1] = spam.deformation.computePhi(transformation)
imLab2 = spam.label.moveLabels(imLab, PhiField, returnStatus = numpy.array([0, 2]),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 7B -> Check that it works if the return status is different to 2
imLab2 = spam.label.moveLabels(imLab, PhiField, returnStatus = numpy.array([0, 0]),boundingBoxes = boundingBoxes, centresOfMass = centresOfMass)
self.assertEqual(1, len(numpy.unique(imLab2)))
def test_erodeLabels(self): def test_erodeLabels(self):
# Create the sphere # Create the sphere
imLab = skimage.morphology.ball(20) imLab = skimage.morphology.ball(20)
......
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