有人可以帮我理解这个关于中值滤波器的matlab代码吗?
function imOut = medianFilter(imIn,windowWidth)
if mod(windowWidth, 2 ) == 0
disp('Window has even size');
return
end
imageSize = size(imIn);
imOut = imIn;
windowBreadth = (windowWidth - 1)/2;
for m=windowBreadth+1:imageSize(1) - windowBreadth
for n=windowBreadth+1:imageSize(2) - windowBreadth
t1 = imIn(m-windowBreadth:m+windowBreadth,n-windowBreadth:n+windowBreadth);
t2 = reshape(t1,windowWidth*windowWidth,1);
t3 = median(t2);
imOut(m,n) = t3;
end
end
我的解释:
函数 MedianFilter 将图像(imIn)作为输入,以及中值滤波器窗口的宽度
,然后我不确定为什么我们需要 if 语句,
然后我们获取输入图像的大小并保存它在一个名为 imageSize 的变量中
,然后我们将 imIn 的所有值复制到 imOut
然后我就迷失了
什么是 windowbreadth?宽度和宽度不是同一个东西吗?
谢谢!
function imOut = medianFilter(imIn,windowWidth)
if mod(windowWidth, 2 ) == 0
disp('Window has even size');
return
end
imageSize = size(imIn);
imOut = imIn;
windowBreadth = (windowWidth - 1)/2;
for m=windowBreadth+1:imageSize(1) - windowBreadth
for n=windowBreadth+1:imageSize(2) - windowBreadth
t1 = imIn(m-windowBreadth:m+windowBreadth,n-windowBreadth:n+windowBreadth);
t2 = reshape(t1,windowWidth*windowWidth,1);
t3 = median(t2);
imOut(m,n) = t3;
end
end
my explanation:
the function medianFilter takes an image(imIn) as an input, and a width for the window of the median filter
then I'm not sure why we need the if statement
after that we take the size of the input image and save it in a variable called imageSize
then we copy all the values of imIn to imOut
then I'm all lost
what is windowbreadth? and isn't breadth and width the same thing?
thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
if
条件检查窗口大小是否为奇数;如果是偶数则没有“中心”像素。windowbreadth
似乎是一个坏名字。但从下图中应该可以清楚其含义:其中
S
是窗口大小,B
是窗口“宽度”,*
> 表示“中心”像素。所以
t1
是当前窗口中的所有样本。 t2 是那些重新排列为一维向量而不是二维数组的样本。The
if
conditional is checking that the window-size is odd; if it's even then there is no "central" pixel.windowbreadth
seems like a bad name. But its meaning should be clear from the diagram below:where
S
is the window-size,B
is the window-"breadth", and*
denotes the "central" pixel.So
t1
is all the samples in the current window.t2
is those samples rearranged as a 1D vector rather than a 2D array.