⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mymedfilt2.m

📁 This file contains the material presented as the first Embedded MATLAB webinar on the MathWorks web
💻 M
字号:
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

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -