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

finally passes the tests again!

parent 5213bd6c
Pipeline #60279 passed with stages
in 13 minutes and 26 seconds
......@@ -122,7 +122,7 @@ if args.PHIFILE is not None:
# 2. by calling the decomposePhi function to compute the translation of each point
for label in range(numberOfLabels):
PhiField[label] = PhiInit.copy()
PhiField[label][0:3, -1] = spam.deformation.decomposePhi(PhiInit.copy(), PhiCentre=PhiFromFile["fieldCoords"][0], PhiPoint=labelPositions[label])["t"]
PhiField[label][0:3, -1] = spam.deformation.decomposePhi(PhiInit.copy(), PhiCentre=PhiFromFile["fieldCoords"][0], PhiPoint=centresOfMass[label])["t"]
## Now recompute F to be only rigid, and calculate rigid-body translations for each point
#if args.REGSUB:
......@@ -333,7 +333,7 @@ outMatrix = numpy.array([numpy.array(range(numberOfLabels)),
error, iterations, returnStatus, deltaPhiNorm,
labelDilateList]).T
numpy.savetxt(args.OUT_DIR + "/" + args.PREFIX + "-discreteDVC.tsv",
numpy.savetxt(args.OUT_DIR + "/" + args.PREFIX + "-ddic.tsv",
outMatrix,
fmt='%.7f',
delimiter='\t',
......@@ -378,4 +378,4 @@ VTKglyphDict = {'displacements': PhiField[:, 0:3, -1],
#"Fxz\tFxy\tFxx\t" +
#"PSCC\terror\titerations\treturnStatus\tdeltaPhiNorm\tLabelDilate")
spam.helpers.writeGlyphsVTK(centresOfMass, VTKglyphDict, fileName=args.OUT_DIR + "/" + args.PREFIX + "-discreteDVC.vtk")
spam.helpers.writeGlyphsVTK(centresOfMass, VTKglyphDict, fileName=args.OUT_DIR + "/" + args.PREFIX + "-ddic.vtk")
This diff is collapsed.
......@@ -527,7 +527,7 @@ def decomposePhiField(PhiField, components, twoD=False):
return output
def correctPhiField(fileName=None, fieldCoords=None, fieldValues=None, fieldRS=None, fieldDPhi=None, fieldPSCC=None, fieldIT=None, fieldBinRatio=1.0, ignoreBadPoints=False, ignoreBackGround=False, correctBadPoints=False, deltaPhiNormMin=0.001, pixelSearchCCmin=0.98, nNeighbours=12, filterPoints=False, filterPointsRadius=3, verbose=False, saveFile=False, saveFileName=None):
def correctPhiField(fileName=None, fieldCoords=None, fieldValues=None, fieldRS=None, fieldDPhi=None, fieldPixelSearchCC=None, fieldIT=None, fieldBinRatio=1.0, ignoreBadPoints=False, ignoreBackGround=False, correctBadPoints=False, deltaPhiNormMin=0.001, pixelSearchCCmin=0.98, nNeighbours=12, filterPoints=False, filterPointsRadius=3, verbose=False, saveFile=False, saveFileName=None):
"""
This function corrects a field of deformation functions **Phi** calculated at a number of points.
This is typically the output of the DICdiscrete and DICregularGrid clients.
......@@ -569,7 +569,7 @@ def correctPhiField(fileName=None, fieldCoords=None, fieldValues=None, fieldRS=N
fieldIT : 1D array, optional
nx1 array of n points `iterations` from the correlation
fieldPSCC : 1D array, optional
fieldPixelSearchCC : 1D array, optional
nx1 array of n points `PScorrelationCoefficient` from the correlation
fieldBinRatio : int, optional
......@@ -641,21 +641,21 @@ def correctPhiField(fileName=None, fieldCoords=None, fieldValues=None, fieldRS=N
return
else:
import spam.helpers.tsvio
fi = spam.helpers.tsvio.readCorrelationTSV(fileName, fieldBinRatio=fieldBinRatio, readConvergence=True, readPSCC=True)
fi = spam.helpers.tsvio.readCorrelationTSV(fileName, fieldBinRatio=fieldBinRatio, readConvergence=True, readPixelSearchCC=True)
PhiField = fi["PhiField"]
fieldCoords = fi["fieldCoords"]
fieldDims = fi["fieldDims"]
RS = fi["returnStatus"]
deltaPhiNorm = fi["deltaPhiNorm"]
iterations = fi["iterations"]
PSCC = fi["PSCC"]
elif fieldCoords is not None and fieldValues is not None and fieldRS is not None and fieldDPhi is not None and fieldPSCC is not None and fieldIT is not None:
PSCC = fi["pixelSearchCC"]
elif fieldCoords is not None and fieldValues is not None and fieldRS is not None and fieldDPhi is not None and fieldPixelSearchCC is not None and fieldIT is not None:
fieldCoords = fieldCoords
fieldDims = numpy.array([len(numpy.unique(fieldCoords[:, 0])), len(numpy.unique(fieldCoords[:, 1])), len(numpy.unique(fieldCoords[:, 2]))])
PhiField = fieldValues
RS = fieldRS
deltaPhiNorm = fieldDPhi
PSCC = fieldPSCC
PSCC = fieldPixelSearchCC
iterations = fieldIT
else:
print("\tdeformationFunction.correctPhiField(): Not enough arguments given. Exiting.")
......
......@@ -225,11 +225,11 @@ def ldicParser(parser):
dest='VTK',
help='Activate VTK output format. Default = False')
parser.add_argument('-tsv',
'--TSVout',
parser.add_argument('-notsv',
'--noTSV',
action="store_false",
dest='TSV',
help='Activate TSV output format. Default = True')
help='Disactivate TSV output format. Default = True')
parser.add_argument('-tif',
'-tiff',
......@@ -370,12 +370,12 @@ def ddicParser(parser):
dest='LABEL_DILATE',
help="Number of times to dilate labels. Default = 1")
parser.add_argument('-ldmax',
'--label-dilate-maximum',
type=int,
default=None,
dest='LABEL_DILATE_MAX',
help="Maximum dilation for label if they don't converge with -ld setting. Default = same as -ld setting")
#parser.add_argument('-ldmax',
#'--label-dilate-maximum',
#type=int,
#default=None,
#dest='LABEL_DILATE_MAX',
#help="Maximum dilation for label if they don't converge with -ld setting. Default = same as -ld setting")
parser.add_argument('-vt',
'--volume-threshold',
......@@ -534,13 +534,13 @@ def ddicParser(parser):
if args.PREFIX is None:
args.PREFIX = os.path.splitext(os.path.basename(args.im1.name))[0] + "-" + os.path.splitext(os.path.basename(args.im2.name))[0]
# Set label dilate max as label dilate if it is none
if args.LABEL_DILATE_MAX is None:
args.LABEL_DILATE_MAX = args.LABEL_DILATE
## Set label dilate max as label dilate if it is none
#if args.LABEL_DILATE_MAX is None:
#args.LABEL_DILATE_MAX = args.LABEL_DILATE
if args.LABEL_DILATE_MAX < args.LABEL_DILATE:
print("spam-ddic: Warning \"label dilate max\" is less than \"label dilate\" setting them equal")
args.LABEL_DILATE_MAX = args.LABEL_DILATE
#if args.LABEL_DILATE_MAX < args.LABEL_DILATE:
#print("spam-ddic: Warning \"label dilate max\" is less than \"label dilate\" setting them equal")
#args.LABEL_DILATE_MAX = args.LABEL_DILATE
if args.DEBUG:
print("spam-ddic: DEBUG mode activated, forcing number of processes to 1")
......
......@@ -106,7 +106,7 @@ class TestFunctionDVC(unittest.TestCase):
f1b = spam.deformation.correctPhiField(fileName=None,
fieldCoords=fieldCoords, fieldValues=PhiField.copy(),
fieldRS=RS.copy(), fieldDPhi=DPhi.copy(),
fieldPSCC=numpy.zeros_like(RS), fieldIT=IT,
fieldPixelSearchCC=numpy.zeros_like(RS), fieldIT=IT,
ignoreBadPoints=True, correctBadPoints=False, saveFile=False)
self.assertEqual(PhiField[:, 0:3, -1].sum() - 3, numpy.nansum(f1b[:, 0:3, -1]))
......@@ -114,7 +114,7 @@ class TestFunctionDVC(unittest.TestCase):
f1c = spam.deformation.correctPhiField(fileName=None,
fieldCoords=fieldCoords, fieldValues=PhiField,
fieldRS=RS, fieldDPhi=numpy.full((fieldCoords.shape[0]), 100),
fieldPSCC=numpy.ones_like(RS), fieldIT=IT,
fieldPixelSearchCC=numpy.ones_like(RS), fieldIT=IT,
ignoreBadPoints=True, correctBadPoints=False, saveFile=False)
self.assertEqual(PhiField[:, 0:3, -1].sum(), f1c[:, 0:3, -1].sum())
......@@ -136,7 +136,7 @@ class TestFunctionDVC(unittest.TestCase):
PSCC[badPoint] = 0.1
f3b = spam.deformation.correctPhiField(fieldCoords=fieldCoords, fieldValues=PhiField.copy(),
fieldRS=RS, fieldDPhi=numpy.full((fieldCoords.shape[0]), 100),
fieldPSCC=PSCC, fieldIT=IT,
fieldPixelSearchCC=PSCC, fieldIT=IT,
correctBadPoints=True, ignoreBackGround=True,
verbose=True, saveFile=True)
self.assertEqual(numpy.nansum(f3b[:, 0:3, -1]), (fieldCoords.shape[0] - 2) * 3)
......@@ -415,59 +415,6 @@ class TestFunctionDVC(unittest.TestCase):
nodePositions, nodesDim2D = spam.DIC.grid.makeGrid((1, 50, 50), 10)
self.assertEqual((1, 4, 4), nodesDim2D)
def test_registerOnGrid(self):
im = spam.datasets.loadSnow()
nodePositions = spam.DIC.grid.makeGrid(im.shape, 20)[0]
Phi = spam.deformation.computePhi({'t': [0, 2, 1]})
imDef = spam.DIC.applyPhi(im, Phi=Phi)
PhiField = numpy.zeros((nodePositions.shape[0], 4, 4))
PhiField[:] = numpy.eye(4)
PhiField[:, 1, -1] = 2
PhiField[:, 2, -1] = 1
subPix = spam.DIC.registerOnGrid(im, imDef,
nodePositions, 10,
PhiField=PhiField,
margin=1,
maxIterations=100,
deltaPhiMin=0.001,
interpolationOrder=1,
minMaskCoverage=0.5, im1mask=numpy.ones_like(im),
greyThreshold=[-numpy.inf, numpy.inf])
self.assertEqual(subPix["PhiField"][:, 0, -1].sum(), 0)
self.assertEqual(subPix["PhiField"][:, 1, -1].sum(), nodePositions.shape[0] * 2)
self.assertEqual(subPix["PhiField"][:, 2, -1].sum(), nodePositions.shape[0])
self.assertEqual(subPix["returnStatus"].sum(), nodePositions.shape[0] * 2)
# check 2d + threshold + python interpolator
nodePositions[:, 0] = 1
subPix2 = spam.DIC.registerOnGrid(im[25], imDef[25],
nodePositions, 10,
interpolationOrder=3,
greyThreshold=[numpy.inf, numpy.inf])
self.assertEqual(numpy.isfinite(subPix2["PhiField"][:, 0:3, -1]).sum(), 0)
for node in range(nodePositions.shape[0]):
self.assertTrue(numpy.allclose(subPix2["PhiField"][node, 0:3, 0:3], numpy.eye(3)))
self.assertEqual(subPix2["returnStatus"][node], -5)
# check nans in PhiField
PhiField[:, 0:3, -1] *= numpy.nan
subPix3 = spam.DIC.registerOnGrid(im, imDef,
nodePositions, 10,
PhiField=PhiField,
margin=1,
maxIterations=100,
deltaPhiMin=0.001,
interpolationOrder=1,
minMaskCoverage=0.5, im1mask=numpy.ones_like(im),
greyThreshold=[-numpy.inf, numpy.inf])
self.assertEqual(numpy.isfinite(subPix3["PhiField"][:, 0:3, -1]).sum(), 0)
for node in range(nodePositions.shape[0]):
self.assertTrue(numpy.allclose(subPix3["PhiField"][node, 0:3, 0:3], numpy.eye(3)))
self.assertEqual(subPix3["returnStatus"][node], -6)
def test_grid(self):
im = spam.datasets.loadSnow()
......
......@@ -25,10 +25,10 @@ class testAll(unittest.TestCase):
os.remove(testFolder+'Step0.tif')
os.remove(testFolder+'Lab0.tif')
os.remove(testFolder+'Step1.tif')
os.remove(testFolder+'Step0-Step1-bin2-registration.tsv')
os.remove(testFolder+'Step0-Step1-registration.tsv')
os.remove(testFolder+'Step0-Step1.tsv')
os.remove(testFolder+'Step0-Step1-discreteDVC.tsv')
os.remove(testFolder+'Step0-Step1-discreteDVC.vtk')
os.remove(testFolder+'Step0-Step1-ddic.tsv')
os.remove(testFolder+'Step0-Step1-ddic.vtk')
os.remove(testFolder+'merged.tsv')
except OSError:
......@@ -795,64 +795,69 @@ class testAll(unittest.TestCase):
#######################################################
### Now use the ddic and ldic
#######################################################
exitCode = subprocess.call(["spam-reg",
testFolder + "Step0.tif",
testFolder + "Step1.tif",
"-bb", "4", "-be", "2",
"-od", testFolder+""])
self.assertEqual(exitCode, 0)
exitCode = subprocess.call(["spam-ldic",
"-pf", testFolder + "Step0-Step1-registration.tsv",
"-glt", "0.5",
"-hws", "10",
"-ns", "10",
"-reg", "-regbb", "2", "-regbe", "2",
"-tsv",
"-gpi", "5",
"Step0.tif", "Step1.tif",
testFolder + "Step0.tif", testFolder + "Step1.tif",
"-od", testFolder+""])
self.assertEqual(exitCode, 0)
exitCode = subprocess.call(["spam-ddic",
"-pf", "Step0-Step1-bin2-registration.tsv", "-pfb", "2",
"-pf", testFolder + "Step0-Step1-registration.tsv",
"-ld", "2",
"Step0.tif", "Lab0.tif", "Step1.tif",
testFolder + "Step0.tif", testFolder + "Lab0.tif", testFolder + "Step1.tif",
"-od", testFolder+""])
self.assertEqual(exitCode, 0)
# With lists
spam.deformation.mergeRegularGridAndDiscrete(regularGrid=spam.helpers.readCorrelationTSV(testFolder+'Step0-Step1.tsv'),
discrete=[spam.helpers.readCorrelationTSV(testFolder+'Step0-Step1-discreteDVC.tsv')],
spam.deformation.mergeRegularGridAndDiscrete(regularGrid=spam.helpers.readCorrelationTSV(testFolder+'Step0-Step1-ldic.tsv'),
discrete=[spam.helpers.readCorrelationTSV(testFolder+'Step0-Step1-ddic.tsv')],
labelledImage=[tifffile.imread(testFolder+'Lab0.tif')],
alwaysLabel=False,
fileName=testFolder+'merged.tsv')
# Non-working options, either one list and not the other, or different sizes, catch None returns
r = spam.deformation.mergeRegularGridAndDiscrete(regularGrid=spam.helpers.readCorrelationTSV(testFolder+'Step0-Step1.tsv'),
discrete=[spam.helpers.readCorrelationTSV(testFolder+'Step0-Step1-discreteDVC.tsv')],
r = spam.deformation.mergeRegularGridAndDiscrete(regularGrid=spam.helpers.readCorrelationTSV(testFolder+'Step0-Step1-ldic.tsv'),
discrete=[spam.helpers.readCorrelationTSV(testFolder+'Step0-Step1-ddic.tsv')],
labelledImage=[tifffile.imread(testFolder+'Lab0.tif'), None],
alwaysLabel=False,
fileName=testFolder+'merged.tsv')
self.assertEqual(r is None, True)
r = spam.deformation.mergeRegularGridAndDiscrete(regularGrid=spam.helpers.readCorrelationTSV(testFolder+'Step0-Step1.tsv'),
discrete=[spam.helpers.readCorrelationTSV(testFolder+'Step0-Step1-discreteDVC.tsv')],
r = spam.deformation.mergeRegularGridAndDiscrete(regularGrid=spam.helpers.readCorrelationTSV(testFolder+'Step0-Step1-ldic.tsv'),
discrete=[spam.helpers.readCorrelationTSV(testFolder+'Step0-Step1-ddic.tsv')],
labelledImage=tifffile.imread(testFolder+'Lab0.tif'),
alwaysLabel=False,
fileName=testFolder+'merged.tsv')
self.assertEqual(r is None, True)
r = spam.deformation.mergeRegularGridAndDiscrete(regularGrid=spam.helpers.readCorrelationTSV(testFolder+'Step0-Step1.tsv'),
discrete=[spam.helpers.readCorrelationTSV(testFolder+'Step0-Step1-discreteDVC.tsv')],
r = spam.deformation.mergeRegularGridAndDiscrete(regularGrid=spam.helpers.readCorrelationTSV(testFolder+'Step0-Step1-ldic.tsv'),
discrete=[spam.helpers.readCorrelationTSV(testFolder+'Step0-Step1-ddic.tsv')],
labelledImage=None,
alwaysLabel=False,
fileName=testFolder+'merged.tsv')
self.assertEqual(r is None, True)
# This works again, no lists
output = spam.deformation.mergeRegularGridAndDiscrete(regularGrid=spam.helpers.readCorrelationTSV(testFolder+'Step0-Step1.tsv'),
discrete=spam.helpers.readCorrelationTSV(testFolder+'Step0-Step1-discreteDVC.tsv'),
output = spam.deformation.mergeRegularGridAndDiscrete(regularGrid=spam.helpers.readCorrelationTSV(testFolder+'Step0-Step1-ldic.tsv'),
discrete=spam.helpers.readCorrelationTSV(testFolder+'Step0-Step1-ddic.tsv'),
labelledImage=tifffile.imread(testFolder+'Lab0.tif'))
for i in range(3):
self.assertAlmostEqual(numpy.mean(output['PhiField'][:,i,-1][output['returnStatus']==2]) - translationStep1[i], 0, places=1)
# Check that there are more RS==2 points in the merged than in the ldic
rsTwoLdic = numpy.sum(spam.helpers.readCorrelationTSV(testFolder+'Step0-Step1.tsv')['returnStatus']==2)
rsTwoLdic = numpy.sum(spam.helpers.readCorrelationTSV(testFolder+'Step0-Step1-ldic.tsv')['returnStatus']==2)
self.assertEqual(numpy.sum(output['returnStatus']==2) > rsTwoLdic, True)
# Check that there some mergeSource = 1
......
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