Matlab实现均值滤波

matlab可以对图像进行均值滤波,代码如下

clear all
close all
clc
I=double(rgb2gray(imread('an.jpg')))
[M,N]=size(I)
result=zeros(M,N)
NEW=zeros(M,N)
a=ones(3)*1/9
for i=2:M-1
    for j=2:N-1
        temp=I(i-1:i+1,j-1:j+1)
        result(i,j)=sum(sum(temp.*a))
    end
end
figure
imshow(I,[])
figure
imshow(result,[])

你可能感兴趣的:(matlab)