2
$\begingroup$

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} & \frac{1}{2} & \frac{1}{4} \\ \frac{1}{2} & 1 & \frac{1}{2} \\ \frac{1}{4} & \frac{1}{2} & \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?

$\endgroup$

1 Answer 1

0
$\begingroup$

So if I run

#30271

A <- 0.5
B <- 0.5
C <- 0

K <- 5

k <- seq(0,K-1)

w_k <- 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?

$\endgroup$
4
  • $\begingroup$ Yes, definitively! Thanks a lot! I can see that you edited my question and replaced the minus with a plus. It seems to me that the professor had an error in his script. I've looked up the Hann window in books and on Matlabcentral and the definition also stated a K-1 instead of a K+1 ... Are there different definitions of the "generalized cosine" out there? $\endgroup$ Apr 22, 2016 at 11:41
  • $\begingroup$ @JanKrüger Oops! I didn't mean to change that. Question and answer updated. There are many different ways to define it the generalized cosine; sometimes $K-1$, sometimes $K+1$. $\endgroup$
    – Peter K.
    Apr 22, 2016 at 11:55
  • $\begingroup$ So it is that easy... By using the calculated vector and multiplying it with the transposed version of the vector we get the filter kernel mentioned above without the gain correction. It is almost too easy... Thanks a lot! $\endgroup$ Apr 22, 2016 at 12:03
  • $\begingroup$ @JanKrüger You're welcome. You were over-thinking it. :-) $\endgroup$
    – Peter K.
    Apr 22, 2016 at 12:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.