自己小编的均值滤波器程序 源代码
clc
clear
%彩色图像灰度化
a=imread('C:\Users\wk\Desktop\2\IMG_20130423_143258.bmp');
g=rgb2gray(a);
figure(1)
imshow(g)
g=uint16(g);
title('灰度图像');
[m,n]=size(g);
f=zeros(m,n);
f(1,1)=(g(1,1)+g(1,2)+g(2,1)+g(2,2));
f(m,1)=1/4*(g(m-1,1)+g(m-1,2)+g(m,1)+g(m,2));
f(1,n)=1/4*(g(1,n-1)+g(1,n)+g(2,n-1)+g(2,n));
f(m,n)=1/4*(g(m-1,n-1)+g(m-1,n)+g(m,n-1)+g(m,n));
for i=2:m-1
f(i,1)=1/6*(g(i-1,1)+g(i,1)+g(i+1,1)+g(i-1,2)+g(i,2)+g(i+1,2));
f(i,n)=1/6*(g(i-1,n)+g(i,n)+g(i+1,n)+g(i-1,n-1)+g(i,2)+g(i+1,n-1));
end
for j=2:n-1
f(1,j)=1/6*(g(1,j-1)+g(1,j)+g(1,j+1)+g(2,j-1)+g(2,j)+g(2,j+1));
f(m,j)=1/6*(g(m-1,j-1)+g(m-1,j)+g(m-1,j+1)+g(m,j-1)+g(m,j)+g(m,j+1));
end
for i=2:m-1
for j=2:n-1
f(i,j)=1/9*(g(i-1,j-1)+g(i,j-1)+g(i+1,j-1)+g(i-1,j)+g(i,j)+g(i+1,j)+g(i-1,j+1)+g(i,j+1)+g(i+1,j+1));
end
end
f=uint8(f);
figure(2)
imshow(f);
title('junzhi灰度图像')
2020-01-12 03:12:04
881B
均值滤波
1