center_weighted_median_filter.m

来自「用MATLABT算法实现, 图象经过center weighted median」· M 代码 · 共 47 行

M
47
字号
the image. The matlab code has been presenting:
function g = median_filter1(f,m)
[height, width]= size(f); 
g = zeros(height, width); 
for y = 1:height
    for x = 1:width
        x1 = x - 2; 
        x2 = x + 2; 
        y1 = y - 2;
        y2 = y + 2;
        if x1 < 1
            x1 = 1;
        end
        
        if x2 > width
            x2 = width;
        end
 
        if y1 < 1
            y1 = 1;
        end
        
        if y2 > height
            y2 = height;
        end
        window = f(y1:y2, x1:x2); 
        window = window(:);  
        window1=[window;repmat(f(y,x),m,1)];
        g(y, x) = median(window); 
    end
end
g = uint8(g); imshow(g); 
 
clear all
m1=1;
m2=4;
m3=24;
a=imread('lena-salt-pepper-noise.bmp');
g1=median_filter(a);
g2=median_filter1(a,m1);
g3=median_filter1(a,m2);
g4=median_filter1(a,m3);
subplot(2,2,1);imshow(g1);title('median');
subplot(2,2,2);imshow(g2);title('CWM with 1');
subplot(2,2,3);imshow(g3);title('CWM with 4');
subplot(2,2,4);imshow(g4);title('CWM with 24');

⌨️ 快捷键说明

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