MATLAB: Sum the matrix 3×3 and looping

convolutionImage Processing Toolboximfilter

how to calculate the total of overlap region 3×3 of a matrix and include loop function as it continue to calculate row by row and column by column.

Best Answer

  • That can be done very simply with imfilter() or conv2():
    outputArray = conv2(double(inputArray), ones(3), 'same');
    Every element (pixel) in the output array (image) will be the sum of input elements (pixels) in the sliding window.