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

[skip-ci] grid pixel search fully tested, starting on label mode, some trouble...

[skip-ci] grid pixel search fully tested, starting on label mode, some trouble re-reading previous result even without registration and zero search range...
parent f965e6cc
Pipeline #56856 skipped
......@@ -82,6 +82,7 @@ if args.LAB1 is not None:
nodePositions = spam.label.centresOfMass(lab1, boundingBoxes=boundingBoxes)
numberOfNodes = nodePositions.shape[0]
im1mask = None
im2mask = None
### Otherwise we are in node spacing and half-window size mode
else:
......@@ -101,6 +102,13 @@ else:
else:
im1mask = None
if args.MASK2:
im2mask = tifffile.imread(args.MASK2.name) != 0
if len(im2mask.shape) == 2:
im2mask = im2mask[numpy.newaxis, ...]
else:
im2mask = None
###############################################################
# Now that we know how many points we want to correlate, initalise PhiField
......@@ -144,6 +152,7 @@ if args.PHIFILE is not None:
else:
# Read the coordinates and values of the input F field
fieldCoords = PhiFromFile["fieldCoords"]
fieldValues = PhiFromFile["PhiField"]
# Create the k-d tree of the coordinates of the input F field
from scipy.spatial import KDTree
......@@ -220,6 +229,7 @@ def pixelSearchOneNode(nodeNumber):
imagetteReturns['imagette1'] = imagette1def
imagetteReturns['imagette1mask'] = gottenLabel['subvol']
imagetteReturns['imagette2mask'] = None
# 2020-09-25 OS and EA: Prepare startStop array for imagette 2 to be extracted with new slicePadded
startStopIm2 = [int(gottenLabel['boundingBox'][0] - max(args.LABEL_DILATE, 0) + initialDisplacement[0] + searchRange[0] ),
......@@ -237,13 +247,14 @@ def pixelSearchOneNode(nodeNumber):
imagetteReturns['returnStatus'] = 0
else:
imagetteReturns = spam.DIC.getImagettes(nodePositions[nodeNumber], PhiField[nodeNumber].copy(), searchRange.copy(), boundingBoxes[nodeNumber], im1, im2, im1mask, args.MASK_COVERAGE, greyThreshold, twoD)
imagetteReturns = spam.DIC.getImagettes(nodePositions[nodeNumber], PhiField[nodeNumber].copy(), searchRange.copy(), boundingBoxes[nodeNumber], im1, im2, im1mask, im2mask, args.MASK_COVERAGE, greyThreshold, twoD)
# If getImagettes was successful (size check and mask coverage check)
if imagetteReturns['returnStatus'] == 1:
PSreturns = spam.DIC.correlate.pixelSearch(imagetteReturns['imagette1'],
imagetteReturns['imagette2'],
imagette1mask = imagetteReturns['imagette1mask'],
imagette2mask = imagetteReturns['imagette2mask'],
returnError = True)
pixelSearchOffset = imagetteReturns['pixelSearchOffset']
writeReturns = True
......@@ -266,7 +277,7 @@ returnStatus = numpy.ones((numberOfNodes), dtype=int)
deltaPhiNorm = numpy.ones((numberOfNodes), dtype=int)
iterations = numpy.ones((numberOfNodes), dtype=int)
if args.LAB1 is not None: firstNode = 1; finishedNodes = 1
if args.LAB1 is not None: firstNode = 1; finishedNodes = 1; returnStatus[0] = 0
else: firstNode = 0; finishedNodes = 0
......
This diff is collapsed.
......@@ -144,12 +144,11 @@ Returns
"""
# WARNING ------------------------- VVVVVVVVVVV--- gets easily overwritten, pass a .copy()!
def getImagettes(nodePosition, Phi, searchRange, boundingBox, im1, im2, im1mask, minMaskCoverage, greyThreshold, twoD=False):
def getImagettes(nodePosition, Phi, searchRange, boundingBox, im1, im2, im1mask, im2mask, minMaskCoverage, greyThreshold, twoD=False):
returnStatus = 1
imagette1mask = None
imagette2mask = None
initialDisplacement = numpy.round(Phi[0:3, 3]).astype(int)
if twoD: m = 0
else: m = 0
# Catch bad bounding boxes:
if numpy.all((boundingBox[1::2] - boundingBox[0::2]) > 0) or ( numpy.all(boundingBox[3::2] - boundingBox[2::2] > 0) and twoD):
......@@ -221,6 +220,8 @@ def getImagettes(nodePosition, Phi, searchRange, boundingBox, im1, im2, im1mask,
int(boundingBox[5] + initialDisplacement[2] + searchRange[5] + 1)]
imagette2 = spam.helpers.slicePadded(im2, startStopIm2)
if im2mask is not None: imagette2mask = spam.helpers.slicePadded(im2mask, startStopIm2)
# Failed minMaskVolume condition
else:
returnStatus = -5
......@@ -248,6 +249,7 @@ def getImagettes(nodePosition, Phi, searchRange, boundingBox, im1, im2, im1mask,
return {'imagette1': imagette1def,
'imagette1mask': imagette1mask,
'imagette2': imagette2,
'imagette2mask': imagette2mask,
'returnStatus': returnStatus,
'pixelSearchOffset': searchRange[0::2]
}
......@@ -1888,6 +1888,8 @@ def register(parser):
# Output file name prefix
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] + "-registration"
else:
args.PREFIX += "-registration"
return args
......@@ -1932,6 +1934,13 @@ def pixelSearch(parser):
type=argparse.FileType('r'),
help="Path to tiff file containing the mask of image 1 -- masks zones not to correlate, which should be == 0")
parser.add_argument('-mf2',
'--maskFile2',
dest='MASK2',
default=None,
type=argparse.FileType('r'),
help="Path to tiff file containing the mask of image 2 -- masks zones not to correlate, which should be == 0")
parser.add_argument('-mc',
'--mask-coverage',
type=float,
......@@ -2137,6 +2146,7 @@ def pixelSearch(parser):
# Output file name prefix
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] + "-pixelSearch"
else:
args.PREFIX += "-pixelSearch"
return args
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