Commit eae598ad authored by Edward Andò's avatar Edward Andò
Browse files

skip ddic labels whose deformed state is wholly outside the image

parent 75f7113a
Pipeline #50211 passed with stages
in 12 minutes and 35 seconds
...@@ -394,6 +394,8 @@ if mpiRank == boss or not mpi: ...@@ -394,6 +394,8 @@ if mpiRank == boss or not mpi:
imagette2 = spam.helpers.slicePadded(im2, startStopIm2) imagette2 = spam.helpers.slicePadded(im2, startStopIm2)
# Catch
# point in im2 that we are searching around # point in im2 that we are searching around
searchCentre = (numpy.array(imagette2.shape, dtype='<f4') - 1) / 2.0 + labelDisplacementInt - middleOfSearchRange searchCentre = (numpy.array(imagette2.shape, dtype='<f4') - 1) / 2.0 + labelDisplacementInt - middleOfSearchRange
#searchCentre = (numpy.array(imagette2.shape, dtype='<f4') - 1) / 2.0 #searchCentre = (numpy.array(imagette2.shape, dtype='<f4') - 1) / 2.0
...@@ -476,9 +478,8 @@ if mpiRank == boss or not mpi: ...@@ -476,9 +478,8 @@ if mpiRank == boss or not mpi:
imagette2imagette1sizeDiff = numpy.array(imagette2.shape) - numpy.array(imagette1.shape) imagette2imagette1sizeDiff = numpy.array(imagette2.shape) - numpy.array(imagette1.shape)
# Catch register DimProblem # If all of imagette2 is nans it fell outside im2 (or in any case it's going to be difficult to correlate)
if not (imagette2imagette1sizeDiff < 0).any(): if not numpy.all(numpy.isnan(imagette2)):
# Remove int() part of displacement since it's already used to extract imagette2 # Remove int() part of displacement since it's already used to extract imagette2
PhiTemp = PhiField[label].copy() PhiTemp = PhiField[label].copy()
PhiTemp[0:3, -1] -= labelDisplacementInt PhiTemp[0:3, -1] -= labelDisplacementInt
...@@ -528,8 +529,8 @@ if mpiRank == boss or not mpi: ...@@ -528,8 +529,8 @@ if mpiRank == boss or not mpi:
workersActive[worker] = True workersActive[worker] = True
else: # Regardless of MPI or single proc failed imDiff condition else: # Regardless of MPI or single proc failed imDiff condition
finishedLabels += 1 finishedLabels += 1
returnStatus[label] = -5 returnStatus[label] = -4
print("\t\tBoss: Fail imDiff", imagette2imagette1sizeDiff) print("\t\tBoss: Empty imagette 2 with initial displacement", labelDisplacementInt)
grainOK = True grainOK = True
else: # No args.LABEL_CORRELATE else: # No args.LABEL_CORRELATE
......
...@@ -145,7 +145,14 @@ class testAll(unittest.TestCase): ...@@ -145,7 +145,14 @@ class testAll(unittest.TestCase):
self.assertEqual(mask[10:110, 10:110, 10:110].sum(), 100**3) self.assertEqual(mask[10:110, 10:110, 10:110].sum(), 100**3)
## case 6: not touching im ## case 6: not touching im
startStop = numpy.array([100, 120, 100, 120, 100, 120]) startStop = numpy.array([100, 120, 40, 60, 40, 60])
imSliced, mask = spam.helpers.slicePadded(im, startStop, createMask = True)
self.assertEqual(list(imSliced.shape), [20, 20, 20])
self.assertEqual(numpy.isfinite(imSliced).sum(), 0)
self.assertEqual(mask.sum(), 0)
## case 7: not touching im
startStop = numpy.array([-120, -100, 40, 60, 40, 60])
imSliced, mask = spam.helpers.slicePadded(im, startStop, createMask = True) imSliced, mask = spam.helpers.slicePadded(im, startStop, createMask = True)
self.assertEqual(list(imSliced.shape), [20, 20, 20]) self.assertEqual(list(imSliced.shape), [20, 20, 20])
self.assertEqual(numpy.isfinite(imSliced).sum(), 0) self.assertEqual(numpy.isfinite(imSliced).sum(), 0)
......
...@@ -487,7 +487,6 @@ def slicePadded(im, startStop, createMask=False, padValue=0): ...@@ -487,7 +487,6 @@ def slicePadded(im, startStop, createMask=False, padValue=0):
assert (startStop[3]>startStop[2]), "spam.helpers.slicePadded(): Ymax should be bigger than Ymin" assert (startStop[3]>startStop[2]), "spam.helpers.slicePadded(): Ymax should be bigger than Ymin"
assert (startStop[5]>startStop[4]), "spam.helpers.slicePadded(): Xmax should be bigger than Xmin" assert (startStop[5]>startStop[4]), "spam.helpers.slicePadded(): Xmax should be bigger than Xmin"
imSliced = numpy.zeros((startStop[1]-startStop[0], imSliced = numpy.zeros((startStop[1]-startStop[0],
startStop[3]-startStop[2], startStop[3]-startStop[2],
startStop[5]-startStop[4]), dtype=im.dtype) + padValue startStop[5]-startStop[4]), dtype=im.dtype) + padValue
...@@ -502,7 +501,7 @@ def slicePadded(im, startStop, createMask=False, padValue=0): ...@@ -502,7 +501,7 @@ def slicePadded(im, startStop, createMask=False, padValue=0):
# Check condition that we're asking for a slice of data wholly outside im # Check condition that we're asking for a slice of data wholly outside im
# This means either that the stop values are all smaller than 0 # This means either that the stop values are all smaller than 0
# OR the start are all bigger than im.shape # OR the start are all bigger than im.shape
if numpy.all(stop < numpy.array([0, 0, 0])) or numpy.all(start >= numpy.array(im.shape)): if numpy.any(stop < numpy.array([0, 0, 0])) or numpy.any(start >= numpy.array(im.shape)):
print("spam.helpers.slicePadded(): The extracted padded slice doesn't not touch the image!") print("spam.helpers.slicePadded(): The extracted padded slice doesn't not touch the image!")
imSliced *= numpy.nan imSliced *= numpy.nan
if createMask: if createMask:
......
...@@ -174,7 +174,7 @@ def ldicParser(parser): ...@@ -174,7 +174,7 @@ def ldicParser(parser):
type=int, type=int,
default=None, default=None,
dest='HWS', dest='HWS',
help="Half correlation window size, measured each side of the node pixel (assumed equal in all 3 directions -- see -hws3 for different setting). Default = 10px") help="Half correlation window size, measured each side of the node pixel (assumed equal in all 3 directions -- see -hws3 for different setting). Default = 10 px")
# Possible: node spacing different in all three directions # Possible: node spacing different in all three directions
parser.add_argument('-hws3', parser.add_argument('-hws3',
...@@ -197,7 +197,7 @@ def ldicParser(parser): ...@@ -197,7 +197,7 @@ def ldicParser(parser):
type=int, type=int,
default=[3], default=[3],
dest='GRID_POINT_MARGIN', dest='GRID_POINT_MARGIN',
help="Margin in pixels for grid-point registration. Default = 3px") help="Margin in pixels for grid-point registration. Default = 3 px")
parser.add_argument('-gpm3', parser.add_argument('-gpm3',
'--grid-point-margin3', '--grid-point-margin3',
...@@ -205,7 +205,7 @@ def ldicParser(parser): ...@@ -205,7 +205,7 @@ def ldicParser(parser):
type=int, type=int,
default=None, default=None,
dest='GRID_POINT_MARGIN', dest='GRID_POINT_MARGIN',
help="Subpixel margin for grid-point registration. Default = 3px") help="Subpixel margin for grid-point registration. Default = [3, 3, 3] px")
parser.add_argument('-gpi', parser.add_argument('-gpi',
'--grid-point-max-iterations', '--grid-point-max-iterations',
...@@ -391,8 +391,10 @@ def ldicParser(parser): ...@@ -391,8 +391,10 @@ def ldicParser(parser):
# Catch 3D options # Catch 3D options
if len(args.NS) == 1: if len(args.NS) == 1:
args.NS = [args.NS[0], args.NS[0], args.NS[0]] args.NS = [args.NS[0], args.NS[0], args.NS[0]]
if len(args.HWS) == 1: if len(args.HWS) == 1:
args.HWS = [args.HWS[0], args.HWS[0], args.HWS[0]] args.HWS = [args.HWS[0], args.HWS[0], args.HWS[0]]
if len(args.GRID_POINT_MARGIN) == 1: if len(args.GRID_POINT_MARGIN) == 1:
args.GRID_POINT_MARGIN = [args.GRID_POINT_MARGIN[0], args.GRID_POINT_MARGIN[0], args.GRID_POINT_MARGIN[0]] args.GRID_POINT_MARGIN = [args.GRID_POINT_MARGIN[0], args.GRID_POINT_MARGIN[0], args.GRID_POINT_MARGIN[0]]
......
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