Overview
在介绍Adaptive thresholding之前,让我们来看看Integral Image的概念:
Integral images have been introduced as an efficient way of summing
pixels in image regions of interest. They are widely used in applications
that involve, for example, computations over sliding windows at multiple
scales.
可以看到,Integral Image是避免重复计算多个ROI像素值和的一种方法。接下来,我们实现的就是简单的矩形ROI,使得Integral Image上的每一个点的值为:该点和图像左上角形成的矩形区域像素值之和。
而Adaptive thresholding 是相对于fixed thresholding而言的。fixed就是我们之前常用的固定阀值,而Adaptive的阀值是由一个固定阀值和一个变化的均值决定的,这个均值,就是某像素点周围一些像素点的均值。
Code
integral.h
实际上,OpenCV已经提供了计算Integral Image的函数cv::integral
,但是书上也自己实现了一边,我们这里也贴上。
1 |
|
main.cpp
这里介绍了,OpenCV自带的fixed thresholding, Adaptive thresholding, boxFilter的用法,同时运用Integral Image重新实现了一遍Adaptive thresholding.
1 |
|
输出:
time (adaptiveThreshold) = 2305893
time integral= 7118664
time filtered= 1179760