该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
(1)均值滤波
function imres = averageFilter(im,N) % imres为均值滤波后的矩阵,参数im为图像的路径,N为滤波模板
if 3==size(im,3) %判断im是否为三维图像,若是,则转换为灰度图像。
im = rgb2gray(im);
end
im = double(im);
h = ones(N,N)/N^2;
imres = imfilter(im, h, 'conv','replicate');
其中h = ones(N,N)/N^2; 是什么意思。
(2)中值滤波
function imres = medianFilter(im,N)
if 3==size(im,3)
im = rgb2gray(im);
end
im= double(im);
imres = im;
[row col] = size(im); %获取图像的行和列
wd = floor(N/2);%floor 向下取整(去掉小数点部分)
for x = wd+1:1:row-wd
for y = wd+1:1:col-wd
subim = im(x-wd:x+wd,y-wd:y+wd);
imres(x,y) = median(subim(:));
end
end
循环这部分我看不懂?
function imres = gaussianFilter(im,sigma) %sigma为标准差
if 3==size(im,3)
im = rgb2gray(im);
end
im = double(im);
GaussianDieOff=0.0001; %
pw = 1:30; %设定滤波器宽度
ssq = sigma^2;%计算方差
width = find(exp(-(pw.*pw)/(2*ssq))>GaussianDieOff,1,'last');
t = (-width:width);
gau = exp(-(t.*t)/(2*ssq))/(2*pi*ssq); % the gaussian 1D filter
gau = gau/sum(gau);
%smooth the image out
aSmooth=imfilter(im,gau,'conv','replicate');
imres=imfilter(aSmooth,gau','conv','replicate');
这个高斯滤波就更看不懂了