Example

Example of Calculating Two-Dimensional Cross-Correlation for Vertical Edge Detection

Consider a 6×66 \times 6 grayscale image, represented as a 6×6×16 \times 6 \times 1 matrix because there are no separate RGB channels. To detect vertical edges, we construct a 3×33 \times 3 filter (or kernel). Cross-correlating the 6×66 \times 6 input matrix with the 3×33 \times 3 filter produces a 4×44 \times 4 output matrix. To compute the upper-left element of this output, we overlay the 3×33 \times 3 filter onto the top-left 3×33 \times 3 region of the input image and sum the element-wise products. For instance, this calculation might be: 3(1)+1(1)+2(1)+0(0)+5(0)+7(0)+1(1)+8(1)+2(1)=53(1) + 1(1) + 2(1) + 0(0) + 5(0) + 7(0) + 1(-1) + 8(-1) + 2(-1) = -5. To compute the second element, we shift the filter one step to the right on the 6×66 \times 6 image, perform the same element-wise products and additions, yielding 4-4, and so on. To compute the next rows, we shift the filter one step down and repeat the procedure.

Image 0

0

1

Updated 2026-07-03

Tags

Data Science