Reputation: 1340
I want to check the calculation of the laplace
filter from scipy.ndimage
and compare it to my own method if differentiation. Below I have a piece of code that I ran
import scipy.ndimage.filters
n = 100
x_range = y_range = np.linspace(-1, 1, n)
X, Y = np.meshgrid(x_range, y_range)
f_fun = X ** 2 + Y ** 2
f_fun_laplace = 4 * np.ones(f_fun.shape)
res_laplace = scipy.ndimage.filters.laplace(f_fun, mode='constant')
I expect that the variable res_laplace
will have the constant value of 4
over the whole domain (excluding the boundaries for simplicity), since this is what I would get by applying the laplace operator to my function f(x,y) = x^2 + y^2
.
However, the value that res_laplace
produces is 0.00163
in this case. So my question was.. why is this not equal to 4?
Upvotes: 0
Views: 84
Reputation: 1340
The answer, in this specific case, is that you need to multiply the output of scipy.ndimage.filters.laplace
with a factor of (1/delta_x) ** 2
. Where delta_x = np.diff(x_range)[0]
I simply assumed that the filter would take care of that, but in hindsight it is of course not able know the value delta_x
.
And since we are differentiating twice, we need to square the inverse of this delta_x
.
Upvotes: 1