Unexpected behavior of Gaussian filtering with Scipy

Viewed 756

Given that I have an image f(x,y) loaded, for example,

enter image description here

I want to compute the Gaussian derivative ∂/∂x ∂/∂y G*f of the image f, where G is a Gaussian filter and * denotes convolution. This is easily done using Scipy:

from scipy.ndimage.filters import gaussian_filter
imshow(gaussian_filter(g, sigma, order=1))

With sigma=50 this produces the following result:

enter image description here

Now, for applicationary reasons, I need to do the computation with mode='constant':

imshow(gaussian_filter(g, sigma, order=1, mode='constant', cval=0))

Still, the result looks reasonable:

enter image description here

However, note that my image's background's intensity is 1 and not 0. Hence, it should be reasonable to use cval=1:

imshow(gaussian_filter(g, sigma, order=1, mode='constant', cval=1))

enter image description here

Now this is unexpected! This result makes no sense, does it?

For the record, I also checked the partial differentials ∂/∂x G*f and ∂/∂y G*f. Whereas

imshow(gaussian_filter(g, sigma, order=[0, 1], mode='constant', cval=1)

looks reasonable

enter image description here

the other one

imshow(gaussian_filter(g, sigma, order=[1, 0], mode='constant', cval=1)

does not:

enter image description here

Why is that?

1 Answers
Related