Laplacian Filter Implementation in MATLAB I implemented a Laplacian filter for the Lena image, but I get an unexpected output.

For input:



I get output:



I used the mask 

M =

     0    -1     0
    -1     5    -1
     0    -1     0



I is my Lenna Image rows and columns are I.rows and I.columns.

And this is my MATLAB function:

function IM = customMaskImage(I, rows, columns, M)
IM = zeros(rows,columns);
[mask_rows, mask_columns] = size(M);

for i = 1+(mask_rows-1)/2:(rows - (mask_rows-1)/2)
    for j = 1+(mask_columns-1)/2:(columns - (mask_columns-1)/2)
        tmpMat = I(i-(mask_rows-1)/2:i+(mask_rows-1)/2,j-(mask_columns-1)/2:j+(mask_columns-1)/2);
        IM(i,j) = sum(sum(customMatConv(tmpMat, 3, 3, M)));
    end
end

end


customMatConv.m is:

function IM = customMatConv(I, rows, columns, M)
IM = zeros(rows,columns);

for i = 1:rows
    for j = 1:columns
        IM(i,j) = I(i,j) * M(i,j);
    end
end

end


What am I doing wrong?
You should use conv2() or imfilter() with your filter.
Unless you want to implement it by hand,