%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)にあると仮定する必要がある理由を説明してもらえますか??