inf=imfinfo('lena.bmp')
figure,imshow(I)
X=grayslice(I,64)
imshow(X,pink(64))
load trees
figure,image(10,10,X)
imwrite(X,map,'trees.bmp')
imfinfo('trees.bmp')
figure,imshow(X,map)
BW=im2bw(X,map,0.6)
figure,imshow(BW)
I=imread('lena.bmp')
inf=imfinfo('lena.bmp')
figure,imshow(I)
X=grayslice(I,64)
figure,imshow(X,pink(64))
A=imread('lena.bmp')
imshow(A)
B=fftshift(fft2(A))
figure
imshow(log(abs(B)),[8,10])
clc
clear all
I=imread('lena.tif')
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %用中值滤波,多维滤波,使用中心为-4,-8的拉普
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure%figure1
subplot(2,2,1)
imshow(I)
title('原始图像')
J=imnoise(I,'salt &pepper',0.04)%加椒盐噪声
title('加椒盐噪声')
subplot(2,2,2)
imshow(J)
K=medfilt2(J,[4,4])%进行中值滤波
subplot(2,2,3)
imshow(K)
title('进行中值滤波')
h=ones(3,3)/9%多维滤波
w=h
g=imfilter(I,w,'conv','replicate')
subplot(2,2,4)
imshow(g)
title('多维滤波')
%使用中心为-4,-8的拉普拉斯滤波器,
w4=[1 1 1
1 -4 1
1 1 1]
w8=[1 1 1
1 -8 1
1 1 1]
f=im2double(I)
g4=f-imfilter(f,w4,'replicate')
g8=f-imfilter(f,w8,'replicate')
imshow(f)
figure%figure2
subplot(1,2,1)
imshow(g4)
title('中心为-4的拉普拉斯滤波')
subplot(1,2,2)
imshow(g8)
title('中心为-8的拉普拉斯滤波')
h3=fspecial('gaussian',[3,3],0.5)%高斯低通滤波
figure%figure3
B4=filter2(h3,I)
subplot(1,2,1)
imshow(B4,[ ])
title('高斯低通滤波')
h4=fspecial('laplacian',0)%使用拉普拉斯滤波器
B5=filter2(h4,I)
subplot(1,2,2)
imshow(B5,[ ])
title('拉普拉斯滤波器')
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %从空域的角度进行亮度变换
% %把灰度等级是10-100的变化到10-255
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure%figure4
subplot(2,2,1)
imshow(I)
title('原始图像')
J2=imadjust(I,[],[],0.5)% 增强低灰度级
subplot(2,2,2)
imshow(J2)
title('增强低灰度级')
J3=imadjust(I,[ ],[ ],2)%增强高灰度级
subplot(2,2,3)
imshow(J3)
title('增强高灰度级')
a1=100/255%把灰度等级是10-100的变化到10-255
a2=255/255
a3=10/255
J2=imadjust(I,[a3,a1],[a3,a2],[])
subplot(2,2,4)
imshow(J2)
title('把灰度等级是10-100的变化到10-255')
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %从频域的角度进行亮度变换
% %fft2
% %由于能量主要集中在低频部分
% %所以对低频进行处理可以得到理想的效果
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
I=imread('lena.tif')
up=0.5%设置处理频率上限
down=0.09%%设置处理频率下限
figure%figure5
subplot(421)
imshow(I)
title('原始图像')
f=double(I)
subplot(4,2,3)
imshow(log(abs(f)),[])
title('unit8转化为double')
g=fft2(f)
g=fftshift(g)
subplot(4,2,5)
imshow(log(abs(g)),[])
title('FFT2变化后的图像')
[M,N]=size(g)% 转换数据矩阵
y1=max(max(abs(g)))%求出最大频率
y2=min(min(abs(g)))%%求出最小频率
y3=(y1-y2)*up+y2%设置滤波上限
y4=(y1-y2)*down+y2%%设置滤波下限
for i=1:M
for j=1:N
if (abs(g(i,j))<y4)
g(i,j)=g(i,j)^1.1%对低频部分进行灰度增强
end
end
end
result=ifftshift(g)
J2=ifft2(result)
J3=uint8(abs(J2))
subplot(427)
imshow(J3,[ ])
title('频域处理后的图像')
subplot(422)
imhist(I,64)
subplot(424)
imhist(f,64)
subplot(426)
imhist(g,64)
subplot(428)
imhist(J3,64)
这是西安电子科技大学《matlab及其在理工课程中的应用》第174页的程序:clf,format compact,t=0:.001:1
A0=10w0=100phi0=0
x=A0*sin(w0*t-phi0)subplot(3,1,1), plot(t,x), hold
xlabel('t'), ylabel('载频信号')
dA=input('振幅增量=')dw=input('频偏=')dphi=input('相移=')
y=(10+dA).*sin((w0+dw).*t+dphi)
subplot(3, 1,2),
plot(t,y),ylabel('调制波形')
subplot(3,1,3)
Y=fft(y)plot(abs(Y)), grid
axis([0, 50, 0, 5000])
1.原先的w0=100,要修改;
2.程序运行后,在命令提示处输入5sin(200t);
3.如果不明白,下载那本书吧。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)