How to represent the calculation in this image mathematically?
For example: With the discrete convolution and Fourier Transform.
It tries to do a calculation on the original image (image $A$/input) and save the result of the calculation in image $B$/output. It tries to multiply the pixel you are dealing with, with $5$ and it tries to multiply one pixel at the left, one pixel at the right, one pixel above of it and one pixel under it with $-1$ and adds the value of all the $5$ pixels you just multiplied together. After that, it will save the value of the new pixel in picture $B$. This happens to every single pixel in the image. Since there are no surrounding pixel on the corners, it simply takes them from somewhere else.
Which makes more sense?
Solution A:
$c(i,j) = \displaystyle\sum_{k_1 \in \Bbb N} \displaystyle\sum_{k_2 \in \Bbb N} a(k_1, k_2) b(i - k_1, j - k_2)$ where $a$ and $b$ are your matrices.
Supposing $a$ is your picture, by setting $b(0,0)=5$, $b(±1,0)=−1$, $b(0,±1)=−1$ and $b=0$ elsewhere.
Solution B:
$$
(f \ast g)(x,y) = \sum_{i=-\infty}^\infty \sum_{j=-\infty}^\infty f(i,j) g(x-i,y-j).
$$
$f$ is the filter, $g$ is the image, and $f \ast g$ is the filtered image. We have $f(0,0) = 5$, $f(-1,0) = f(1,0) = f(0,-1) = f(0,1) = -1$, and $f(i,j) = 0$ otherwise.
Note to answerer: Please try not to overcomplicate your answer...