Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

filters.laplace result has the wrong sign #7357

Open
Matthias-Schroeter opened this issue Mar 23, 2024 · 0 comments · May be fixed by #7366
Open

filters.laplace result has the wrong sign #7357

Matthias-Schroeter opened this issue Mar 23, 2024 · 0 comments · May be fixed by #7366
Labels

Comments

@Matthias-Schroeter
Copy link

Matthias-Schroeter commented Mar 23, 2024

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
pitkajuh pushed a commit to pitkajuh/scikit-image that referenced this issue Apr 3, 2024
@pitkajuh pitkajuh linked a pull request Apr 3, 2024 that will close this issue
pitkajuh pushed a commit to pitkajuh/scikit-image that referenced this issue Apr 13, 2024
pitkajuh pushed a commit to pitkajuh/scikit-image that referenced this issue Apr 13, 2024
pitkajuh pushed a commit to pitkajuh/scikit-image that referenced this issue Apr 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant