%This routine performs median filtering on an image.
%
% Input: im - a grayscale image (values in [0,255])
% winSize - a 1x2 vector describing the size (height,width) of thefiltering window.
% Output: nim - a grayscale image (values in [0,255]) which is the median filtered im.
% Image nim is of the same size as im.
%
% Method: Performs Median Filtering on image im in windows of size winSize. Assume the
% window origin is at floor(size(B)/2)+1. Assume cyclic-padding.
所以这是我在图像处理中给出的练习的定义,这是我的解决方案:
function [ nim ] = medianFilt( im,winSize )
nim = im;
temp = cat(2,[im ;im(1:winSize(1)-1,:)],[ im(:,1:winSize(2)-1); im(1:winSize(1)-1,1:winSize(2)-1)])
for i = 1:size(im,1);
for j = 1:size(im,2);
winSizeMatrix = temp(i:i+winSize(1)-1,j:j+winSize(2)-1);
winSizeVector = reshape(winSizeMatrix,[],1);
medianOfVector = median(double(winSizeVector));
nim(i,j) = medianOfVector;
end
end
end
我得到了一个平滑图片的结果 - 我正在使用盐和胡椒过滤器,但最后一个像素看起来像是从第一个像素复制的,而不是固定过滤器。他们是我的输出应该的方式吗?还是我错过了什么?
也有人可以解释一下为什么我需要假设窗口原点在地板(大小(im/2)+1)?