Algorithm · Apple · Medium
You are given a grayscale image as a 2D integer matrix image and a 3 x 3 integer kernel kernel. Compute the filtered image by applying standard 2D convolution: the kernel is flipped in both axes, then centered on each input pixel. For output cell (r, c), the value is $$O[r][c] = \sum_{i=-1}^{1}\sum_{j=-1}^{1} I[r+i][c+j] \cdot K[1-i][1-j]$$ where I[x][y] is treated as 0 whenever x or y falls outside the image. Return a new matrix of the same dimensions as image. In your…
Checking your access…