Skip to content

filters.laplace result has the wrong sign #7357

@Matthias-Schroeter

Description

@Matthias-Schroeter

Description:

The purpose of a Laplace filter is to compute an approximation for the second derivative. Which means that at the position of a maximum, it should give us back a negative number. That is e.g. the behavior of the scipy implementation of a Laplace filter. The filter matrix in skimage is inverted.
Fixing this bug will break the workarounds some people might have used in the past (i.e. multiplying the skimage result with minus 1).

Way to reproduce:

import numpy as np
import skimage as ski

from scipy import signal
maximum = np.outer(signal.windows.gaussian(5, 1)*10, signal.windows.gaussian(5,1))*10
np.set_printoptions(precision = 1)
print ('a 2D Gaussian maximum:\n',maximum)

laplace_result= ski.filters.laplace(maximum)
print('\nLaplace filter result:\n',laplace_result)


### the underlying reason is that the signs in the filter matrix are inverted
### as can be seen by a comparison with the scipy implementation
from scipy import ndimage

A = np.zeros((3,3))
A[1,1] = 1

laplace_filter_scipy = ndimage.laplace(A)
laplace_filter_skimage= ski.filters.laplace(A)

print('scipy:\n',laplace_filter_scipy)
print('\nskimage:\n',laplace_filter_skimage)

Version information:

3.11.5 (main, Sep 11 2023, 13:54:46) [GCC 11.2.0]
Linux-6.7.9-1-default-x86_64-with-glibc2.39
scikit-image version: 0.22.0
numpy version: 1.26.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    Status

    To Do

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions