资源简介
双边滤波的opencv实现,效果很好,代码自己写的,很规范,希望对大家有帮助,使用需要配置opencv2.3.1.
代码片段和文件信息
#pragma once
#include “BilateralFilter.h“
BilateralFilter::BilateralFilter()
{
this->distance_sigma = 3.0;
this->similar_sigma = 30.0;
}
void BilateralFilter::bilateral_filter_process(IplImage* img_src IplImage* img_dest)
{
/* get properties of source image */
data_src = (uchar *)img_src->imageData;
img_width = img_src->width;
img_height = img_src->height;
step_src = img_src->widthStep;
/* get properties of destination image */
data_dest = (uchar *)img_dest->imageData;
step_dest = img_dest->widthStep;
build_distance_weight_table();
build_similar_weight_table();
for(int i=0; i {
for(int j=0; j {
data_dest[i * step_dest + j] = count_pixel(i j);
}
}
}
uchar BilateralFilter::count_pixel(int row int column)
{
double sum_pixel = 0;
double sum_weight = 0;
int center_pixel_index = row * step_src + column;
for(int i=-kernel_radius; i<=kernel_radius; i++)
{
for(int j=-kernel_radius; j<=kernel_radius; j++)
{
int temp_row = row + i;
if(temp_row < 0)
temp_row = 0;
else if(temp_row > img_height - 1)
temp_row = img_height - 1;
int temp_column = column + j;
if(temp_column < 0)
temp_column = 0;
else if(temp_column > img_width - 1)
temp_column = img_width - 1;
int temp_pixel_index = temp_row * step_src + temp_column;
double distance_weight = distance_weight_table[i + kernel_radius][j + kernel_radius];
double similar_weight = similar_weight_table[abs(data_src[center_pixel_index] - data_src[temp_pixel_index])];
double weight = distance_weight * similar_weight; //双边滤波
// double weight = distance_weight; //高斯滤波
sum_pixel += data_src[temp_pixel_index] * weight;
sum_weight += weight;
}
}
sum_pixel /= sum_weight;
uchar pixel = (uchar)sum_pixel;
return pixel;
}
//建立距离高斯权重表(Weight Table)
void BilateralFilter::build_distance_weight_table()
{
for(int i=-kernel_radius; i<=kernel_radius; i++)
{
for(int j=-kernel_radius; j<=kernel_radius; j++)
{
distance_weight_table[i + kernel_radius][j + kernel_radius] = exp(-(i*i + j*j)/(2 * distance_sigma * distance_sigma));
}
}
}
//建立像素灰度差值高斯权重表(Weight Table)
void BilateralFilter::build_similar_weight_table()
{
for(int i=0; i<256; i++)
{
similar_weight_table[i] = exp((-i*i)/(2 * similar_sigma * similar_sigma));
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 5591040 2013-06-18 15:53 Bilateral_Filter\BilateralFilter.sdf
文件 904 2012-12-10 20:51 Bilateral_Filter\BilateralFilter.sln
..A..H. 16896 2013-06-18 15:53 Bilateral_Filter\BilateralFilter.suo
文件 82416 2012-11-07 14:52 Bilateral_Filter\opencv_test\1.png
文件 141388 2012-11-07 14:52 Bilateral_Filter\opencv_test\2.png
文件 2458 2012-12-18 21:06 Bilateral_Filter\opencv_test\BilateralFilter.cpp
文件 717 2012-11-07 22:18 Bilateral_Filter\opencv_test\BilateralFilter.h
文件 104130 2012-11-12 11:14 Bilateral_Filter\opencv_test\Debug\BilateralFilter.obj
文件 2142 2012-11-12 11:15 Bilateral_Filter\opencv_test\Debug\cl.command.1.tlog
文件 95272 2012-11-12 11:15 Bilateral_Filter\opencv_test\Debug\CL.read.1.tlog
文件 1752 2012-11-12 11:15 Bilateral_Filter\opencv_test\Debug\CL.write.1.tlog
文件 2 2012-11-12 11:15 Bilateral_Filter\opencv_test\Debug\li
文件 2 2012-11-12 11:15 Bilateral_Filter\opencv_test\Debug\li
文件 2 2012-11-12 11:15 Bilateral_Filter\opencv_test\Debug\li
文件 2 2012-11-12 11:15 Bilateral_Filter\opencv_test\Debug\li
文件 2 2012-11-12 11:15 Bilateral_Filter\opencv_test\Debug\li
文件 2 2012-11-12 11:15 Bilateral_Filter\opencv_test\Debug\li
文件 2 2012-11-12 11:15 Bilateral_Filter\opencv_test\Debug\li
文件 2 2012-11-12 11:15 Bilateral_Filter\opencv_test\Debug\li
文件 2 2012-11-12 11:15 Bilateral_Filter\opencv_test\Debug\li
文件 2 2012-11-12 11:15 Bilateral_Filter\opencv_test\Debug\li
文件 2 2012-11-12 11:15 Bilateral_Filter\opencv_test\Debug\li
文件 2 2012-11-12 11:15 Bilateral_Filter\opencv_test\Debug\li
文件 2 2012-11-12 11:15 Bilateral_Filter\opencv_test\Debug\li
文件 2 2012-11-12 11:15 Bilateral_Filter\opencv_test\Debug\li
文件 3926 2012-11-12 11:15 Bilateral_Filter\opencv_test\Debug\li
文件 7848 2012-11-12 11:15 Bilateral_Filter\opencv_test\Debug\li
文件 1880 2012-11-12 11:15 Bilateral_Filter\opencv_test\Debug\li
文件 842 2012-11-12 11:15 Bilateral_Filter\opencv_test\Debug\mt.command.1.tlog
文件 722 2012-11-12 11:15 Bilateral_Filter\opencv_test\Debug\mt.read.1.tlog
............此处省略27个文件信息
- 上一篇:sd2.0 协议标准完整版
- 下一篇:IT设备管理源代码
相关资源
- Adobe Audition3.0扩展编码器 Audition3.0Fi
- FilterLab 2.0使用手册(pdf)
- Microstrip Filters for RF Microwave Applicatio
- Introduction-to-Digital-Filters-with-Audio-App
- ECCV10-Guided Image Filter-代码
- ECCV10-Guided Image Filter -ppt
- 二阶锁频辅助三阶锁相环路滤波器设
- 自适应滤波器原理第五版英文答案S
- Fundamentals of Kalman Filtering: A Practical
- Instagram Filters 破解了Instagram App的几十
- Fundamentals of Kalman Filtering A Practical A
- PS星光滤镜ProDigital Software StarFilter V
- filter solutions
- Filter_Solutions_教程
- lavfilter-0.70.2 windows下的解码器
- NDIS中间层 NDIS6过滤驱动开发笔记
- as3的颜色矩阵滤镜ColorMatrixFilter的使用
- FilterPro MFB 和 Sallen-Key 低通滤波器设计
- EWT参考文献
- Microwave Resonators and Filters
- Retinex by two Bilateral Filters
- 经典去噪算法小波、Lee等等
- 视频流实时人脸检测Filter
- 最简单的基于DirectShow的
- Saliency Filters的实现
- meanFilter.zip
- 用户登陆Filter(过滤器)
- Norbert_Wiener-Extrapolation_interpolation_and
- 我所见过的功能最强大的有源滤波器
- FilterPro使用教程
评论
共有 条评论