How to Calculate the Hann Low Pass Filter / Kernel for Image Processing I'm currently studying for an exam in image processing and stumbled upon a exercise which i could not answer and my professor will not be available before the exam anymore. The exercise goes as follows:


  Create a Hann-lowpass kernel of size $3\times 3$ and calculate the result of the convolution at $(2,2)$ in the image.


The given solution for the filter kernel is shown below, but I do not understand how he got there:

$$
A = \frac{1}{4}
\begin{pmatrix}
\frac{1}{4} &amp; \frac{1}{2} &amp; \frac{1}{4}  \\
\frac{1}{2} &amp; 1 &amp; \frac{1}{2}  \\
\frac{1}{4} &amp; \frac{1}{2} &amp; \frac{1}{4}  \\
\end{pmatrix}
$$ 

The second part of the question is a simple convolution with the image which I'm able to do. The factor in front of the kernel is given by the constraint $ \sum A = 1$ to achieve a filter gain of one. 
I've done literature research but none of the books in the library do explain how to calculate such a kernel. The professor gives a "hint" in his presentation pointing to the generalized cosine window with $A = 0.5$, $B = 0.5$ and $C = 0$:

$$
w_k = A - B\cdot \cos\left(2\pi\frac{k}{K-1}\right) + C\cdot \cos\left(4\pi\frac{k}{K-1}\right)
$$

Yet I cannot derive the final kernel from the given formulas. Can anyone give me a step by step solution for the problem?
So if I run

#30271

A &lt;- 0.5
B &lt;- 0.5
C &lt;- 0

K &lt;- 5

k &lt;- seq(0,K-1)

w_k &lt;- A - B * cos(2*pi*k/(K-1)) + C * cos(4*pi*k/(K-1))

print(w_k)


and it outputs 

[1] 0.0 0.5 1.0 0.5 0.0


Does that help?