Commit 69f8675e authored by Edward Andò's avatar Edward Andò
Browse files

new ddic script: lc options instead of gp; gradient update; debug mode;...

new ddic script: lc options instead of gp; gradient update; debug mode; applyPhi nicely for pixel search
parent f94ea529
Pipeline #47832 failed with stages
in 11 minutes and 45 seconds
......@@ -345,7 +345,7 @@ if mpiRank == boss or not mpi:
extractCube=False,
boundingBoxes=boundingBoxes,
centresOfMass=centresOfMass,
margin=labelDilateCurrent + args.GRID_POINT_MARGIN,
margin=labelDilateCurrent + args.LABEL_CORRELATE_MARGIN,
maskOtherLabels=args.MASK,
labelDilate=labelDilateCurrent)
......@@ -382,12 +382,12 @@ if mpiRank == boss or not mpi:
(searchRangeForThisLabel['xRange'][0] + searchRangeForThisLabel['xRange'][1])/2] ).astype(int)
# Slice for image 2
subVolSlice2 = (slice(max(int(boundingBoxes[label][0] - max(labelDilateCurrent, 0) - args.GRID_POINT_MARGIN + searchRangeForThisLabel['zRange'][0]), 0),
min(int(boundingBoxes[label][1] + max(labelDilateCurrent, 0) + args.GRID_POINT_MARGIN + searchRangeForThisLabel['zRange'][1] + 1), im1.shape[0])),
slice(max(int(boundingBoxes[label][2] - max(labelDilateCurrent, 0) - args.GRID_POINT_MARGIN + searchRangeForThisLabel['yRange'][0]), 0),
min(int(boundingBoxes[label][3] + max(labelDilateCurrent, 0) + args.GRID_POINT_MARGIN + searchRangeForThisLabel['yRange'][1] + 1), im1.shape[1])),
slice(max(int(boundingBoxes[label][4] - max(labelDilateCurrent, 0) - args.GRID_POINT_MARGIN + searchRangeForThisLabel['xRange'][0]), 0),
min(int(boundingBoxes[label][5] + max(labelDilateCurrent, 0) + args.GRID_POINT_MARGIN + searchRangeForThisLabel['xRange'][1] + 1), im1.shape[2])))
subVolSlice2 = (slice(max(int(boundingBoxes[label][0] - max(labelDilateCurrent, 0) - args.LABEL_CORRELATE_MARGIN + searchRangeForThisLabel['zRange'][0]), 0),
min(int(boundingBoxes[label][1] + max(labelDilateCurrent, 0) + args.LABEL_CORRELATE_MARGIN + searchRangeForThisLabel['zRange'][1] + 1), im1.shape[0])),
slice(max(int(boundingBoxes[label][2] - max(labelDilateCurrent, 0) - args.LABEL_CORRELATE_MARGIN + searchRangeForThisLabel['yRange'][0]), 0),
min(int(boundingBoxes[label][3] + max(labelDilateCurrent, 0) + args.LABEL_CORRELATE_MARGIN + searchRangeForThisLabel['yRange'][1] + 1), im1.shape[1])),
slice(max(int(boundingBoxes[label][4] - max(labelDilateCurrent, 0) - args.LABEL_CORRELATE_MARGIN + searchRangeForThisLabel['xRange'][0]), 0),
min(int(boundingBoxes[label][5] + max(labelDilateCurrent, 0) + args.LABEL_CORRELATE_MARGIN + searchRangeForThisLabel['xRange'][1] + 1), im1.shape[2])))
# Extract it...
imagette2 = im2[subVolSlice2]
......@@ -403,12 +403,12 @@ if mpiRank == boss or not mpi:
# Deform imagette1, using relative COM as point of application
imagette1def = spam.DIC.applyPhi(imagette1, PhiNoDisp, PhiPoint=getLabel['centreOfMassREL'])
imagette1defCrop = imagette1def[args.GRID_POINT_MARGIN:-args.GRID_POINT_MARGIN,
args.GRID_POINT_MARGIN:-args.GRID_POINT_MARGIN, # This is to remove edge artefacts of applyPhi
args.GRID_POINT_MARGIN:-args.GRID_POINT_MARGIN]
imagette1crop = imagette1[args.GRID_POINT_MARGIN:-args.GRID_POINT_MARGIN,
args.GRID_POINT_MARGIN:-args.GRID_POINT_MARGIN, # This is to remove edge artefacts of applyPhi
args.GRID_POINT_MARGIN:-args.GRID_POINT_MARGIN]
#imagette1defCrop = imagette1def[args.LABEL_CORRELATE_MARGIN:-args.LABEL_CORRELATE_MARGIN,
#args.LABEL_CORRELATE_MARGIN:-args.LABEL_CORRELATE_MARGIN, # This is to remove edge artefacts of applyPhi
#args.LABEL_CORRELATE_MARGIN:-args.LABEL_CORRELATE_MARGIN]
#imagette1crop = imagette1[args.LABEL_CORRELATE_MARGIN:-args.LABEL_CORRELATE_MARGIN,
#args.LABEL_CORRELATE_MARGIN:-args.LABEL_CORRELATE_MARGIN, # This is to remove edge artefacts of applyPhi
#args.LABEL_CORRELATE_MARGIN:-args.LABEL_CORRELATE_MARGIN]
if args.MASK:
imagette1toCorrelate = imagette1def.copy()
......@@ -456,15 +456,15 @@ if mpiRank == boss or not mpi:
print("Phi after pixel search:\n", PhiField[label])
if args.GRID_POINT:
if args.LABEL_CORRELATE:
labelDisplacementInt = numpy.round(PhiField[label][0:3, -1])
slicette2 = (slice(max(int(boundingBoxes[label][0] - args.GRID_POINT_MARGIN - max(labelDilateCurrent, 0) + labelDisplacementInt[0] ), 0 ),
min(int(boundingBoxes[label][1] + args.GRID_POINT_MARGIN + max(labelDilateCurrent, 0) + labelDisplacementInt[0] + 1), im1.shape[0])),
slice(max(int(boundingBoxes[label][2] - args.GRID_POINT_MARGIN - max(labelDilateCurrent, 0) + labelDisplacementInt[1] ), 0 ),
min(int(boundingBoxes[label][3] + args.GRID_POINT_MARGIN + max(labelDilateCurrent, 0) + labelDisplacementInt[1] + 1), im1.shape[1])),
slice(max(int(boundingBoxes[label][4] - args.GRID_POINT_MARGIN - max(labelDilateCurrent, 0) + labelDisplacementInt[2] ), 0 ),
min(int(boundingBoxes[label][5] + args.GRID_POINT_MARGIN + max(labelDilateCurrent, 0) + labelDisplacementInt[2] + 1), im1.shape[2])))
slicette2 = (slice(max(int(boundingBoxes[label][0] - args.LABEL_CORRELATE_MARGIN - max(labelDilateCurrent, 0) + labelDisplacementInt[0] ), 0 ),
min(int(boundingBoxes[label][1] + args.LABEL_CORRELATE_MARGIN + max(labelDilateCurrent, 0) + labelDisplacementInt[0] + 1), im1.shape[0])),
slice(max(int(boundingBoxes[label][2] - args.LABEL_CORRELATE_MARGIN - max(labelDilateCurrent, 0) + labelDisplacementInt[1] ), 0 ),
min(int(boundingBoxes[label][3] + args.LABEL_CORRELATE_MARGIN + max(labelDilateCurrent, 0) + labelDisplacementInt[1] + 1), im1.shape[1])),
slice(max(int(boundingBoxes[label][4] - args.LABEL_CORRELATE_MARGIN - max(labelDilateCurrent, 0) + labelDisplacementInt[2] ), 0 ),
min(int(boundingBoxes[label][5] + args.LABEL_CORRELATE_MARGIN + max(labelDilateCurrent, 0) + labelDisplacementInt[2] + 1), im1.shape[2])))
#print(slicette1)
#print(slicette2)
......@@ -485,9 +485,11 @@ if mpiRank == boss or not mpi:
im1mask=maskette1,
margin=1,
PhiInit=PhiTemp,
maxIterations=args.GRID_POINT_MAX_ITERATIONS,
deltaPhiMin=args.GRID_POINT_MIN_PHI_CHANGE,
interpolationOrder=args.GRID_POINT_INTERPOLATION_ORDER,
PhiRigid=args.LABEL_CORRELATE_RIGID,
updateGradient=args.LABEL_CORRELATE_UPDATE_GRADIENT,
maxIterations=args.LABEL_CORRELATE_MAX_ITERATIONS,
deltaPhiMin=args.LABEL_CORRELATE_MIN_PHI_CHANGE,
interpolationOrder=args.LABEL_CORRELATE_INTERPOLATION_ORDER,
verbose=args.DEBUG,
imShowProgress='Z' if args.DEBUG else None)
writeReturns = True
......@@ -499,10 +501,12 @@ if mpiRank == boss or not mpi:
'im2': im2[slicette2],
'im1mask': maskette1,
'PhiInit': PhiTemp,
'PhiRigid': args.LABEL_CORRELATE_RIGID,
'updateGradient': args.LABEL_CORRELATE_UPDATE_GRADIENT,
'margin': 1, # see top of this file for compensation
'maxIterations': args.GRID_POINT_MAX_ITERATIONS,
'deltaPhiMin': args.GRID_POINT_MIN_PHI_CHANGE,
'interpolationOrder': args.GRID_POINT_INTERPOLATION_ORDER,
'maxIterations': args.LABEL_CORRELATE_MAX_ITERATIONS,
'deltaPhiMin': args.LABEL_CORRELATE_MIN_PHI_CHANGE,
'interpolationOrder': args.LABEL_CORRELATE_INTERPOLATION_ORDER,
'labelDisplacementInt': labelDisplacementInt,
'writeReturns': writeReturns,
'labelDilate': labelDilateCurrent
......@@ -519,7 +523,7 @@ if mpiRank == boss or not mpi:
print("\t\tBoss: Fail imDiff", imagette2imagette1sizeDiff)
grainOK = True
else: # No args.GRID_POINT
else: # No args.LABEL_CORRELATE
finishedLabels += 1
grainOK = True
......@@ -665,6 +669,8 @@ elif mpi: # We are not the mpi boss, so we are a lukasKanade worker
m['im2'],
im1mask=m['im1mask'],
PhiInit=m['PhiInit'],
PhiRigid=m['PhiRigid'],
updateGradient=m['updateGradient'],
margin=m['margin'],
maxIterations=m['maxIterations'],
deltaPhiMin=m['deltaPhiMin'],
......
......@@ -262,6 +262,17 @@ class TestFunctionDVC(unittest.TestCase):
self.assertAlmostEqual(numpy.array(returns7['transformation']["t"][i]), 0, places=1)
self.assertAlmostEqual(numpy.array(returns7['transformation']["r"][i]) - [rot, 0, 0][i], 0, places=1)
# CASE 7b: lasrge rot and only rigid
returns7b = spam.DIC.register(im, imDef, margin=10, PhiInit=PhiGuess, PhiRigid=True)
self.assertEqual(returns7b['returnStatus'], 2)
returns7b['transformation'] = spam.deformation.decomposePhi(returns7b['Phi'])
for i in range(3):
self.assertAlmostEqual(numpy.array(returns7b['transformation']["t"][i]), 0, places=1)
self.assertAlmostEqual(numpy.array(returns7b['transformation']["r"][i]) - [rot, 0, 0][i], 0, places=1)
# Check that it's rigid!!
self.assertAlmostEqual(numpy.linalg.norm(numpy.array(returns7b['transformation']["U"])-numpy.eye(3)), 0, places=4)
# CASE 8: 3D case with large initial rotation (say 120 deg) with gradient update, should need fewer iterations
rot = 120
Phi = spam.deformation.computePhi({'r': [rot, 0, 0]})
......@@ -298,7 +309,9 @@ class TestFunctionDVC(unittest.TestCase):
for i in range(3):
self.assertAlmostEqual(t2[c][i] - t[c][i], 0, places=1)
# Check transaltion example with translation guess
# Check translation example with translation guess
t = {'t': [4.0, 0, 0],
'r': [0.0, 0, 0]}
Phi = spam.deformation.computePhi(t)
......@@ -315,7 +328,7 @@ class TestFunctionDVC(unittest.TestCase):
for i in range(3):
self.assertAlmostEqual(t4[c][i] - t[c][i], 0, places=1)
# check graident update
# check gradient update
reg5 = spam.DIC.registerMultiscale(im, imDef, 2, margin=8, PhiInit=spam.deformation.computePhi({'t': [5,0,0]}), PhiInitBinRatio=2, updateGradient=True)
t5 = spam.deformation.decomposePhi(reg4['Phi'])
for c in ['t', 'r']:
......
......@@ -461,11 +461,11 @@ def ddicParser(parser):
dest='PSR',
help='Z- Z+ Y- Y+ X- X+ ranges (in pixels) for the pxiel search. Requires pixel search to be activated. Default = +-3px')
parser.add_argument('-nogp',
'--no-grid-point',
parser.add_argument('-nolc',
'--no-label-correlation',
action="store_false",
dest='GRID_POINT',
help='Disactivate grid-point registration?')
dest='LABEL_CORRELATE',
help='Disactivate label registration?')
parser.add_argument('-ld',
'--label-dilate',
......@@ -534,7 +534,6 @@ def ddicParser(parser):
dest='PHIFILE_BIN_RATIO',
help="Ratio of binning level between loaded F file and current calculation. If the input F file has been obtained on a 500x500x500 image and now the calculation is on 1000x1000x1000, this should be 2. Default = 1")
parser.add_argument('-pfd',
'--phiFile-direct',
action="store_true",
......@@ -561,34 +560,46 @@ def ddicParser(parser):
dest='MASK',
help='Don\'t mask each label\'s image')
parser.add_argument('-gpm',
'--grid-point-margin',
parser.add_argument('-lcm',
'--label-correlate-margin',
type=numpy.uint,
default=2,
dest='GRID_POINT_MARGIN',
default=5,
dest='LABEL_CORRELATE_MARGIN',
help="Margin in pixels for grid-point registration to be added to label dilate. Default = 2px")
parser.add_argument('-gpi',
'--grid-point-max-iterations',
parser.add_argument('-lci',
'--label-correlate-max-iterations',
type=numpy.uint,
default=50,
dest='GRID_POINT_MAX_ITERATIONS',
dest='LABEL_CORRELATE_MAX_ITERATIONS',
help="Maximum iterations for grid-point registration. Default = 50")
parser.add_argument('-gpp',
'--grid-point-min-phi-change',
parser.add_argument('-lcp',
'--label-correlate-min-phi-change',
type=numpy.float,
default=0.001,
dest='GRID_POINT_MIN_PHI_CHANGE',
dest='LABEL_CORRELATE_MIN_PHI_CHANGE',
help="Minimum change in Phi to consider grid-point registration as converged. Default = 0.001")
parser.add_argument('-gpo',
'--grid-point-interpolation-order',
parser.add_argument('-lco',
'--label-correlate-interpolation-order',
type=numpy.uint,
default=1,
dest='GRID_POINT_INTERPOLATION_ORDER',
dest='LABEL_CORRELATE_INTERPOLATION_ORDER',
help="Interpolation order for grid-point registration. Default = 3")
parser.add_argument('-lnr',
'--label-correlate-non-rigid',
action="store_false",
dest='LABEL_CORRELATE_RIGID',
help='Activate non-rigid registration for each label')
parser.add_argument('-lcug',
'--label-correlate-update-gradient',
action="store_true",
dest='LABEL_CORRELATE_UPDATE_GRADIENT',
help='Update gradient in label registration? More computation time but more robust and possibly fewer iterations. Default = False')
parser.add_argument('-od',
'--out-dir',
type=str,
......
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