?? amedfilt2.m
字號(hào):
function J = amedfilt2(I)
% 2-D Adaptive Median Filter
% This filter ignores edge effects and boundary conditions, as such, the
% output is a cropped version of the original image, where the amount
% cropped is equal to the maximum window size vertically and horizontally.
% Define smax as a constant
smax = 9;
% Initialize Output Image (J)
J = I;
% Calculate valid region limits for filter
[nrows ncols] = size(I);
ll = ceil(smax/2);
ul = floor(smax/2);
% Loop over the entire image ignoring edge effects
for rows = ll:nrows-ul
for cols = ll:ncols-ul
for s = 3:2:smax
% grab block region
window_ind = -floor(s/2):floor(s/2);
region = I(rows+window_ind,cols+window_ind);
% calculate rmin, rmax, rmed
rmin = min(region(:));
rmax = max(region(:));
rmed = median(region(:));
% current sweet spot pixel value
centerpixel = region(ceil(s/2),ceil(s/2));
% adapt region size
if rmed > rmin && rmed < rmax
if centerpixel <= rmin || centerpixel >= rmax
J(rows,cols) = rmed;
end
% stop adapting
break;
end
end
end
end
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -