二维 高斯低通滤波器matlab程序设计.pdfVIP

  • 0
  • 0
  • 约2.22千字
  • 约 3页
  • 2021-10-21 发布于江苏
  • 举报
二维高斯滤波器图像滤波MTATLAB程序设计 用MATLAB 设计一个3×3 模板标准差为0.5,1.5,2.5 的二维高斯低通滤波器(Gaussion low pass filter 分别对灰度图像,真彩色图像,伪彩色图像进行滤波处理 %二维高斯低通滤波器 %文件为glpf.m functionglpf(J) %处理索引图像 ifisind(J) [I,map]=imread(J); I=imnoise(I,gaussian,0.005); subplot(2,2,1) imshow(I,map); title(a.原始图像); K1=filter2(fspecial(gaussian,3*3,0.5),I); K2=filter2(fspecial(gaussian,3*3,1.5),I); K3=filter2(fspecial(gaussian,3*3,2.5),I); subplot(2,2,2) imshow(K1,map); title(b.滤波器3*3,sigma=0.5) subplot(2,2,3) imshow(K2,map); title(c.滤波器3*3,sigma=1.5) subplot(2,2,4) imshow(K3,map); title(d.滤波器3*3,sigma=2.5) end %处理灰度,真彩色图像 if ~isind(J) J=imread(J);%读入图像 I=imnoise(J,gaussian);%加入高斯噪声 %输出原始图像 subplot(2,2,1) imshow(I); title(a.原始图像) h1 = fspecial(gaussian,[3,3], 0.5);%用预定义的gaussian 函数 [m n p]=size(I); %[m n p] m,n 代表像素点的位置,p 代表空间分量 %p=1,代表亮度分量,即灰度图像 %p=3,代表亮度分量(Y),色差分量(Cr,Cb) if p==1%处理灰度图像 I=double(I); I=conv2(I,h1,same);%I 与h 的二维离散卷积 end if p==3%处理真彩色 I=double(I); I(:,:,1)=conv2(I(:,:,1),h1,same); I(:,:,2)=conv2(I(:,:,2),h1,same); I(:,:,3)=conv2(I(:,:,3),h1,same); end I=uint8(I);%8位无符号整型 %经过3*3,sigma=0.5 二维高斯低通滤波器滤波后的图像 subplot(2,2,2) imshow(I); title(b.滤波器3*3,sigma=0.5) h2 = fspecial(gaussian,[3,3],1.5); [m n p]=size(I); if p==1 I=double(I); I=conv2(I,h2,same);%二维离散卷积 end if p==3 I=double(I); I(:,:,1)=conv2(I(:,:,1),h2,same); I(:,:,2)=conv2(I(:,:,2),h2,same); I(:,:,3)=conv2(I(:,:,3),h2,same); end I=uint8(I); %经过3*3,sigma=1.5 二维高斯低通滤波器滤波后的图像 subplot(2,2,3) imshow(I); title(c.滤波器3*3,sigma=1.5) h3 = fspecial(gaussian,[3,3], 2.5); [m n p]=size(I); if p==1 I=double(I); I=conv2(I,h3,same); end if p==3 I=double(I); I(:,:,1)=conv2(I(:,:,1),h3,same); I(:,:,2)=conv2(I(:,:,2),h3,same); I(:,:,3)=conv2(I(:,:,3),h3,same); end I=uint8(I); %经过3*3,sigma=2.5 二维高斯低通滤波器滤波后的图像 subplot(2,2,4) imshow(I); title(d.滤波器3*3,sigma=2.5) end 程序调用

文档评论(0)

1亿VIP精品文档

相关文档