Filters.h各种信号恢复滤波器头文件
这篇文章有部分原理:http://blog.csdn.net/u013467442/article/details/41125473
代码下载地址:http://read.pudn.com/downloads125/sourcecode/app/529186/source/3rdParty/FreeImage/FreeImageToolkit/Filters.h__.htm
// ==========================================================
// Upsampling / downsampling filters
//
// Design and implementation by
// - Herv� Drolon (drolon@infonie.fr)
//
// This file is part of FreeImage 3
//
// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES
// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE
// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED
// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT
// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY
// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL
// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER
// THIS DISCLAIMER.
//
// Use at your own risk!
// ========================================================== #ifndef _FILTERS_H_
#define _FILTERS_H_ /**
CGenericFilter is a generic abstract filter class used to access to the filter library.<br>
Filters used in this library have been mainly taken from the following references : <br>
<b>Main reference</b> : <br>
Paul Heckbert, C code to zoom raster images up or down, with nice filtering.
UC Berkeley, August 1989. [online] http://www-2.cs.cmu.edu/afs/cs.cmu.edu/Web/People/ph/heckbert.html <b>Heckbert references</b> : <br>
<ul>
<li>Oppenheim A.V., Schafer R.W., Digital Signal Processing, Prentice-Hall, 1975
<li>Hamming R.W., Digital Filters, Prentice-Hall, Englewood Cliffs, NJ, 1983
<li>Pratt W.K., Digital Image Processing, John Wiley and Sons, 1978
<li>Hou H.S., Andrews H.C., "Cubic Splines for Image Interpolation and Digital Filtering",
IEEE Trans. Acoustics, Speech, and Signal Proc., vol. ASSP-26, no. 6, pp. 508-517, Dec. 1978.
</ul> */
class CGenericFilter
{
protected: #define FILTER_PI double (3.1415926535897932384626433832795)
#define FILTER_2PI double (2.0 * 3.1415926535897932384626433832795)
#define FILTER_4PI double (4.0 * 3.1415926535897932384626433832795) /// Filter support
double m_dWidth; public: /// Constructor
CGenericFilter (double dWidth) : m_dWidth (dWidth) {}
/// Destructor
virtual ~CGenericFilter() {} /// Returns the filter support
double GetWidth() { return m_dWidth; }
/// Change the filter suport
void SetWidth (double dWidth) { m_dWidth = dWidth; } /// Returns F(dVal) where F is the filter's impulse response
virtual double Filter (double dVal) = 0;
}; // -----------------------------------------------------------------------------------
// Filters library
// All filters are centered on 0
// ----------------------------------------------------------------------------------- /**
Box filter<br>
Box, pulse, Fourier window, 1st order (constant) b-spline.<br><br> <b>Reference</b> : <br>
Glassner A.S., Principles of digital image synthesis. Morgan Kaufmann Publishers, Inc, San Francisco, Vol. 2, 1995
*/
class CBoxFilter : public CGenericFilter
{
public:
/**
Constructor<br>
Default fixed width = 0.5
*/
CBoxFilter() : CGenericFilter(0.5) {}
virtual ~CBoxFilter() {} double Filter (double dVal) { return (fabs(dVal) <= m_dWidth ? 1.0 : 0.0); }
}; /** Bilinear filter
*/
class CBilinearFilter : public CGenericFilter
{
public: CBilinearFilter () : CGenericFilter(1) {}
virtual ~CBilinearFilter() {} double Filter (double dVal) {
dVal = fabs(dVal);
return (dVal < m_dWidth ? m_dWidth - dVal : 0.0);
}
}; /**
Mitchell & Netravali's two-param cubic filter<br> The parameters b and c can be used to adjust the properties of the cubic.
They are sometimes referred to as "blurring" and "ringing" respectively.
The default is b = 1/3 and c = 1/3, which were the values recommended by
Mitchell and Netravali as yielding the most visually pleasing results in subjective tests of human beings.
Larger values of b and c can produce interesting op-art effects--for example, try b = 0 and c = -5. <br><br> <b>Reference</b> : <br>
Don P. Mitchell and Arun N. Netravali, Reconstruction filters in computer graphics.
In John Dill, editor, Computer Graphics (SIGGRAPH '88 Proceedings), Vol. 22, No. 4, August 1988, pp. 221-228.
*/
class CBicubicFilter : public CGenericFilter
{
protected:
// data for parameterized Mitchell filter
double p0, p2, p3;
double q0, q1, q2, q3; public:
/**
Constructor<br>
Default fixed width = 2
@param b Filter parameter (default value is 1/3)
@param c Filter parameter (default value is 1/3)
*/
CBicubicFilter (double b = (1/(double)3), double c = (1/(double)3)) : CGenericFilter(2) {
p0 = (6 - 2*b) / 6;
p2 = (-18 + 12*b + 6*c) / 6;
p3 = (12 - 9*b - 6*c) / 6;
q0 = (8*b + 24*c) / 6;
q1 = (-12*b - 48*c) / 6;
q2 = (6*b + 30*c) / 6;
q3 = (-b - 6*c) / 6;
}
virtual ~CBicubicFilter() {} double Filter(double dVal) {
dVal = fabs(dVal);
if(dVal < 1)
return (p0 + dVal*dVal*(p2 + dVal*p3));
if(dVal < 2)
return (q0 + dVal*(q1 + dVal*(q2 + dVal*q3)));
return 0;
}
}; /**
Catmull-Rom spline, Overhauser spline<br> When using CBicubicFilter filters, you have to set parameters b and c such that <br>
b + 2 * c = 1<br>
in order to use the numerically most accurate filter.<br>
This gives for b = 0 the maximum value for c = 0.5, which is the Catmull-Rom
spline and a good suggestion for sharpness.<br><br> <b>References</b> : <br>
<ul>
<li>Mitchell Don P., Netravali Arun N., Reconstruction filters in computer graphics.
In John Dill, editor, Computer Graphics (SIGGRAPH '88 Proceedings), Vol. 22, No. 4, August 1988, pp. 221-228.
<li>Keys R.G., Cubic Convolution Interpolation for Digital Image Processing.
IEEE Trans. Acoustics, Speech, and Signal Processing, vol. 29, no. 6, pp. 1153-1160, Dec. 1981.
</ul> */
class CCatmullRomFilter : public CGenericFilter
{
public: /**
Constructor<br>
Default fixed width = 2
*/
CCatmullRomFilter() : CGenericFilter(2) {}
virtual ~CCatmullRomFilter() {} double Filter(double dVal) {
if(dVal < -2) return 0;
if(dVal < -1) return (0.5*(4 + dVal*(8 + dVal*(5 + dVal))));
if(dVal < 0) return (0.5*(2 + dVal*dVal*(-5 - 3*dVal)));
if(dVal < 1) return (0.5*(2 + dVal*dVal*(-5 + 3*dVal)));
if(dVal < 2) return (0.5*(4 + dVal*(-8 + dVal*(5 - dVal))));
return 0;
}
}; /**
Lanczos-windowed sinc filter<br> Lanczos3 filter is an alternative to CBicubicFilter with high values of c about 0.6 ... 0.75
which produces quite strong sharpening. It usually offers better quality (fewer artifacts) and a sharp image.<br><br> */
class CLanczos3Filter : public CGenericFilter
{
public:
/**
Constructor<br>
Default fixed width = 3
*/
CLanczos3Filter() : CGenericFilter(3) {}
virtual ~CLanczos3Filter() {} double Filter(double dVal) {
dVal = fabs(dVal);
if(dVal < m_dWidth) {
return (sinc(dVal) * sinc(dVal / m_dWidth));
}
return 0;
} private:
double sinc(double value) {
if(value != 0) {
value *= FILTER_PI;
return (sin(value) / value);
}
return 1;
}
}; /**
4th order (cubic) b-spline<br> */
class CBSplineFilter : public CGenericFilter
{
public: /**
Constructor<br>
Default fixed width = 2
*/
CBSplineFilter() : CGenericFilter(2) {}
virtual ~CBSplineFilter() {} double Filter(double dVal) { dVal = fabs(dVal);
if(dVal < 1) return (4 + dVal*dVal*(-6 + 3*dVal)) / 6;
if(dVal < 2) {
double t = 2 - dVal;
return (t*t*t / 6);
}
return 0;
}
}; // -----------------------------------------------------------------------------------
// Window function library
// ----------------------------------------------------------------------------------- /**
Blackman window
*/
class CBlackmanFilter : public CGenericFilter
{
public:
/**
Constructor<br>
Default width = 0.5
*/
CBlackmanFilter (double dWidth = double(0.5)) : CGenericFilter(dWidth) {}
virtual ~CBlackmanFilter() {} double Filter (double dVal) {
if(fabs (dVal) > m_dWidth) {
return 0;
}
double dN = 2 * m_dWidth + 1;
dVal /= (dN - 1);
return 0.42 + 0.5*cos(FILTER_2PI*dVal) + 0.08*cos(FILTER_4PI*dVal);
}
}; #endif // _FILTERS_H_
Filters.h各种信号恢复滤波器头文件的更多相关文章
- 在.h和.cpp中包含头文件的区别
1.在.h中包含头文件,是为了声明一系列这个头文件的变量等,可能会产生重复包含的问题: 2.在.cpp中包含头文件只是为了实现这个头文件或者使用其中的方法,不会有重复包含的问题,所以尽量在源文件中包含 ...
- 单片机中用c编程时头文件reg51.h及reg52.h解析
单片机中用c编程时头文件reg51.h及reg52.h解析 我们在用c语言编程是往往第一行就是reg51.h或者其他的自定义头文件,我们怎么样来理解呢? 1)“文件包含”处理. 程序的第一行是一个“文 ...
- C/C++关于string.h头文件和string类
学习C语言时,用字符串的函数例如stpcpy().strcat().strcmp()等,要包含头文件string.h 学习C++后,C++有字符串的标准类string,string类也有很多方法,用s ...
- C++头文件#include<bits/stdc++.h>
一句话的事,直截了当——#include<bits/stdc++.h>包含C++的所有头文件 参考网站(点击):http://www.tuicool.com/articles/m6neUj ...
- C++预编译头文件 – stdafx.h
预编译头文件的由来 也许请教了别的高手之后,他们会告诉你,这是预编译头,必须包含.可是,这到底是为什么呢?预编译头有什么用呢? 咱们从头文件的编译原理讲起.其实头文件并不神秘,其在编译时的作用,就是把 ...
- 转载:C/C++关于string.h头文件和string类
学习C语言时,用字符串的函数例如stpcpy().strcat().strcmp()等,要包含头文件string.h 学习C++后,C++有字符串的标准类string,string类也有很多方法,用s ...
- visual c++ 中的stdafx.h头文件的作用
stdafx.h VC工程里面经常见到stdafx.h这个头文件,以前也没有特别注意,但是这个文件用不好经常会出错,所以就GOOGLE了一下,总算是弄清楚了... stdafx的英文全称为:Stand ...
- Visual Studio中头文件stdafx.h的作用
在较新版的Visual Studio中,新生成的C++项目文件的的头文件夹下会默认有头文件stdafx.h,而源文件夹下则默认有源文件stdafx.cpp,手动将这些文件删除后,编译时系统还会报错.下 ...
- 浅谈头文件(.h)和源文件(.cpp)的区别
浅谈头文件(.h)和源文件(.cpp)的区别 本人原来在大一写C的时候,都是所有代码写在一个文件里一锅乱煮.经过自己开始写程序之后,发现一个工程只有一定是由多个不同功能.分门别类展开的文件构成的.一锅 ...
随机推荐
- 程序员必知的LinuxShell命令
程序员必知的LinuxShell命令 grep (Globle Regular Expression Print全局正则表达式) 命令是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹 配的 ...
- C语言常见问题总结
1.多次运行程序 解决方法: 错误原因是,已经编译运行出一个exe,没有关闭此exe,又点击编译运行. 应该将之前运行出的exe关闭,再来运行代码 2.单精度类型和双精度类型如何区分使用... 解决方 ...
- Linux 学习(四)
搭建jdk 安装jdk操作: 1.光驱挂载:mount /dev/cdrom /mnt 2.拷贝安装包至其他文件夹(如home目录下) 3.执行安装包(bin包:./包名) 4.配置环境变量:打开文件 ...
- NVIDIA各个领域芯片现阶段的性能和适应范围
NVIDIA作为老牌显卡厂商,在AI领域深耕多年.功夫不负有心人,一朝AI火,NVIDIA大爆发,NVIDIA每年送给科研院所和高校的大量显卡,大力推广Physix和CUDA,终于钓了产业的大鱼. 由 ...
- x86汇编之十(使用字符串)
x86汇编之十(使用字符串) 转自网络,出处不详 一.传送字符串 Intel提供了完整的字符串传送指令,就像是MOV指令一样. 1.MOVS指令 1)movs指令格式 把字符串从一个位内存位置传送到另 ...
- 00Cascading Style Sheet
Cascading Style Sheet CSS(Cascading Style Sheet)即层叠样式表,简称样式表.要理解层叠样式表的概念先要理解样式的概念.样式就是对网页中的 元素(字体.段落 ...
- 100 道 Linux 笔试题,能拿 80 分就算大神!
本套笔试题共100题,每题1分,共100分.(参考答案在文章末尾) 1. cron 后台常驻程序 (daemon) 用于: A. 负责文件在网络中的共享 B. 管理打印子系统C. 跟踪管理系统信息和错 ...
- 网络编程 - 简单的socket例子
1.客户端 #客户端import socketclient=socket.socket() #生成socket连接对象client.connect(("localhost",696 ...
- Spring自定义拦截器
HandlerInterceptorAdapter由Spring MVC提供,用来拦截请求. 实现自定义拦截器需要继承HandlerInterceptorAdapter或实现HandlerInterc ...
- Extjs查询实现
效果图如上: 页面代码: Ext.QuickTips.init(); //放在图标上会自动提示信息 Ext.define('ExtApp.view.StudentList' , { extend : ...