您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 管理学资料 > matlab图像滤波(附经典图片)
I=imread('lena.bmp');inf=imfinfo('lena.bmp')figure,imshow(I)X=grayslice(I,64);imshow(X,pink(64))loadtreesfigure,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;clearall;I=imread('lena.tif');%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%用中值滤波,多维滤波,使用中心为-4,-8的拉普%%拉斯滤波器,高斯低通滤波,拉普拉斯滤波器进行滤波处理%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%figure;%figure1subplot(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=[111;1-41;111];w8=[111;1-81;111];f=im2double(I);g4=f-imfilter(f,w4,'replicate');g8=f-imfilter(f,w8,'replicate');imshow(f);figure;%figure2subplot(1,2,1);imshow(g4);title('中心为-4的拉普拉斯滤波');subplot(1,2,2);imshow(g8);title('中心为-8的拉普拉斯滤波');h3=fspecial('gaussian',[3,3],0.5);%高斯低通滤波figure;%figure3B4=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;%figure4subplot(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-255a2=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;%figure5subplot(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;%%设置滤波下限fori=1:Mforj=1:Nif(abs(g(i,j))y4)g(i,j)=g(i,j)^1.1;%对低频部分进行灰度增强endendendresult=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图像滤波(附经典图片)
链接地址:https://www.777doc.com/doc-6003788 .html