Commit 9d39910c authored by Edward Andò's avatar Edward Andò
Browse files

[skip-ci] work on applyPhiField

parent 25734c8f
Pipeline #68157 skipped
......@@ -72,11 +72,9 @@ if TSV['PhiField'].shape[0] == 1:
imdef = spam.DIC.applyPhi(im, Phi=Phi)
else:
# Define a linear mask for points
mask = numpy.zeros(TSV['fieldCoords'].shape[0], dtype=bool)
# Accept points that have converged
mask[TSV['returnStatus']==2] = True
# Accept points based on return stat
mask = TSV["returnStatus"] >= args.RETURN_STATUS_THRESHOLD
print(f"\nspam-deformImage: excluding points based on return threshold < {args.RETURN_STATUS_THRESHOLD} (excluded {100*(1-numpy.mean(mask)):2.1f}%)")
if args.RADIUS is not None:
# Also exclude based on radius
......@@ -88,7 +86,7 @@ else:
r = numpy.sqrt( numpy.square(x) + numpy.square(y))
mask[r > args.RADIUS] = False
print("Proportion of correlation points included {:0.0f}%".format(100*(mask.sum()/(len(mask)-1))))
#print("Proportion of correlation points included {:0.0f}%".format(100*(mask.sum()/(len(mask)-1))))
# update points
points = TSV['fieldCoords'][mask]
......
......@@ -262,17 +262,22 @@ def applyPhiField(im, fieldName=None, fieldCoords=None, fieldValues=None, fieldB
# Deform the coordinates of the current point
# by subtracting the translation part of the deformation function Phi
coordNew -= fieldValues[indices][numpy.where(distance == 0)][0][0:3, -1].copy()
#coordNew -= fieldValues[indices][numpy.where(distance == 0)][0][0:3, -1].copy()
try:
coordNew += numpy.linalg.inv(fieldValues[indices][numpy.where(distance == 0)][0])[0:3, -1]
except:
coordNew = numpy.zeros(3)
# Check if we have asked only for the closest neighbour
elif neighbours == 1:
# Deform the coordinates of the current point
# by subtracting the translation part of the deformation function Phi
# applied on the current point
coordNew -= spam.deformation.decomposePhi(fieldValues[indices].copy(),
PhiCentre=fieldCoords[indices],
PhiPoint=coorXdIn[point, :3])["t"]
## Check if we have asked only for the closest neighbour
#elif neighbours == 1:
## Deform the coordinates of the current point
## by subtracting the translation part of the deformation function Phi
## applied on the current point
#coordNew -= spam.deformation.decomposePhi(fieldValues[indices].copy(),
#PhiCentre=fieldCoords[indices],
#PhiPoint=coorXdIn[point, :3])["t"]
# Consider the k closest neighbours
else:
......@@ -288,11 +293,17 @@ def applyPhiField(im, fieldName=None, fieldCoords=None, fieldValues=None, fieldB
# by subtracting the translation part of the deformation function Phi
# applied on the current point
# multiplied by the weight of each neighbour
coordNew -= numpy.dot(spam.deformation.decomposePhi(fieldValues[indices][neighbour].copy(),
#coordNew -= numpy.dot(spam.deformation.decomposePhi(fieldValues[indices][neighbour].copy(),
#PhiCentre=fieldCoords[indices][neighbour],
#PhiPoint=coordIn[point, :3])["t"],
#weightInv)
try:
coordNew += numpy.dot(spam.deformation.decomposePhi(numpy.linalg.inv(fieldValues[indices][neighbour].copy()),
PhiCentre=fieldCoords[indices][neighbour],
PhiPoint=coordIn[point, :3])["t"],
weightInv)
#print("coordNew", coordNew)
except:
pass
qResults.put([point, coordNew])
numberofPoints = imSize[0] * imSize[1] * imSize[2]
......
......@@ -2228,13 +2228,6 @@ def deformImageParser(parser):
type=argparse.FileType('r'),
help="Path to TSV file containing the deformation function field (required)")
parser.add_argument('-rad',
'--radius-limit',
type=float,
default=None,
dest='RADIUS',
help='Assume a sample which is a cylinder with the axis in the z-direction. Exclude points outside a given radius. Use Default = None')
parser.add_argument('-pfb',
'--phiFile-bin-ratio',
type=float,
......@@ -2242,6 +2235,20 @@ def deformImageParser(parser):
dest='PHIFILE_BIN_RATIO',
help="Ratio of binning level between loaded Phi file and current calculation. If the input Phi file has been obtained on a 500x500x500 image and now the calculation is on 1000x1000x1000, this should be 2. Default = 1")
parser.add_argument('-rst',
'--return-status-threshold',
type=int,
default=2,
dest='RETURN_STATUS_THRESHOLD',
help='Lowest return status value to preserve in input PhiField. Default = 2')
parser.add_argument('-rad',
'--radius-limit',
type=float,
default=None,
dest='RADIUS',
help='Assume a sample which is a cylinder with the axis in the z-direction. Exclude points outside a given radius. Use Default = None')
parser.add_argument('-od',
'--out-dir',
type=str,
......
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