# Filtering an image with a helmholtz-type equation

I'm attempting to apply the following PDE as an image filter to smooth a discrete heightmap with a helmholtz-type equation as described in this paper. It seemed like an interesting alternative to a gaussian filter.

The equation is: $$ddx(h') + ddy(h') + y(h'-h) = 0$$

I solved for h and got: $$\dfrac{ddx(h')}{y} + \dfrac{ddy(h')}{y} + h' = h$$

I then discretized it with a central finite difference and turned it into a linear system of the form $Ax=b$ where $b$ is the source image and A is a matrix with elements around the diagonal corresponding to the coefficients of a central finite difference approximation of the second derivative. I also added an additional $1$ to the diagonal to account for the standalone $h'$ on the left hand side.

Unfortunately, the results don't look anything like a smoothed version of the original image. For very high y, the resulting image is mostly similar to h, but for lower y it quickly degrades into noise and eventually just a black image.

I suspect part of the issue is the way I'm dealing with the boundary conditions. I recognize that the derivative is undefined at the border of the image, so I've tried a number of different approaches to address this from excluding the borders from the system, to special casing the kernel of border pixels by adding the missing border weights to the diagonal of A.

Here is some code I've been playing around with to solve this problem.

I would greatly appreciate help understanding how to handle the boundary conditions and learning how to properly apply this PDE as an image filter!

Thanks, Kris

• I might be wrong, but the diagonal term coefficients.push_back(T(index, index, dc)); with const Scalar dc = -2.0/gamma; seems strange. If i understood correctly, since there is a second derivative along x and a second derivative along y, the center term is expected to be const Scalar dc = -4.0/gamma;. – francis Apr 17 '15 at 16:47
• Or const Scalar dc = -4.0/gamma+1;. +1 is for the additional $h'$ – francis Apr 17 '15 at 16:56
• francis, thank you for taking a look at the code. I started with the term you included, and got similar results - I should have left the example code that was as you are correct that the second derivative should have dc = -4.0/gamma, but I was playing around and changed it to -2.0 to see if it helped at all. – Kris Apr 18 '15 at 16:47