84
82
res2[img_idx] = sqrtf(fmaxf(((float)sum2) / cnt - mean*mean,0));
92
static __global__ void vecCompute(
93
uint16_t *items, float *res,
94
cufftReal *corr, float corr_scale,
95
float *lsum, float lsum_scale,
96
float *denom, float denom_scale
98
int pos = items[threadIdx.x + blockIdx.x*BLOCK_SIZE_1D];//correct (row/column)?
99
res[pos] = (corr[pos] * corr_scale - lsum[pos]*lsum_scale) / (denom[pos] * denom_scale);
104
static __global__ void vecCompute(
106
cufftReal *corr, float corr_scale,
107
float *lsum, float lsum_scale,
108
float *denom, float denom_scale,
111
int pos = threadIdx.x + blockIdx.x*size;
114
res[pos] = (corr[pos] * corr_scale - lsum[pos]*lsum_scale) / (denom[pos] * denom_scale);
119
85
static __global__ void vecCompute(
121
87
cufftReal *corr, float corr_scale,
132
98
res[pos] = (corr[pos] * corr_scale - lsum[pos]*lsum_scale) / (denom[pos] * denom_scale);
102
static __global__ void find_max1(float *buf1, int32_t *buf2, float *corr, int image_pitch, int row_pitch, int size) {
104
int end = size * row_pitch;
106
int side_idx = blockIdx.x * blockDim.x + threadIdx.x;
107
int img_idx = blockIdx.y * blockDim.y + threadIdx.y;
109
float max = 0.5; // This is limit for acceptance in cpcorr
112
float *vec = corr + img_idx * image_pitch + side_idx;
114
for (i = 0; i < end; i+=row_pitch) {
122
// align to remove if
123
if (side_idx < size) {
124
buf1[side_idx * CP_BLOCK + img_idx] = max;
125
buf2[side_idx * CP_BLOCK + img_idx] = pos / row_pitch;
129
static __global__ void find_max2(
130
float *res1, float *res2, float *buf1, int32_t *buf2,
131
float *corr, int image_pitch, int row_pitch,
132
int size, float center, float limit
135
int end = size * CP_BLOCK;
136
int img_idx = blockIdx.x * blockDim.x + threadIdx.x;
138
float max = 0.5; // This is limit for acceptance in cpcorr
142
float *maxes = buf1 + img_idx;
143
int32_t *poses = buf2 + img_idx;
146
This is a magic number which are used to reimplement position fitting
147
using 9 neighbouring points (see findpeak.m). Thats array is a
148
Moore-Penrose pseudoinverse (pinv) of matrix "X":
149
x = [-1 -1 -1 0 0 0 1 1 1]';
150
y = [-1 0 1 -1 0 1 -1 0 1]';
151
X = [ones(9,1), x, y, x.*y, x.^2, y.^2];
152
This matrix is, then, used to compute
159
-1.111111111111111e-01, 2.222222222222223e-01, -1.111111111111110e-01, 2.222222222222222e-01, 5.555555555555555e-01, 2.222222222222222e-01, -1.111111111111112e-01, 2.222222222222222e-01, -1.111111111111111e-01,
160
-1.666666666666667e-01, -1.666666666666667e-01, -1.666666666666669e-01, 4.625993595943901e-17, 5.251763038925035e-17, -7.864015431086855e-17, 1.666666666666668e-01, 1.666666666666668e-01, 1.666666666666667e-01,
161
-1.666666666666667e-01, 2.989343524323885e-17, 1.666666666666668e-01, -1.666666666666668e-01, -1.466129894633581e-18, 1.666666666666668e-01, -1.666666666666668e-01, -2.561771598799484e-17, 1.666666666666667e-01,
162
2.499999999999986e-01, -3.087055673664417e-16, -2.499999999999991e-01, -1.189598686604080e-15, 1.394017483632152e-17, 1.214208755585016e-15, -2.500000000000011e-01, 3.049745671257349e-16, 2.500000000000016e-01,
163
1.666666666666664e-01, 1.666666666666666e-01, 1.666666666666667e-01, -3.333333333333334e-01, -3.333333333333330e-01, -3.333333333333331e-01, 1.666666666666665e-01, 1.666666666666666e-01, 1.666666666666667e-01,
164
1.666666666666667e-01, -3.333333333333335e-01, 1.666666666666664e-01, 1.666666666666669e-01, -3.333333333333332e-01, 1.666666666666667e-01, 1.666666666666668e-01, -3.333333333333333e-01, 1.666666666666665e-01
168
for (i = 0; i < end; i+=CP_BLOCK) {
169
float val = maxes[i];
179
if ((max > 0.5f)&&((fabsf(xpos - center) < limit)&&(fabsf(ypos - center) < limit))) {
181
// Limit warranties we are not at the edge
185
float *vec0 = corr + img_idx * image_pitch + (xpos - 1)*row_pitch + (ypos - 1);
186
float *vec1 = corr + img_idx * image_pitch + (xpos )*row_pitch + (ypos - 1);
187
float *vec2 = corr + img_idx * image_pitch + (xpos + 1)*row_pitch + (ypos - 1);
189
float neighbors[9] = {
190
vec0[0], vec0[1], vec0[2],
191
vec1[0], max , vec1[2],
192
vec2[0], vec2[1], vec2[2]
196
for (i=0; i<6; i++) {
198
for (j=0; j<9; j++) {
199
A[i] += magic[i*9 + j] * neighbors[j];
203
x_offset = (-A[2]*A[3]+2*A[5]*A[1]) / (A[3]*A[3]-4*A[4]*A[5]);
204
y_offset = -1.f / ( A[3]*A[3]-4*A[4]*A[5])*(A[3]*A[1]-2*A[4]*A[2]);
206
if ((fabsf(x_offset)>1.f)||(fabsf(y_offset)>1.f)) {
210
x_offset = roundf(10*x_offset)/10;
211
y_offset = roundf(10*y_offset)/10;
213
res1[img_idx] = ((float)xpos) + x_offset + 1 - center;
214
res2[img_idx] = ((float)ypos) + y_offset + 1 - center;
216
// DS: Still fractional offsets are computed in this case, shall we ignore that?