?? mymedfilt2.m
字號(hào):
function J = mymedfilt2(I)
% MYMEDFILT2 2-D median filtering.
% J = MYMEDFILT2(I) performs median filtering of the matrix
% I in two dimensions. Each output pixel contains the median
% value in 9-by-9 neighborhood around the corresponding
% pixel in the input image. MYMEDFILT2 ignores the edges, so
% the values for the pixels within 4 of the edges will appear
% identical to the input image.
%
% Class Support
% -------------
% The input image I can be any class supported by the median
% function (single, double). The output image J is of the
% same class as I.
%
% Example
% -------
% I = imread('eight.tif');
% J = imnoise(I,'salt & pepper',0.02);
% K = mymedfilt2(J);
% figure, imshow(J), figure, imshow(K)
[nrows ncols] = size(I);
window_size = 9;
ll = ceil(window_size/2);
ul = floor(window_size/2);
window_ind = -ul:ul;
% Initialize Output Image (J)
J = I;
% Loop over the center part of the image to ignore edge effects
for rows = ll:nrows-ul
for cols = ll:ncols-ul
% grab block region
region = I(rows+window_ind,cols+window_ind);
% calculate median
rmed = median(region(:));
% update output image
J(rows,cols) = rmed;
end
end
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -