updated normalization routine in the matchTemplate to avoid division by zero on black images (ticket #798), added test

This commit is contained in:
Alexey Spizhevoy
2011-01-11 09:36:21 +00:00
parent a961cfe135
commit dc763e0250
3 changed files with 72 additions and 67 deletions

View File

@@ -560,7 +560,7 @@ __global__ void matchTemplatePreparedKernel_CCOFF_NORMED_8U(
(image_sqsum.ptr(y + h)[x + w] - image_sqsum.ptr(y)[x + w]) -
(image_sqsum.ptr(y + h)[x] - image_sqsum.ptr(y)[x]));
result.ptr(y)[x] = min(1.f, (ccorr - image_sum_ * templ_sum_scale) *
rsqrtf(templ_sqsum_scale * (image_sqsum_ - weight * image_sum_ * image_sum_)));
rsqrtf(templ_sqsum_scale * (image_sqsum_ - weight * image_sum_ * image_sum_ + 1.f)));
}
}
@@ -611,7 +611,7 @@ __global__ void matchTemplatePreparedKernel_CCOFF_NORMED_8UC2(
(image_sqsum_g.ptr(y + h)[x] - image_sqsum_g.ptr(y)[x]));
float ccorr = result.ptr(y)[x];
float rdenom = rsqrtf(templ_sqsum_scale * (image_sqsum_r_ - weight * image_sum_r_ * image_sum_r_
+ image_sqsum_g_ - weight * image_sum_g_ * image_sum_g_));
+ image_sqsum_g_ - weight * image_sum_g_ * image_sum_g_ + 1.f));
result.ptr(y)[x] = min(1.f, (ccorr - image_sum_r_ * templ_sum_scale_r
- image_sum_g_ * templ_sum_scale_g) * rdenom);
}
@@ -680,7 +680,7 @@ __global__ void matchTemplatePreparedKernel_CCOFF_NORMED_8UC3(
float ccorr = result.ptr(y)[x];
float rdenom = rsqrtf(templ_sqsum_scale * (image_sqsum_r_ - weight * image_sum_r_ * image_sum_r_
+ image_sqsum_g_ - weight * image_sum_g_ * image_sum_g_
+ image_sqsum_b_ - weight * image_sum_b_ * image_sum_b_));
+ image_sqsum_b_ - weight * image_sum_b_ * image_sum_b_ + 1.f));
result.ptr(y)[x] = min(1.f, (ccorr - image_sum_r_ * templ_sum_scale_r
- image_sum_g_ * templ_sum_scale_g
- image_sum_b_ * templ_sum_scale_b) * rdenom);
@@ -763,7 +763,7 @@ __global__ void matchTemplatePreparedKernel_CCOFF_NORMED_8UC4(
float rdenom = rsqrtf(templ_sqsum_scale * (image_sqsum_r_ - weight * image_sum_r_ * image_sum_r_
+ image_sqsum_g_ - weight * image_sum_g_ * image_sum_g_
+ image_sqsum_b_ - weight * image_sum_b_ * image_sum_b_
+ image_sqsum_a_ - weight * image_sum_a_ * image_sum_a_));
+ image_sqsum_a_ - weight * image_sum_a_ * image_sum_a_ + 1.f));
result.ptr(y)[x] = min(1.f, (ccorr - image_sum_r_ * templ_sum_scale_r
- image_sum_g_ * templ_sum_scale_g
- image_sum_b_ * templ_sum_scale_b
@@ -822,7 +822,7 @@ __global__ void normalizeKernel_8U(
float image_sqsum_ = (float)(
(image_sqsum.ptr(y + h)[(x + w) * cn] - image_sqsum.ptr(y)[(x + w) * cn]) -
(image_sqsum.ptr(y + h)[x * cn] - image_sqsum.ptr(y)[x * cn]));
result.ptr(y)[x] = min(1.f, result.ptr(y)[x] * rsqrtf(image_sqsum_ * templ_sqsum));
result.ptr(y)[x] = min(1.f, result.ptr(y)[x] * rsqrtf((image_sqsum_ + 1.f) * templ_sqsum));
}
}