积分图像
2013-10-30 15:01
148 查看
回忆积分图概念的过程中,搜到一篇很好的介绍积分图的帖子,遂转贴出并向原作者致敬。目前为止看到的结果是积分图用到了Haar小波,LBP,HOG和SURF的特征提取中,此种手法也是用空间换取时间的算法优化,值得学习。
How
Suppose an image is w pixels
wide and h pixels
high. Then the integral of this will be w+1 pixels
wide and h+1 pixels
high. The first row andcolumn of the integral image are all zeros.
All
other pixels have a value equal to the sum of all pixels before it.
See the integral in the above image? Every pixel is the summation of the pixels before it
(above and to the left).
Now, to calculate the summation of the pixels in the black box, you take the corresponding
box in the integral. You sum as follows: (Bottomright + top left – top right – bottom left).
So for the 3,5,4,1 box, the calculations would go like this: (30+0-17-0 = 13). For the 4,1
box, it would be (0+15-10-0 = 5).
This way, you can calculate summations in rectangular regions rapidly.
More
With the basic idea in mind, you can extend it to more types of summations. You can calculate
the sum of squares. You can rotate the image by 45 degrees and then do the summations. Then, you can calculate the totals in any arbitrary rectangular region that is upright or tilted at 45 degrees.
You can calculate summations on irregular areas too (only those with 90 degree corners though).
Not just that, you can do super fast blurs, approximate gradients and compute means and standard deviations very fast.
Calculating
OpenCV comes with a predefined function to calculate an integral image.
The parame
4000
ters are, as always, self explanatory:
image:
the source image
sum:
the sum summation integral image
sqsum:
the square sum integral image
tiled_sum: image is
rotated by 45 degrees and then its integral is calculated
But they let you do more complex stuff (like blurring, HAAR wavelets, etc) super fast. And cvIntegral in
OpenCV calculates integral images for you.
也贴出只针对8位灰度图的代码,相当精简,看起来会比openCV的稍稍舒服一些
How
it works
Suppose an image is w pixelswide and h pixels
high. Then the integral of this will be w+1 pixels
wide and h+1 pixels
high. The first row andcolumn of the integral image are all zeros.
All
other pixels have a value equal to the sum of all pixels before it.
See the integral in the above image? Every pixel is the summation of the pixels before it
(above and to the left).
Now, to calculate the summation of the pixels in the black box, you take the corresponding
box in the integral. You sum as follows: (Bottomright + top left – top right – bottom left).
So for the 3,5,4,1 box, the calculations would go like this: (30+0-17-0 = 13). For the 4,1
box, it would be (0+15-10-0 = 5).
This way, you can calculate summations in rectangular regions rapidly.
More
than just summations!
With the basic idea in mind, you can extend it to more types of summations. You can calculatethe sum of squares. You can rotate the image by 45 degrees and then do the summations. Then, you can calculate the totals in any arbitrary rectangular region that is upright or tilted at 45 degrees.
You can calculate summations on irregular areas too (only those with 90 degree corners though).
Not just that, you can do super fast blurs, approximate gradients and compute means and standard deviations very fast.
Calculating
Integral Images in OpenCV
OpenCV comes with a predefined function to calculate an integral image.void cvIntegral(const CvArr* image, CvArr* sum, CvArr* sqsum=NULL, CvArr* tilted_sum=NULL);
The parame
4000
ters are, as always, self explanatory:
image:
the source image
sum:
the sum summation integral image
sqsum:
the square sum integral image
tiled_sum: image is
rotated by 45 degrees and then its integral is calculated
Summary
Calculating integral images is trivial.But they let you do more complex stuff (like blurring, HAAR wavelets, etc) super fast. And cvIntegral in
OpenCV calculates integral images for you.
也贴出只针对8位灰度图的代码,相当精简,看起来会比openCV的稍稍舒服一些
for( y = 0; y < image->height; y++, src += image->width, sum += sum_width )
{
int s = sum[-1] = 0;
for( x = 0; x < image->width; x ++ )
{
s += src[x];
sum[x] = sum[x - sum_width] + s;
}
}
相关文章推荐
- 机器视觉中的图像积分图及事实上现
- 积分图像和积分直方图
- 图像分析:积分图像与代码实现
- 【人脸检测:Haar】利用积分图像法快速计算Haar特征(二)
- 积分图像与卷积图像背景故事杂谈
- 关于医学图像处理中钙化积分的计算
- opencv学习---计算图像的水平积分投影和垂直积分投影
- 利用积分图像法快速计算Haar特征
- 【图像处理】快速计算积分图
- 【图像特征提取1】方向梯度直方图HOG---从理论到实践------附带积分图像的解析
- 积分图像
- matlab构建积分图像
- 机器视觉中的图像积分图及其实现
- 图像积分图的计算
- 目标检测的图像特征提取之(三)Haar特征+积分图+盒式滤波器Box Filter
- 【图像处理】所谓的“快速积分图”,其实并不快
- SSE图像算法优化系列六:OpenCv关于灰度积分图的SSE代码学习和改进。
- 图像积分图代码实现(c代码)
- 基于OpenCL的图像积分图算法改进
- opencv3/C++ 积分图像