comp_laplacian.m

来自「this is a very very very nice code」· M 代码 · 共 49 行

M
49
字号
%Function computes the laplacian of an image, but only on pixels defined by
%the input parameter mask. Wind is the sub-window over which to compute (to
%save time by not checking regions the user knows contain no true parts of
%the mask), and type defines the type of laplacian to perform
function out = comp_laplacian_test(in, pix_set, type)

out = zeros(size(in));
if type == 1
    %Compute the standard laplacian
    for k = 1:size(pix_set,1)
        y = pix_set(k,1);
        x = pix_set(k,2);
        out(y,x) = -4*in(y,x) + in(y+1,x) + in(y-1,x) + in(y,x+1) + in(y,x-1);
    end

elseif type == 2
    %Compute the 1D (in the y-direction) laplacian
    for k = 1:size(pix_set,1)
        y = pix_set(k,1);
        x = pix_set(k,2);
        out(y,x) = in(y+1,x) + in(y-1,x) -2*in(y,x);
    end
        
elseif type == 3
    %Compute the 1D (in the x-direction) laplacian
    for k = 1:size(pix_set,1)
        y = pix_set(k,1);
        x = pix_set(k,2);
        out(y,x) = in(y,x+1) + in(y,x-1) -2*in(y,x);
    end

elseif type == 4
    %Compute the "cross-laplacian" used in the anisotropic diffusion
    for k = 1:size(pix_set,1)
        y = pix_set(k,1);
        x = pix_set(k,2);
        out(y,x) = ( -in(y+1,x+1) - in(y-1,x-1) + in(y+1,x-1) + in(y-1,x+1) ) / 4;
    end
    
elseif type == 5
    %Compute the "cross-laplacian" used in the anisotropic diffusion
    for k = 1:size(pix_set,1)
        y = pix_set(k,1);
        x = pix_set(k,2);
        out(y,x) = sum(sum(in(y-1:y+1, x-1:x+1))) - 9*in(y,x);
    end
    
end

⌨️ 快捷键说明

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