求图像滤波函数代码c语言(图像中值滤波算法)
admin 发布:2022-12-19 20:34 176
今天给各位分享求图像滤波函数代码c语言的知识,其中也会对图像中值滤波算法进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:
- 1、一段matlab低通滤波器程序,求改编成C语言。
- 2、帮帮忙,能不能给我 基于C语言的FIR滤波器设计的程序代码(包括CMD,C,ASM),谢谢了 真的很急!!!
- 3、急急急!图像逆滤波与维纳滤波的程序代码(matlab)
- 4、请教C语言卡尔曼滤波算法
- 5、C语言实现fir1函数
一段matlab低通滤波器程序,求改编成C语言。
这个我刚好做过一个滤波器,事实上对时域信号做FFT,截取一定点数再做逆FFT相当于理想滤波。设计滤波器代码如下:
f1=100;f2=200;%待滤波正弦信号频率
fs=2000;%采样频率
m=(0.3*f1)/(fs/2);%定义过度带宽
M=round(8/m);%定义窗函数的长度
N=M-1;%定义滤波器的阶数
b=fir1(N,f2/fs);%使用fir1函数设计滤波器
%输入的参数分别是滤波器的阶数和截止频率
figure(1)
[h,f]=freqz(b,1,512);%滤波器的幅频特性图
%[H,W]=freqz(B,A,N)当N是一个整数时函数返回N点的频率向量和幅频响应向量
plot(f*fs/(2*pi),20*log10(abs(h)))%参数分别是频率与幅值
xlabel('频率/赫兹');ylabel('增益/分贝');title('滤波器的增益响应');
figure(2)
subplot(211)
t=0:1/fs:0.5;%定义时间范围和步长
s=sin(2*pi*f1*t)+sin(2*pi*f2*t);%滤波前信号
plot(t,s);%滤波前的信号图像
xlabel('时间/秒');ylabel('幅度');title('信号滤波前时域图');
subplot(212)
Fs=fft(s,512);%将信号变换到频域
AFs=abs(Fs);%信号频域图的幅值
f=(0:255)*fs/512;%频率采样
plot(f,AFs(1:256));%滤波前的信号频域图
xlabel('频率/赫兹');ylabel('幅度');title('信号滤波前频域图');
figure(3)
sf=filter(b,1,s);%使用filter函数对信号进行滤波
%参数分别为滤波器系统函数的分子和分母多项式系数向量和待滤波信号输入
subplot(211)
plot(t,sf)%滤波后的信号图像
xlabel('时间/秒');ylabel('幅度');title('信号滤波后时域图');
axis([0.2 0.5 -2 2]);%限定图像坐标范围
subplot(212)
Fsf=fft(sf,512);%滤波后的信号频域图
AFsf=abs(Fsf);%信号频域图的幅值
f=(0:255)*fs/512;%频率采样
plot(f,AFsf(1:256))%滤波后的信号频域图
xlabel('频率/赫兹');ylabel('幅度');title('信号滤波后频域图');
帮帮忙,能不能给我 基于C语言的FIR滤波器设计的程序代码(包括CMD,C,ASM),谢谢了 真的很急!!!
#include"math.h"
void firwin(n,band,fln,fhn,wn,h)
int n,band,wn;
double fln,fhn,h[];
{int i,n2,mid;
double s,pi,wc1,wc2,beta,delay;
double window();
beta=0.0;
if(wn==7)
{printf("input beta parameter of Kaiser window(2beta10)\n");
scanf("%1f",beta);
}
pi=4.0*atan(1.0);
if((n%2)==0)/*如果n是偶数*/
{n2=n/2+1;/*这行什么意思*/
mid=1;
}
else
{n2=n/2;
mid=0;
}
delay=n/2.0;
wc1=2.0*pi*fln;
if(band=3) wc2=2.0*pi*fhn;/*先判断用户输入的数据,如果band参数大于3*/
switch(band)
{case 1:
{for(i=0;i=n2;i++)
{s=i-delay;
h[i]=(sin(wc1*s)/(pi*s))*window(wn,n+1,i,beta);
h[n-i]=h[i];
}
if(mid==1) h[n/2]=wc1/pi;
break;
}
case 2:
{for(i=0;i=n2;i++)
{s=i-delay;
h[i]=(sin(pi*s)-sin(wc1*s))/(pi*s);
h[i]=h[i]*window(wn,n+1,i,beta);
h[n-i]=h[i];
}
if(mid==1) h[n/2]=1.0-wc1/pi;
break;
}
case 3:
{for(i=0;in2;i++)
{s=i-delay;
h[i]=(sin(wc2*s)-sin(wc1*s))/(pi*s);
h[i]=h[i]*window(wn,n+1,i,beta);
h[n-i]=h[i];
}
if(mid==1)h[n/2]=(wc2-wc1)/pi;
break;
}
case 4:
{for(i=0;i=n2;i++)
{s=i-delay;
h[i]=(sin(wc1*s)+sin(pi*s)-sin(wc2*s))/(pi*s);
h[i]=h[i]*window(wn,n+1,i,beta);
h[n-i]=h[i];
}
if(mid==1)h[n/2]=(wc1+pi-wc2)/pi;
break;
}
}
}
static double window(type,n,i,beta)
int i,n,type;
double beta;
{int k;
double pi,w;
double kaiser();
pi=4.0*atan(1.0);
w=1.0;
switch(type)
{case 1:
{w=1.0;
break;
}
case 2:
{k=(n-2)/10;
if(i=k)
w=0.5*(1.0-cos(i*pi/(k+1)));
break;
}
case 3:
{w=1.0-fabs(1.0-2*i/(n-1.0));
break;
}
case 4:
{w=0.5*(1.0-cos(2*i*pi/(n-1)));
break;
}
case 5:
{w=0.54-0.46*cos(2*i*pi/(n-1));
break;
}
case 6:
{w=0.42-0.5*cos(2*i*pi/(n-1))+0.08*cos(4*i*pi/(n-1));
break;
}
case 7:
{w=kaiser(i,n,beta);
break;
}
}
return(w);
}
static double kaiser(i,n,beta)
int i,n;
double beta;
{
double a,w,a2,b1,b2,beta1;
double bessel0();
b1=bessel0(beta);
a=2.0*i/(double)(n-1)-1.0;
a2=a*a;
beta1=beta*sqrt(1.0-a2);
b2=bessel0(beta1);
w=b2/b1;
return(w);
}
static double bessel0(x)
double x;
{int i;
double d,y,d2,sum;
y=x/2.0;
d=1.0;
sum=1.0;
for(i=1;i=25;i++)
{d=d*y/i;
d2=d*d;
sum=sum+d2;
if(d2sum*(1.0e-8)) break;
}
return(sum);
}
这是窗函数法的,当然还有其他的比如切比雪夫,零相位滤波什么的,我也在研究,不是很懂哈
急急急!图像逆滤波与维纳滤波的程序代码(matlab)
clc;clear all;
%读原始图像%
format long
Blurred=imread('fig525(b).bmp');
subplot(1,2,1);imshow( Blurred);title('原图像');
%自编函数进行维纳滤波%
k=0.0025;
[m,n]=size(Blurred);
spectrum=zeros(m,n);
H=zeros(m,n);
for u=1:m
for v=1:n
H(u,v)=exp(-k*((u-m/2)^2+(v-n/2)^2)^(5/6));
spectrum(u,v)=H(u,v)^2;
end
end
f=double(Blurred);
F1=fftshift(fft2(f));
HW=H./(spectrum+0.001);
restore1=HW.*F1;
restored=real(ifft2(ifftshift(restore1)));
subplot(1,2,2);imshow(restored,[]);title('自编函数进行维纳滤波');
%调用matlab提供的维纳滤波函数%
figure;
hw1=real(ifft2(ifftshift(H)));%转化到空域上来
result1=deconvwnr(Blurred,hw1,0.001);
result2=ifftshift(result1);%再去图像进行1,3象限对调,2与4象限对调
subplot(1,2,1);imshow(result2,[]);title('调用维纳滤波函数');
请教C语言卡尔曼滤波算法
网上能找到一些程序。
例如,卡尔曼滤波简介+ 算法实现代码 :
较详细地 提供了 C 和 C++ 程序。可以同他的方法比较一下,如果结果接近,
则你的算法没问题。
C语言实现fir1函数
#include stdio.h
#ifdef WIN32
#include conio.h
#endif
#define SAMPLE double /* define the type used for data samples */
void clear(int ntaps, SAMPLE z[])
{
int ii;
for (ii = 0; ii ntaps; ii++) {
z[ii] = 0;
}
}
SAMPLE fir_basic(SAMPLE input, int ntaps, const SAMPLE h[], SAMPLE z[])
{
int ii;
SAMPLE accum;
/* store input at the beginning of the delay line */
z[0] = input;
/* calc FIR */
accum = 0;
for (ii = 0; ii ntaps; ii++) {
accum += h[ii] * z[ii];
}
/* shift delay line */
for (ii = ntaps - 2; ii = 0; ii--) {
z[ii + 1] = z[ii];
}
return accum;
}
SAMPLE fir_circular(SAMPLE input, int ntaps, const SAMPLE h[], SAMPLE z[],
int *p_state)
{
int ii, state;
SAMPLE accum;
state = *p_state; /* copy the filter's state to a local */
/* store input at the beginning of the delay line */
z[state] = input;
if (++state = ntaps) { /* incr state and check for wrap */
state = 0;
}
/* calc FIR and shift data */
accum = 0;
for (ii = ntaps - 1; ii = 0; ii--) {
accum += h[ii] * z[state];
if (++state = ntaps) { /* incr state and check for wrap */
state = 0;
}
}
*p_state = state; /* return new state to caller */
return accum;
}
SAMPLE fir_shuffle(SAMPLE input, int ntaps, const SAMPLE h[], SAMPLE z[])
{
int ii;
SAMPLE accum;
/* store input at the beginning of the delay line */
z[0] = input;
/* calc FIR and shift data */
accum = h[ntaps - 1] * z[ntaps - 1];
for (ii = ntaps - 2; ii = 0; ii--) {
accum += h[ii] * z[ii];
z[ii + 1] = z[ii];
}
return accum;
}
SAMPLE fir_split(SAMPLE input, int ntaps, const SAMPLE h[], SAMPLE z[],
int *p_state)
{
int ii, end_ntaps, state = *p_state;
SAMPLE accum;
SAMPLE const *p_h;
SAMPLE *p_z;
/* setup the filter */
accum = 0;
p_h = h;
/* calculate the end part */
p_z = z + state;
*p_z = input;
end_ntaps = ntaps - state;
for (ii = 0; ii end_ntaps; ii++) {
accum += *p_h++ * *p_z++;
}
/* calculate the beginning part */
p_z = z;
for (ii = 0; ii state; ii++) {
accum += *p_h++ * *p_z++;
}
/* decrement the state, wrapping if below zero */
if (--state 0) {
state += ntaps;
}
*p_state = state; /* return new state to caller */
return accum;
}
SAMPLE fir_double_z(SAMPLE input, int ntaps, const SAMPLE h[], SAMPLE z[],
int *p_state)
{
SAMPLE accum;
int ii, state = *p_state;
SAMPLE const *p_h, *p_z;
/* store input at the beginning of the delay line as well as ntaps more */
z[state] = z[state + ntaps] = input;
/* calculate the filter */
p_h = h;
p_z = z + state;
accum = 0;
for (ii = 0; ii ntaps; ii++) {
accum += *p_h++ * *p_z++;
}
/* decrement state, wrapping if below zero */
if (--state 0) {
state += ntaps;
}
*p_state = state; /* return new state to caller */
return accum;
}
SAMPLE fir_double_h(SAMPLE input, int ntaps, const SAMPLE h[], SAMPLE z[],
int *p_state)
{
SAMPLE accum;
int ii, state = *p_state;
SAMPLE const *p_h, *p_z;
/* store input at the beginning of the delay line */
z[state] = input;
/* calculate the filter */
p_h = h + ntaps - state;
p_z = z;
accum = 0;
for (ii = 0; ii ntaps; ii++) {
accum += *p_h++ * *p_z++;
}
/* decrement state, wrapping if below zero */
if (--state 0) {
state += ntaps;
}
*p_state = state; /* return new state to caller */
return accum;
}
int main(void)
{
#define NTAPS 6
static const SAMPLE h[NTAPS] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 };
static SAMPLE h2[2 * NTAPS];
static SAMPLE z[2 * NTAPS];
#define IMP_SIZE (3 * NTAPS)
static SAMPLE imp[IMP_SIZE];
SAMPLE output;
int ii, state;
/* make impulse input signal */
clear(IMP_SIZE, imp);
imp[5] = 1.0;
/* create a SAMPLEd h */
for (ii = 0; ii NTAPS; ii++) {
h2[ii] = h2[ii + NTAPS] = h[ii];
}
/* test FIR algorithms */
printf("Testing fir_basic:\n ");
clear(NTAPS, z);
for (ii = 0; ii IMP_SIZE; ii++) {
output = fir_basic(imp[ii], NTAPS, h, z);
printf("%3.1lf ", (double) output);
}
printf("\n\n");
printf("Testing fir_shuffle:\n ");
clear(NTAPS, z);
state = 0;
for (ii = 0; ii IMP_SIZE; ii++) {
output = fir_shuffle(imp[ii], NTAPS, h, z);
printf("%3.1lf ", (double) output);
}
printf("\n\n");
printf("Testing fir_circular:\n ");
clear(NTAPS, z);
state = 0;
for (ii = 0; ii IMP_SIZE; ii++) {
output = fir_circular(imp[ii], NTAPS, h, z, state);
printf("%3.1lf ", (double) output);
}
printf("\n\n");
printf("Testing fir_split:\n ");
clear(NTAPS, z);
state = 0;
for (ii = 0; ii IMP_SIZE; ii++) {
output = fir_split(imp[ii], NTAPS, h, z, state);
printf("%3.1lf ", (double) output);
}
printf("\n\n");
printf("Testing fir_double_z:\n ");
clear(2 * NTAPS, z);
state = 0;
for (ii = 0; ii IMP_SIZE; ii++) {
output = fir_double_z(imp[ii], NTAPS, h, z, state);
printf("%3.1lf ", (double) output);
}
printf("\n\n");
printf("Testing fir_double_h:\n ");
clear(NTAPS, z);
state = 0;
for (ii = 0; ii IMP_SIZE; ii++) {
output = fir_double_h(imp[ii], NTAPS, h2, z, state);
printf("%3.1lf ", (double) output);
}
#ifdef WIN32
printf("\n\nHit any key to continue.");
getch();
#endif
return 0;
}
1. fir_basic: 实现基本的FIR滤波器
2. fir_circular: 说明环行buffer是如何实现FIR的。
3. fir_shuffle: 一些TI的处理器上使用的shuffle down技巧
4. fir_split: 把FIR滤波器展开为两块,避免使用环行缓存。
5. fir_double_z: 使用双精度的延迟线,使可以使用一个flat buffer。
6. fir_double_h: 使用双精度的系数,使可以使用一个flat buffer。
关于求图像滤波函数代码c语言和图像中值滤波算法的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。
版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;
相关推荐
- 04-28贴吧自动签到代码(贴吧的一键签到)[20240428更新]
- 04-28怎么看小游戏的代码(如何查看手机游戏的代码)[20240428更新]
- 04-28网页缩放代码(网页的缩放)[20240428更新]
- 04-28购物网页制作代码(购物网页制作代码大全)[20240428更新]
- 04-28识别图片文字的代码(识别图片文字的代码是什么)[20240428更新]
- 04-28源代码和二进制代码(有二进制版本的,但源代码是后来的)[20240428更新]
- 04-28mfc五子棋代码(cmd五子棋代码)[20240428更新]
- 04-28用php获取第三方接口网址代码(php 访问接口)[20240428更新]
- 04-28android锁屏代码(android锁屏密码解锁)[20240428更新]
- 04-28通过鼠标滑动切换界面的代码(鼠标拖动窗口总是滑动)[20240428更新]
取消回复欢迎 你 发表评论:
- 标签列表
- 最近发表
-
- 视频互联网推广选择隐迅推,视频互联网推广选择隐迅推广的原因
- mfc五子棋代码(cmd五子棋代码)[20240428更新]
- 医药供货网页源代码(医药厂家直供货源平台)[20240428更新]
- 可以免费做网站推广的平台,哪些网站可以免费做推广
- 网页文件上传源代码(上传文件的网页)[20240428更新]
- 用php获取第三方接口网址代码(php 访问接口)[20240428更新]
- android锁屏代码(android锁屏密码解锁)[20240428更新]
- 通过鼠标滑动切换界面的代码(鼠标拖动窗口总是滑动)[20240428更新]
- 百度网盘会员,百度网盘会员到期后超出的容量怎么办
- f网自己的代码(F是什么代码)[20240428更新]
- 友情链接