# Mathmatical way to represent an image kernel?

How to represent the calculation in this image mathematically? For example: With the discrete convolution $(f * g)[n]\ \stackrel{\mathrm{}}{=}\ \sum_{m=-\infty}^\infty f[m]\, g[n - m]$ and Fourier transform.

• The calculation is two-dimensional calculation, the two -dimensional analog of the formula you wrote. – Yuval Filmus Apr 6 '13 at 19:50
• @YuvalFilmus: The problem I have is how to represent the functions f and g. Since you can't multiply it with 5 for both, the x and y direction... If you do so, you will multiply each pixel with 5*5=25 and not 5. – user1095332 Apr 6 '13 at 19:51
• Can you explain the calculation in English? I don't understand the picture, and besides a picture is not searchable — we strive to have questions that others faced with the same problem can find. – Gilles 'SO- stop being evil' Apr 6 '13 at 20:34
• It tries to do a calculation on the original image (image A) and save the result of the calculation in image B. 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 pixels you just multiplied toghether. 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 not surrounding pixel on the corners, it simply takes them from somewhere else. – user1095332 Apr 6 '13 at 20:41
• Posting a question without properly explaining what you want to know and then flagging all answers is not good style. – Raphael Apr 7 '13 at 12:36

Applying the filter corresponds to two-dimensional convolution: $$(f \ast g)(x,y) = \sum_{i=-\infty}^\infty \sum_{j=-\infty}^\infty f(i,j) g(x-i,y-j).$$ In our case, $f$ is the filter, $g$ is the image, and $f \ast g$ is the filtered image. Since the support of $f$ (the number of non-zero entries) is finite, the sums in question are finite, and the convolution is well-defined. More explicitly, 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.

Edit 1: Here is another way of viewing it. This time, $f$ is the image and $g$ is the filter, defined by $g(0,0) = 5$, $g(-1,0) = g(1,0) = g(0,-1) = g(0,1) = -1$, and $g(i,j) = 0$. The same formula for filtering, $f \ast g$, works before, since $f \ast g = g \ast f$. In other words, the filtered image $h$ is given by the formula $$h(x,y) = \sum_{i=-\infty}^\infty \sum_{j=-\infty}^\infty g(i,j) f(x-i,y-j).$$

Edit 2: We can rewrite the convolution as a product of generating functions. Suppose the original image is given by $$F = \sum_x \sum_y f(x,y) X^x Y^y.$$ The filter $G$ in your case is given by $$G = 5 - X - X^{-1} - Y - Y^{-1}.$$ Filtering the image corresponds to the multiplication $H = FG$, and the filtered image $h$ can be extracted as $$H = \sum_x \sum_y h(x,y) X^x Y^y.$$

Edit 3: Going back to the notation of Edit 1, in terms of the two-dimensional Fourier transform, we have $$\hat{h} = \hat{f} \hat{g},$$ where the multiplication on the right is pointwise. So filtering corresponds to multiplying each Fourier coefficient by some fixed amount, which depends on the filter.

Edit 4: In this particular case, the relation between the original image $f$ and the filtered image $h$ is $$h(x,y) = 5f(x,y) - f(x-1,y) - f(x+1,y) - f(x,y-1) - f(x,y+1).$$

Edit 5: The image you posted handles the boundary issue by extending the first and last rows and columns past the boundary. For example, $f(x,-1) = f(x,0)$, $f(-1,y) = f(0,y)$ and $f(-1,-1) = f(0,0)$.

• @user1095332 I made the formula up myself (so I have no sources), and in my formula, $f$ is the filter and $g$ is the image. You can check that $f \ast g = g \ast f$, so you get the same thing if you take $f$ as the image and $g$ as the filter. – Yuval Filmus Apr 7 '13 at 12:39
• I think our understanding of the concept of "mathematically correct" is different. For me, an example of a mathematically correct equation is $2+3=5$. Can you explain what "mathematically correct" means to you? – Yuval Filmus Apr 7 '13 at 12:40
• Please rewrite it, so f is the image and g the is filter, it is really confusing... – user1095332 Apr 7 '13 at 13:12
• Lets do a chat. – user1095332 Apr 7 '13 at 14:16
• @user1095332 I rewrote it, but an important skill to develop is the one of mentally reinterpreting formulas with different symbols. Different authors use different symbols to mean the same thing, and it's helpful if you can ignore these differences while concentrating on the meaning of what is said. – Yuval Filmus Apr 7 '13 at 15:24

it seems a classical image filtering technique, should be in textbooks, try fundamentals of digital image processing by Anil K Jain

the depicted filter seems like a discrete laplacian (altough the central number is 5 instead 4), have a look at http://en.wikipedia.org/wiki/Discrete_Laplace_operator

• Could you make this answer a little bit more self-contained? – frafl Apr 6 '13 at 21:40
• Those textbooks don't cover the process in this kind of detail... They don't tell you how to represent the calculation in a mathmatical form for this classical filter. And I'd like to see Fourier instead of Laplace. – user1095332 Apr 6 '13 at 21:52