matlab平滑窗滤波,matlab实现平滑滤波
clc;clear;close all;
im=imread(‘p1.jpg‘);
im = rgb2gray(im);
im=double(im);
im=im/max(im(??);
figure(‘Name‘,‘原圖‘,‘NumberTitle‘,‘off‘);imshow(im,[0,1]);
P1 = imnoise(im,‘gaussian‘,0,0.005); % adding gaussian noise 這里im是原始圖像,添加了均值是0,方差是0.005的高斯噪聲。
figure(‘Name‘,‘高斯噪聲‘,‘NumberTitle‘,‘off‘);imshow(P1,[0,1]);
P2 = imnoise(im,‘salt & pepper‘,0.02); % adding impulse noise 添加鹽和胡椒噪聲,默認噪聲密度為0.05。這會影響大約5%的像素。
figure(‘Name‘,‘椒鹽噪聲‘,‘NumberTitle‘,‘off‘);imshow(P2,[0,1]);
a=[1 1 1;1 1 1;1 1 1]; %定義一個3X3的全為1的模板
template1=(1/9)*a;
%對高斯噪聲進行濾波操作
imAve=conv2(double(P1),double(template1));% 返回矩陣 a 和 template1 的二維卷積。
figure(‘Name‘,‘高斯噪聲:均值濾波‘,‘NumberTitle‘,‘off‘);imshow(imAve,[0,1]);
imMed=medfilt2(P1,[3,3],‘symmetric‘); %執行中值濾波,其中每個輸出像素包含輸入圖像中相應像素周圍的m按n鄰域的中值。
figure(‘Name‘,‘高斯噪聲:中值濾波‘,‘NumberTitle‘,‘off‘);imshow(imMed,[0,1]);
psf=fspecial(‘gaussian‘,3,1); %返回大小為 hsize 的旋轉對稱高斯低通濾波器,標準差為 sigma。
imGau=imfilter(P1,psf,‘conv‘,‘symmetric‘); %根據一個或多個返回大小為 hsize 的旋轉對稱高斯低通濾波器,標準差為 sigma。
figure(‘Name‘,‘高斯噪聲:高斯濾波‘,‘NumberTitle‘,‘off‘);imshow(imGau,[0,1]);
%對椒鹽噪聲進行濾波操作
imAve=conv2(double(P2),double(template1));% 返回矩陣 a 和 template1 的二維卷積。
figure(‘Name‘,‘椒鹽噪聲:均值濾波‘,‘NumberTitle‘,‘off‘);imshow(imAve,[0,1]); title(‘average filter‘);
imMed=medfilt2(P2,[3,3],‘symmetric‘); %執行中值濾波,其中每個輸出像素包含輸入圖像中相應像素周圍的m按n鄰域的中值。
figure(‘Name‘,‘椒鹽噪聲:中值濾波‘,‘NumberTitle‘,‘off‘);imshow(imMed,[0,1]);
psf=fspecial(‘gaussian‘,3,1); %返回大小為 hsize 的旋轉對稱高斯低通濾波器,標準差為 sigma。
imGau=imfilter(P2,psf,‘conv‘,‘symmetric‘); %根據一個或多個返回大小為 hsize 的旋轉對稱高斯低通濾波器,標準差為 sigma。
figure(‘Name‘,‘椒鹽噪聲:高斯濾波‘,‘NumberTitle‘,‘off‘);imshow(imGau,[0,1]);
原文:https://www.cnblogs.com/lightice/p/14088144.html
總結
以上是生活随笔為你收集整理的matlab平滑窗滤波,matlab实现平滑滤波的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 信用卡申请提升额度该怎么做 信用卡申请提
- 下一篇: 连续反应matlab,MATLAB和Mo