Commit 4c2228e1 authored by Gustavo Pinzon's avatar Gustavo Pinzon
Browse files

Merge branch 'master' of https://gricad-gitlab.univ-grenoble-alpes.fr/ttk/spam into ddicTools

parents dca3b07b 3c9476e1
......@@ -46,7 +46,7 @@ def register(im1, im2, im1mask=None, PhiInit=None, PhiRigid=False, PhiInitBinRat
"Discrete correlation" can be performed by masking im1.
im1 and im2 do not necessarily have to be the same size (`i.e.`, im2 can be bigger) -- this is good since there
is a zone to accommodate movement. In the case of a bigger im2, im1 and im2 are centred with respect to each other.
is a zone to accommodate movement. In the case of a bigger im2, im1 and im2 are assumed to be centred with respect to each other.
Parameters
----------
......@@ -139,9 +139,6 @@ def register(im1, im2, im1mask=None, PhiInit=None, PhiRigid=False, PhiInitBinRat
----
This correlation was written in the style of S. Roux (especially "An extension of Digital Image Correlation for intermodality image registration")
especially equations 12 and 13.
Since we're using classical DIC (without multimodal registration) there is no need to update the gradient image,
so this is calculated once at the beginning.
"""
# Explicitly set input images to floats
im1 = im1.astype('<f4')
......@@ -183,8 +180,11 @@ def register(im1, im2, im1mask=None, PhiInit=None, PhiRigid=False, PhiInitBinRat
# Automatically calculate margin if none is passed
# Detect default case and calculate maring necessary for a 45deg rotation with no displacement
if margin is None:
# sqrt
margin = [1+int(0.1 * max(im1.shape))] * 3
if twoD:
# z-margin will be overwritten below
margin = [1+int(0.1 * min(im1.shape[1:]))] * 3
else:
margin = [1+int(0.1 * min(im1.shape))] * 3
elif type(margin) == list:
pass
else:
......
......@@ -443,7 +443,11 @@ def registerOnGrid(im1, im2, nodePositions, halfWindowSize, PhiField=None, margi
numberOfNodes = nodePositions.shape[0]
def getImagettes(nodeNumber, im1, im2, PhiField, nodePositions, margin, halfWindowSize, greyThreshold, im1mask, minMaskVolume):
def getImagettes(nodeNumber, im1, im2, PhiField, nodePositions, margin, halfWindowSize, greyThreshold, im1mask, minMaskVolume, twoD=False):
# We don't have many single letter variable names, but this is one to keep things aligned
# This variable is =0 in 2D and =1 in 3D
if twoD: m = 0
else: m = 1
# Initialise defaults
imagette1mask = None
PhiInit = None
......@@ -459,7 +463,7 @@ def registerOnGrid(im1, im2, nodePositions, halfWindowSize, PhiField=None, margi
#slice(int(nodePositions[nodeNumber, 1] - halfWindowSize[1] - 1), int(nodePositions[nodeNumber, 1] + halfWindowSize[1] + 1 + 1)),
#slice(int(nodePositions[nodeNumber, 2] - halfWindowSize[2] - 1), int(nodePositions[nodeNumber, 2] + halfWindowSize[2] + 1 + 1)))
#imagette1 = im1[subVolSlice1].copy()
startStopIm1 = [int(nodePositions[nodeNumber, 0] - halfWindowSize[0] - 1), int(nodePositions[nodeNumber, 0] + halfWindowSize[0] + 1 + 1),
startStopIm1 = [int(nodePositions[nodeNumber, 0] - halfWindowSize[0] - m), int(nodePositions[nodeNumber, 0] + halfWindowSize[0] + 1 + m),
int(nodePositions[nodeNumber, 1] - halfWindowSize[1] - 1), int(nodePositions[nodeNumber, 1] + halfWindowSize[1] + 1 + 1),
int(nodePositions[nodeNumber, 2] - halfWindowSize[2] - 1), int(nodePositions[nodeNumber, 2] + halfWindowSize[2] + 1 + 1)]
imagette1, imagette1mask = spam.helpers.slicePadded(im1, startStopIm1, createMask=True)
......@@ -487,7 +491,7 @@ def registerOnGrid(im1, im2, nodePositions, halfWindowSize, PhiField=None, margi
#slice(int(nodePositions[nodeNumber, 2] - halfWindowSize[2] + nodeDisplacement[2] - margin[2] - 1), int(nodePositions[nodeNumber, 2] + halfWindowSize[2] + nodeDisplacement[2] + margin[2] + 1 + 1)))
## Extract it
#imagette2 = im2[subVolSlice2].copy()
startStopIm2 = [int(nodePositions[nodeNumber, 0] - halfWindowSize[0] + nodeDisplacement[0] - margin[0] - 1), int(nodePositions[nodeNumber, 0] + halfWindowSize[0] + nodeDisplacement[0] + margin[0] + 1 + 1),
startStopIm2 = [int(nodePositions[nodeNumber, 0] - halfWindowSize[0] + nodeDisplacement[0] - margin[0] - m), int(nodePositions[nodeNumber, 0] + halfWindowSize[0] + nodeDisplacement[0] + margin[0] + m + 1),
int(nodePositions[nodeNumber, 1] - halfWindowSize[1] + nodeDisplacement[1] - margin[1] - 1), int(nodePositions[nodeNumber, 1] + halfWindowSize[1] + nodeDisplacement[1] + margin[1] + 1 + 1),
int(nodePositions[nodeNumber, 2] - halfWindowSize[2] + nodeDisplacement[2] - margin[2] - 1), int(nodePositions[nodeNumber, 2] + halfWindowSize[2] + nodeDisplacement[2] + margin[2] + 1 + 1)]
imagette2 = spam.helpers.slicePadded(im2, startStopIm2, padValue=numpy.nan)
......@@ -589,7 +593,7 @@ def registerOnGrid(im1, im2, nodePositions, halfWindowSize, PhiField=None, margi
# Get the next node off the queue
nodeNumber = q.get()
imagetteReturns = getImagettes(nodeNumber, im1, im2, PhiField, nodePositions, margin, halfWindowSize, greyThreshold, im1mask, minMaskVolume)
imagetteReturns = getImagettes(nodeNumber, im1, im2, PhiField, nodePositions, margin, halfWindowSize, greyThreshold, im1mask, minMaskVolume, twoD)
if imagetteReturns['returnStatus'] == 2:
if mpi:
......
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