Vous avez reçu un message "Your GitLab account has been locked ..." ? Pas d'inquiétude : lisez cet article https://docs.gricad-pages.univ-grenoble-alpes.fr/help/unlock/

Commit 847e927e authored by Edward Andò's avatar Edward Andò
Browse files

Resolves issue #177 -- registerMultiscale handles im1mask and check on returnStatus

parent 378cc4ed
Pipeline #49349 passed with stages
in 23 minutes and 22 seconds
......@@ -309,14 +309,12 @@ class TestFunctionDVC(unittest.TestCase):
for i in range(3):
self.assertAlmostEqual(t2[c][i] - t[c][i], 0, places=1)
# Check translation example with translation guess
t = {'t': [4.0, 0, 0],
'r': [0.0, 0, 0]}
Phi = spam.deformation.computePhi(t)
imDef = spam.DIC.applyPhi(im, Phi=Phi)
reg3 = spam.DIC.registerMultiscale(im, imDef, 2, deltaPhiMin=0.00001, margin=4, PhiInit=Phi)
reg3 = spam.DIC.registerMultiscale(im, imDef, 2, deltaPhiMin=0.00001, margin=10, PhiInit=Phi)
t3 = spam.deformation.decomposePhi(reg3['Phi'])
for c in ['t', 'r']:
for i in range(3):
......@@ -330,7 +328,7 @@ class TestFunctionDVC(unittest.TestCase):
# 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'])
t5 = spam.deformation.decomposePhi(reg5['Phi'])
for c in ['t', 'r']:
for i in range(3):
self.assertAlmostEqual(t5[c][i] - t[c][i], 0, places=1)
......@@ -342,6 +340,17 @@ class TestFunctionDVC(unittest.TestCase):
for i in range(3):
self.assertAlmostEqual(t6[c][i] - t[c][i], 0, places=1)
# Test for an im1 mask:
im1mask = numpy.ones_like(im, dtype=bool)
im1mask[0:2] = False
im1mask[-2::] = False
reg7 = spam.DIC.registerMultiscale(im, imDef, 2, im1mask=im1mask, margin=8, PhiInit=spam.deformation.computePhi({'t': [5,0,0]}), PhiInitBinRatio=2)
t7 = spam.deformation.decomposePhi(reg7['Phi'])
for c in ['t', 'r']:
for i in range(3):
self.assertAlmostEqual(t7[c][i] - t[c][i], 0, places=1)
def test_pixelSearch(self):
tVector = numpy.random.randint(1, 4, 3)
# print("test_pixelSearch(): initial random displacement:", tVector)
......
......@@ -99,7 +99,7 @@ def register(im1, im2, im1mask=None, PhiInit=None, PhiRigid=False, PhiInitBinRat
Get to know what the function is really thinking, recommended for debugging only.
Default = False
imShowProgress : Bool, optional
imShowProgress : bool, optional
Pop up a window showing a ``imShowProgress`` slice of the image differences (im1-im2) as im1 is progressively deformed.
Default = False
......@@ -541,7 +541,7 @@ def register(im1, im2, im1mask=None, PhiInit=None, PhiRigid=False, PhiInitBinRat
def registerMultiscale( im1, im2, binMax, PhiInit=None, PhiInitBinRatio=1.0, margin=None, maxIterations=100, deltaPhiMin=0.0001, updateGradient=False, interpolationOrder=1, interpolator='C', verbose=False, imShowProgress=None):
def registerMultiscale(im1, im2, binMax, im1mask=None, PhiInit=None, PhiInitBinRatio=1.0, margin=None, maxIterations=100, deltaPhiMin=0.0001, updateGradient=False, interpolationOrder=1, interpolator='C', verbose=False, imShowProgress=False, forceChangeScale=False):
"""
Perform multiscale subpixel image correlation between im1 and im2.
......@@ -601,9 +601,13 @@ def registerMultiscale( im1, im2, binMax, PhiInit=None, PhiInitBinRatio=1.0, mar
verbose : bool, optional
Get to know what the function is really thinking, recommended for debugging only. Default = False
imShowProgress : String, optional (default = None)
imShowProgress : bool, optional
Pop up a window showing a ``imShowProgress`` slice of the image differences (im1-im2) as im1 is progressively deformed.
Accepted options are "Z", "Y" and "X" -- the slicing direction.
Default = False
forceChangeScale : bool, optional
Change up a scale even if not converged?
Default = False
Returns
-------
......@@ -631,6 +635,7 @@ def registerMultiscale( im1, im2, binMax, PhiInit=None, PhiInitBinRatio=1.0, mar
'iterations': int
Number of iterations
"""
import math
l = math.log(binMax, 2)
if not l.is_integer():
......@@ -646,6 +651,9 @@ def registerMultiscale( im1, im2, binMax, PhiInit=None, PhiInitBinRatio=1.0, mar
PhiInit[0:3, -1] *= PhiInitBinRatio/2.0/float(binMax)
reg = {'Phi': PhiInit}
if im1mask is not None:
# Multiply up to 100 so we can apply a threshold below on binning in %
im1mask = im1mask.astype('<u1')*100
binLevel = int(binMax)
while binLevel > 0.5:
......@@ -653,9 +661,19 @@ def registerMultiscale( im1, im2, binMax, PhiInit=None, PhiInitBinRatio=1.0, mar
if binLevel > 1:
im1b = spam.DIC.binning(im1, binLevel)
im2b = spam.DIC.binning(im2, binLevel)
if im1mask is not None:
# There is no spam binning for bool images, since it's pretty meaningless to interpolate bools...
# Low threshold of 25% (see above)
im1maskb = spam.DIC.binning(im1mask, binLevel) > 0
else:
im1maskb = None
else:
im1b = im1
im2b = im2
if im1mask is not None:
im1maskb = im1mask > 0
else:
im1maskb = None
# Automatically calculate margin if none is passed
# Detect default case and calculate maring necessary for a 45deg rotation with no displacement
......@@ -671,7 +689,9 @@ def registerMultiscale( im1, im2, binMax, PhiInit=None, PhiInitBinRatio=1.0, mar
margin = [margin] * 3
marginB = (numpy.array(margin)//binLevel).tolist()
reg = spam.DIC.register(im1b, im2b, PhiInit=reg['Phi'], PhiInitBinRatio=2.0,
reg = spam.DIC.register(im1b, im2b,
im1mask = im1maskb,
PhiInit=reg['Phi'], PhiInitBinRatio=2.0,
margin=marginB,
maxIterations=maxIterations, deltaPhiMin=deltaPhiMin,
updateGradient=updateGradient,
......@@ -679,6 +699,10 @@ def registerMultiscale( im1, im2, binMax, PhiInit=None, PhiInitBinRatio=1.0, mar
verbose=verbose,
imShowProgress=imShowProgress)
if reg['returnStatus'] != 2 and not forceChangeScale:
print("spam.DIC.registerMultiscale(): binning {} did not converge (return Status = {}), not continuing".format(binLevel, reg['returnStatus']))
return
binLevel = int(binLevel/2)
return reg
......
Markdown is supported
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