IIR型高斯滤波的原理及实现





二、实现
GIMP中有IIR型高斯滤波的实现,代码位于contrast-retinex.c中,读者可自行查看。下面给出本人实现的核心代码:
#include"stdafx.h"
typedef struct
{
float B;
float b[];
} gauss_coefs; //参数计算
void compute_coefs3(gauss_coefs *c,float sigma)
{
float q, q2, q3;
if (sigma >= 2.5)
{
q = 0.98711 * sigma - 0.96330;
}
else if ((sigma >= 0.5) && (sigma < 2.5))
{
q = 3.97156 - 4.14554 * (float) sqrt ((float) - 0.26891 * sigma);
}
else
{
q = 0.1147705018520355224609375;
}
q2 = q * q;
q3 = q * q2;
c->b[] = /(1.57825+(2.44413*q)+(1.4281 *q2)+(0.422205*q3));
c->b[] = ( (2.44413*q)+(2.85619*q2)+(1.26661 *q3)) *c->b[];
c->b[] = ( -((1.4281*q2)+(1.26661 *q3)))*c->b[];
c->b[] = ( (0.422205*q3)) *c->b[];
c->B = 1.0-(c->b[]+c->b[]+c->b[]); } //IIR型高斯滤波
//**************************************************************//
//参考文献:Recursive implementation of the Gaussian filter
//Src:输入图像
//Dest:输出图像
//sigma:高斯标准差
//**************************************************************//
IS_RET IIRGaussianFilter(TMatrix *Src,TMatrix *Dest,float sigma)
{
int X,Y,Width=Src->Width,Height=Src->Height,Stride=Src->WidthStep,Channel=Src->Channel;
gauss_coefs c;
compute_coefs3(&c,sigma);
unsigned char *LinePS,*LinePD;
float *Buff,*BPointer,*w1,*w2;
Buff=(float*)malloc(sizeof(float)*Height*Width);//缓存
if(Buff==NULL){return IS_RET_ERR_OUTOFMEMORY;}
for(int i=;i<Channel;i++)
{
LinePS=Src->Data+i;
LinePD=Dest->Data+i;
//拷贝原图至缓存Buff
BPointer=Buff;
for (Y=;Y<Height;Y++)
{
for (X=;X<Width;X++)
{
BPointer[]=float(LinePS[]);
BPointer++;
LinePS+=Channel;
}
LinePS+=Stride-Width*Channel;
}
//横向滤波
BPointer=Buff;
w1=(float*)malloc(sizeof(float)*(Width+));
if(w1==NULL){return IS_RET_ERR_OUTOFMEMORY;}
w2=(float*)malloc(sizeof(float)*(Width+));
if(w2==NULL){return IS_RET_ERR_OUTOFMEMORY;}
for(Y=;Y<Height;Y++)
{
//前向滤波
w1[]=w1[]=w1[]=BPointer[];
for(int n=,i=;i<Width;n++,i++)
{
w1[n]=c.B*BPointer[i]+(c.b[]*w1[n-]+c.b[]*w1[n-]+c.b[]*w1[n-]);
}
//后向滤波
w2[Width]=w2[Width+]=w2[Width+]=w1[Width+];
for(int n=Width-;n>=;n--)
{
BPointer[n]=w2[n]=c.B*w1[n+]+(c.b[]*w2[n+]+c.b[]*w2[n+]+c.b[]*w2[n+]);
}
BPointer+=Width;
} //纵向滤波
BPointer=Buff;
w1=(float*)realloc(w1,sizeof(float)*(Height+));
if(w1==NULL){return IS_RET_ERR_OUTOFMEMORY;}
w2=(float*)realloc(w2,sizeof(float)*(Height+));
if(w2==NULL){return IS_RET_ERR_OUTOFMEMORY;}
for (X=;X<Width;X++)
{
//前向滤波
w1[]=w1[]=w1[]=BPointer[];
for(int n=,i=;i<Height;n++,i++)
{
w1[n]=c.B*BPointer[i*Width]+(c.b[]*w1[n-]+c.b[]*w1[n-]+c.b[]*w1[n-]);
}
//后向滤波
w2[Height]=w2[Height+]=w2[Height+]=w1[Height+];
for(int n=Height-;n>=;n--)
{
BPointer[n*Width]=w2[n]=c.B*w1[n+]+(c.b[]*w2[n+]+c.b[]*w2[n+]+c.b[]*w2[n+]);
}
BPointer++;
}
//拷贝缓存至结果
BPointer=Buff;
for(Y=;Y<Height;Y++)
{
for(X=;X<Width;X++)
{
LinePD[]=BPointer[];
if(BPointer[]>)LinePD[]=;
if(BPointer[]<)LinePD[]=;
BPointer++;
LinePD+=Channel;
}
LinePD+=Stride-Width*Channel;
}
free(w1);
free(w2);
}
return IS_RET_OK;
}
实验结果:对一幅1024*1024的彩色图像,算法耗时175ms。

