MATLAB滤波代码
来源:互联网 发布:java 主要开源项目 编辑:程序博客网 时间:2024/04/30 14:27
clear all;clc;
%FFT变换
I=imread('cameraman.tif');
A1=fft2(I);
A2=ifft2(A1);
A3=uint8(A2);
figure,subplot(221),imshow(I);
subplot(222);imshow(A3);
%DCT变换
I=imread('cameraman.tif');
figure,subplot(223);imshow(I);
I=im2double(I);
T=dctmtx(8);
B=blkproc(I,[8 8], 'P1*x*P2',T,T');
Mask=[1 1 1 1 0 0 0 0
1 1 1 0 0 0 0 0
1 1 0 0 0 0 0 0
1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0];
B2=blkproc(B,[8 8],'P1.*x',Mask); % 此处为点乘(.*)
I2=blkproc(B2,[8 8], 'P1*x*P2',T',T);
subplot(224);imshow(I2);
%直方图均衡
I=imread('pout.tif');
figure,subplot(321);imshow(I);
subplot(322);imhist(I);
[J,T]=histeq(I,64); % 图像灰度扩展到0~255,但是只有64个灰度级
subplot(323);imshow(J);
subplot(324);imhist(J);
J=histeq(I,32);
subplot(325);imshow(J); % 图像灰度扩展到0~255,但是只有32个灰度级
subplot(326);imhist(J);
figure,plot((0:255)/255,T); % 转移函数的变换曲线
%灰度拉伸
I=imread('pout.tif');
figure,subplot(221);imshow(I);
subplot(222);imhist(I);
[X,map]=imread('pout.tif');
Y=imadjust(X,[0.1 0.99],[0 1]);
subplot(223);imshow(Y,map);
subplot(224);imhist(Y);
% 图像空间域处理
[I,map] = imread('pout.tif');
J1=imnoise(I,'gaussian',0,0.02);
% 叠加均值为0,方差为0.02的高斯噪声,可以用localvar代替
%J2=imnoise(I,'salt & pepper',0.04); % 叠加密度为0.04的椒盐噪声
M4=[0 1 0; 1 0 1; 0 1 0];
M4=M4/4; % 4邻域平均滤波
I_filter1=filter2(M4,J1);
figure,subplot(321);imshow(I);
subplot(322);imshow(J1);
subplot(323);imshow(I_filter1,map);
M8=[1 1 1; 1 0 1; 1 1 1]; % 8邻域平均滤波
M8=M8/8;
I_filter2=filter2(M8,J1);
subplot(324);imshow(I_filter2,map);
K1 = medfilt2(J1,[3,3]);
subplot(325);imshow(K1);
K2=medfilt2(J2,[7 7]);
subplot(326);imshow(K2);
%频域处理
I=imread('pout.tif');
figure,subplot(221);imshow(I);
J1=imnoise(I,'salt & pepper'); % 叠加椒盐噪声
subplot(222);imshow(J1);
f=double(J1); % 数据类型转换,MATLAB不支持图像的无符号整型的计算
g=fft2(f); % 傅立叶变换
g=fftshift(g); % 转换数据矩阵
[M,N]=size(g);
nn=2; % 二阶巴特沃斯(Butterworth)低通滤波器
d0=50;
m=fix(M/2); n=fix(N/2);
for i=1:M
for j=1:N
d=sqrt((i-m)^2+(j-n)^2);
h=1/(1+0.414*(d/d0)^(2*nn)); % 计算低通滤波器传递函数
result(i,j)=h*g(i,j);
end
end
result=ifftshift(result);
J2=ifft2(result);
J3=uint8(real(J2));
subplot(223);imshow(J3); % 显示滤波处理后的图像
[I,map]=imread('pout.tif');
figure,subplot(221);imshow(I,map);
H2=[-1 -1 -1;-1 -9 -1;-1 -1 -1];
J1=filter2(H2,I); % 高通滤波
subplot(222);imshow(J1,map);
I=imread('pout.tif');
figure,subplot(221);imshow(I);
f=double(I); % 数据类型转换,MATLAB不支持图像的无符号整型的计算
g=fft2(f); % 傅立叶变换
g=fftshift(g); % 转换数据矩阵
[M,N]=size(g);
nn=2; % 二阶巴特沃斯(Butterworth)高通滤波器
d0=5;
m=fix(M/2);
n=fix(N/2);
for i=1:M
for j=1:N
d=sqrt((i-m)^2+(j-n)^2);
if (d==0)
h=0;
else
h=1/(1+0.414*(d0/d)^(2*nn));% 计算传递函数
end
result(i,j)=h*g(i,j);
end
end
result=ifftshift(result);
J2=ifft2(result);
J3=uint8(real(J2));
subplot(222);imshow(J3); % 滤波后图像显示
end
- MATLAB滤波代码
- 双边滤波matlab代码
- 粒子滤波Matlab代码
- garbor 滤波 matlab 代码
- Matlab中值滤波代码
- kalman滤波matlab代码demo
- 【滤波】卡尔曼matlab仿真代码
- 非局部均值滤波matlab代码理解
- 五点三次平滑法滤波 C 和 matlab代码
- 基于L0边缘保持滤波的图像融合 matlab代码
- 双边滤波(bilateral filter)灰度图 matlab实现代码
- 双边滤波(bilateral filter)彩色图 matlab实现代码
- 双边滤波(bilateral filter)快速算法 matlab实现代码
- 卡尔曼滤波简介说明及其算法MATLAB实现代码
- MATLAB里得粒子滤波代码存储库
- 高斯滤波 模板生成原理 matlab代码
- 3.高斯滤波、中值滤波MATLAB代码和结果图像
- MATLAB滤波实验
- VCam 虚拟摄像头 V3.1.0 下载 - 天空软件站 - 聊天工具 - 联络聊天
- 互联网应用发展新阶段的几个显著特点
- Unix时间和年月日时分秒时间格式转换
- MATLAB滤波实验
- Delphi易主Embarcadero
- MATLAB滤波代码
- Enum遍历方法
- 标准韩国语发音入门—元音和辅音
- 代码笔记 - Licence与Authorized Supervisor
- Start
- FireFox下GridView表格线显示、隐藏的问题
- IBM DeveloperWorks上的王强博士
- WinCvs入门必读
- 记一次球形闪电