《matlab程序语句.doc》由会员分享,可在线阅读,更多相关《matlab程序语句.doc(6页珍藏版)》请在金锄头文库上搜索。
1、%图像增强之直方图均衡化Im=imread(tire.tif);J=histeq(Im); %均衡化subplot(2,2,1);imshow(Im);title(原图);subplot(2,2,2);imhist(Im);title(原图直方图);subplot(2,2,3);imshow(J);title(均衡化结果);subplot(2,2,4);imhist(J);title(均衡化结果的直方图);%灰度调整Im=imread(rice.png);J=imadjust(Im,0.3 0.7,0 1);subplot(2,2,1);imshow(Im);title(原图);subplot
2、(2,2,2);imhist(Im);title(原图直方图);subplot(2,2,3);imshow(J);title(灰度调整结果);subplot(2,2,4);imhist(J);title(灰度调整后的直方图);%理想低通和高通clc;clear;data4=imread(lena.gif);subplot(3,2,1); imshow(data4);title(原图);i=fft2(data4);subplot(3,2,2); i=fftshift(i); z=log(abs(i); x=0:1:255;y=0:1:255;x,y=meshgrid(x,y);mesh(z);
3、%以三维坐标显示该图像频谱图title(原图频谱);n,m=size(i); %对该图进行低通滤波for k=1:1:n for l=1:1:m if (k2+l2)=1902 %选取D=190 result(k,l)=0; else result(k,l)=i(k,l); end endendsubplot(3,2,4);z=log(abs(result); %三维方式显示低通滤波后的频谱图x=0:1:255;y=0:1:255;x,y=meshgrid(x,y);mesh(z);title(理想低通滤波后的频谱);subplot(3,2,3); %新建图像显示窗口result=fftshi
4、ft(result); %滤波后的数据去中心化b=ifft2(result); %三维方式显示低通滤波前的频谱图imshow(uint8(abs(b);title(理想低通滤波后的图像);subplot(3,2,6); %新建图像显示窗口 % n,m=size(c); %对原图进行高通滤波 for k=1:1:n for l=1:1:m if (k2+l2)=1902 %选取D=190 result(k,l)=0; else result(k,l)=i(k,l); end endendz=log(abs(result);x=0:1:255; %三维方式显示高通滤波前的频谱图 y=0:1:255
5、;x,y=meshgrid(x,y);mesh(z);title(理想高通滤波后的频谱);subplot(3,2,5); result=fftshift(result); %滤波后的数据去中心化d=ifft2(result); %三维方式显示高通滤波后的频谱图imshow(uint8(abs(d);title(理想高通滤波后的图像);%频域增强(巴特沃斯原型)%利用巴特沃斯(Butterworth)低通滤波器对受噪声干扰的图像进行平滑处理clc;clear;J1=imread(lena.gif);subplot(3,2,1);imshow(J1);title(原图);f=double(J1);
6、 g=fft2(f); % 傅立叶变换g=fftshift(g); % 转换数据矩阵subplot(3,2,2);x=0:1:255;y=0:1:255;x,y=meshgrid(x,y);z=log(abs(g); %取幅度mesh(z); %以三维坐标显示该图像频谱图title(原图频谱);M,N=size(g);nn=2; % 二阶巴特沃斯(Butterworth)低通滤波器d0=20;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); % 计算低通滤波器传
7、递函数 result(i,j)=h*g(i,j); endendsubplot(3,2,4);x=0:1:255;y=0:1:255;x,y=meshgrid(x,y);z=log(abs(result); %取幅度mesh(z); %以三维坐标显示该图像频谱图title(低通滤波后的频谱);result=ifftshift(result);J2=ifft2(result);J3=uint8(abs(J2);subplot(3,2,3);imshow(J3);title(低通滤波后的图像);%利用巴特沃斯(Butterworth)高通滤波器对受噪声干扰的图像进行平滑处理nn=2; % 二阶巴特
8、沃斯(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); endendsubplot(3,2,6);x=0:1:255;y=0:1:255;x,y=meshgrid(x,y);z=log(abs(result); %取幅度mesh(z); %以三维坐标显示该图像频谱图title(高通滤波后的频谱);result=ifftshift(result);J2=ifft2(result);J3=uint8(abs(J2);subplot(3,2,5);imshow(J3);title(高通滤波后的图像);