参考文献:
Young I T, Van Vliet L J. Recursive implementation of the Gaussian filter[J]. Signal processing, 1995, 44(2): 139-151.
IIR型高斯滤波的原理及实现的更多相关文章
- OpenCV计算机视觉学习(4)——图像平滑处理(均值滤波,高斯滤波,中值滤波,双边滤波)
如果需要处理的原图及代码,请移步小编的GitHub地址 传送门:请点击我 如果点击有误:https://github.com/LeBron-Jian/ComputerVisionPractice &q ...
- 学习 opencv---(7) 线性邻域滤波专场:方框滤波,均值滤波,高斯滤波
本篇文章中,我们一起仔细探讨了OpenCV图像处理技术中比较热门的图像滤波操作.图像滤波系列文章浅墨准备花两次更新的时间来讲,此为上篇,为大家剖析了"方框滤波","均值滤 ...
- matlab做gaussian高斯滤波
原文链接:https://blog.csdn.net/humanking7/article/details/46826105 核心提示 在Matlab中高斯滤波非常方便,主要涉及到下面两个函数: 函数 ...
- matlab中fspecial Create predefined 2-D filter以及中值滤波均值滤波以及高斯滤波
来源: 1.https://ww2.mathworks.cn/help/images/ref/fspecial.html?searchHighlight=fspecial&s_tid=doc_ ...
- Atitit 图像处理 平滑 也称 模糊, 归一化块滤波、高斯滤波、中值滤波、双边滤波)
Atitit 图像处理 平滑 也称 模糊, 归一化块滤波.高斯滤波.中值滤波.双边滤波) 是一项简单且使用频率很高的图像处理方法 用途 去噪 去雾 各种线性滤波器对图像进行平滑处理,相关OpenC ...
- OpenCV实现的高斯滤波探究_1(《学习OpenCV》练习题第五章第三题ab部分)
首先看下OpenCV 官方文档对于cvSmooth各个参数的解释: Smooths the image in one of several ways. C: void cvSmooth(const C ...
- 基于MATLAB的中值滤波均值滤波以及高斯滤波的实现
基于MATLAB的中值滤波均值滤波以及高斯滤波的实现 作者:lee神 1. 背景知识 中值滤波法是一种非线性平滑技术,它将每一像素点的灰度值设置为该点某邻域窗口内的所有像素点灰度值的中值. 中值滤 ...
- 基于opencv下对视频的灰度变换,高斯滤波,canny边缘检测处理,同窗体显示并保存
如题:使用opencv打开摄像头或视频文件,实时显示原始视频,将视频每一帧依次做灰度转换.高斯滤波.canny边缘检测处理(原始视频和这3个中间步骤处理结果分别在一个窗口显示),最后将边缘检测结果保存 ...
- opencv3.2.0图像处理之高斯滤波GaussianBlur API函数
/*高斯滤波:GaussianBlur函数 函数原型: void GaussianBlur( InputArray src, OutputArray dst, Size ksize, double s ...
随机推荐
- vs2010 msvcr100.DLL 丢失!!! 用release 就可以了
- java sleep和wait的区别和联系
Thread.sleep不会改变锁的行为,如果当前线程拥有锁,那么当前线程sleep之后,该锁不会被释放. Thread.sleep和Object.wait都会暂停当前的线程,让出cpu.Thread ...
- JAVA中Stack和Heap的区别
http://m.blog.csdn.net/wl_ldy/article/details/5935528
- android studio Error:Unable to tunnel through proxy. Proxy returns "HTTP/1.1 400 Bad Request"
android studio运行会遇到Error:Unable to tunnel through proxy. Proxy returns "HTTP/1.1 400 Bad Reques ...
- Linux Linker
文章原文:http://zhidao.baidu.com/link?url=U2Mtcc6BKi4vuQ1MO8U6s9gNm4y9Epphz03veA2lVpRWMozyVdj0PYvw1ZU9qj ...
- log4j 路径环境变量配置和log4j加载配置
1.lo4j日志路径从环境变量读取,log4j.xml配置如下: 具体配置如下: log4j.appender.R.Encoding=UTF-8 log4j.appender.R=org.apache ...
- SDUT 3033 这题实在不知道起啥名好了(思维巧法)
这题实在不知道起啥名好了 Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 懒得想背景故事了,开门见山. 有一个长度为n的整数数列A ...
- java性能时间与空间消耗
Java性能时间与空间消耗 一.减少时间消耗 标准代码优化 (1) 将循环不变量的计算移出循环 例如:for (int i=0; i<size()*2; i++) { ... } ------& ...
- codeforces B. 4-point polyline 解题报告
题目链接:http://codeforces.com/problemset/problem/452/B 题目意思:给出一个长为n,宽为 m 的矩形,要从这里面(包括边上)找出4个不同的点,使得以某一个 ...
- NOIP2005题解
传送门 考查题型 dp 模拟 贪心 T1 谁拿了最多的奖学金 题目描述 某校的惯例是在每学期的期末考试之后发放奖学金.发放的奖学金共有五种,获取的条件各自不同: 1) 院士奖学金,每人8000元,期末 ...