Commit 5d138926 authored by Edward Andò's avatar Edward Andò
Browse files

[skip-ci] spam-pixelSearch with new changes to pixelSearch

parent 1c238ccd
......@@ -52,12 +52,12 @@ for key in sorted(argsDict):
# Do something about these variables later...
halfWindowSize = args.HWS
halfWindowSize = numpy.array(args.HWS)
minMaskCoverage = args.MASK_COVERAGE
greyThreshold = [args.GREY_LOW_THRESH, args.GREY_HIGH_THRESH]
# Fill in search range as a dictionary
searchRange = [args.SEARCH_RANGE[0], args.SEARCH_RANGE[1], args.SEARCH_RANGE[2], args.SEARCH_RANGE[3], args.SEARCH_RANGE[4], args.SEARCH_RANGE[5]]
searchRange = numpy.array([args.SEARCH_RANGE[0], args.SEARCH_RANGE[1], args.SEARCH_RANGE[2], args.SEARCH_RANGE[3], args.SEARCH_RANGE[4], args.SEARCH_RANGE[5]])
# Load reference image
im1 = tifffile.imread(args.im1.name)
......@@ -231,14 +231,14 @@ def getImagettes(nodeNumber, nodePositions, PhiField, searchRange, halfWindowSiz
initialDisplacement = PhiField[nodeNumber, 0:3, 3].astype(int)
# Add initial displacement guess to search range
searchRangeForThisNode = {'zRange': [searchRange['zRange'][0] + initialDisplacement[0], searchRange['zRange'][1] + initialDisplacement[0]],
'yRange': [searchRange['yRange'][0] + initialDisplacement[1], searchRange['yRange'][1] + initialDisplacement[1]],
'xRange': [searchRange['xRange'][0] + initialDisplacement[2], searchRange['xRange'][1] + initialDisplacement[2]]}
searchRangeForThisNode = searchRange
#Add initial displacement to searchRange
searchRangeForThisNode[0::2] += initialDisplacement
searchRangeForThisNode[1::2] += initialDisplacement
# point in im2 that we are searching around
searchCentre = [halfWindowSize[0] - searchRangeForThisNode['zRange'][0],
halfWindowSize[1] - searchRangeForThisNode['yRange'][0],
halfWindowSize[2] - searchRangeForThisNode['xRange'][0]]
searchCentre = halfWindowSize - searchRangeForThisNode[0::2]
# 2020-09-25 OS and EA: Prepare startStop array for imagette 1 to be extracted with new slicePadded
PhiNoDisp = PhiField[nodeNumber]
......@@ -275,12 +275,12 @@ def getImagettes(nodeNumber, nodePositions, PhiField, searchRange, halfWindowSiz
# Slice for image 2
## 2020-09-25 OS and EA: Prepare startStop array for imagette 2 to be extracted with new slicePadded
## Extract it...
startStopIm2 = [int(nodePositions[nodeNumber, 0] - halfWindowSize[0] + searchRangeForThisNode['zRange'][0]),
int(nodePositions[nodeNumber, 0] + halfWindowSize[0] + searchRangeForThisNode['zRange'][1] + 1),
int(nodePositions[nodeNumber, 1] - halfWindowSize[1] + searchRangeForThisNode['yRange'][0]),
int(nodePositions[nodeNumber, 1] + halfWindowSize[1] + searchRangeForThisNode['yRange'][1] + 1),
int(nodePositions[nodeNumber, 2] - halfWindowSize[2] + searchRangeForThisNode['xRange'][0]),
int(nodePositions[nodeNumber, 2] + halfWindowSize[2] + searchRangeForThisNode['xRange'][1] + 1)]
startStopIm2 = [int(nodePositions[nodeNumber, 0] - halfWindowSize[0] + searchRangeForThisNode[0]),
int(nodePositions[nodeNumber, 0] + halfWindowSize[0] + searchRangeForThisNode[1] + 1),
int(nodePositions[nodeNumber, 1] - halfWindowSize[1] + searchRangeForThisNode[2]),
int(nodePositions[nodeNumber, 1] + halfWindowSize[1] + searchRangeForThisNode[3] + 1),
int(nodePositions[nodeNumber, 2] - halfWindowSize[2] + searchRangeForThisNode[4]),
int(nodePositions[nodeNumber, 2] + halfWindowSize[2] + searchRangeForThisNode[5] + 1)]
imagette2 = spam.helpers.slicePadded(im2, startStopIm2)
# Failed minMaskVolume or greylevel condition
......@@ -408,7 +408,7 @@ while finishedNodes != numberOfNodes:
finishedNodes += 1
writeReturns = False
# set translation for this node
PhiField[nodeNumber, 0:3, 3] = numpy.array(returns['transformation']['t'])
PhiField[nodeNumber, 0:3, 3] = numpy.array(returns['t'])
pixelSearchCC[nodeNumber] = returns['cc']
widgets[0] = progressbar.FormatLabel(" CC={:0>7.5f} ".format(pixelSearchCC[nodeNumber]))
......
......@@ -108,7 +108,7 @@ void pixelSearch(py::array_t<float> im1Numpy,
xBot = xTop+im1x;
// printf("zTop %i yTop %i xTop %i\n", zTop, yTop, xTop);
// printf("zDisp %i yDisp %i xDisp %i\n", zDisp, yDisp, xDisp);
// // printf("zDisp %i yDisp %i xDisp %i\n", zDisp, yDisp, xDisp);
// std::cout << "Tops: "<< zTop << " " << yTop << " " << xTop << "\n" << std::endl;
// std::cout << "Bots: "<< zBot << " " << yBot << " " << xBot << "\n" << std::endl;
/* Check we're not outside the boundaries... */
......@@ -116,14 +116,11 @@ void pixelSearch(py::array_t<float> im1Numpy,
zBot <= (int)im2z && yBot <= (int)im2y && xBot <= (int)im2x )
{
// std::cout << zDisp << " " << yDisp << " " << xDisp << "\n" << std::endl;
/* reset calculations */
/* three components to our NCC calculation (see documentation/C-remi.odt) */
float a,b,c;
a = b = c = 0;
// std::cout << im1z << " " << im1y << " " << im1x << "\n" << std::endl;
/* CC calculation Loop z-first (for numpy) */
for ( z=0; z<im1z; z++ )
{
......@@ -139,30 +136,24 @@ void pixelSearch(py::array_t<float> im1Numpy,
for ( x=0; x<im1x; x++ )
{
// std::cout << "x = " << x << " y = " << y << " z = " << z << std::endl;
/* build index to 1D image1 */
// index1 = z *im1y*im1x + y *im1x + x;
size_t index1 = zOffset1 + yOffset1 + x;
// std::cout << "index1 = " << index1 << std::endl;
/*2015-10-22: EA -- skip NaNs in the reference image
* NaNs in C are not even equal to themselves, so we'll use this simple check. */
/* 2015-10-22: EA -- skip NaNs in the reference image
* NaNs in C are not even equal to themselves, so we'll use this simple check. */
if ( im1[ index1 ] == im1[ index1 ] )
{
/* build index to 1D image2 */
// index2 = (z+zTop)*im2y*im2x + (y+yTop)*im2x + (x+xTop);
size_t index2 = zOffset2 + yOffset2 + (x+xTop);
// fetch 1 pixel from both images
im1px = im1[ index1 ];
im2px = im2[ index2 ];
// printf( "\tim1px=%f im2px=%f\n", im1px, im2px );
// Our little bits of the NCC
a = a + im1px * im2px;
b = b + im1px * im1px;
c = c + im2px * im2px;
// printf( "\ta=%f b=%f c=%f\n", a, b, c );
}
}
}
......
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