-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
gaussian filter produces pixels outside valid range #6459
Comments
I think this is caused by the upstream (SciPy 1.9.0, NumPy 1.23.2) function import scipy as sp
import skimage as ski
image = ski.img_as_float(ski.data.checkerboard())
sp.ndimage.gaussian_filter(image, sigma=2.).max() # returns 1.0000000000000002
sp.ndimage.gaussian_filter1d(image.ravel(), sigma=2).max() # returns 1.0000000000000002 I am not sure how to best approach this, too. For the current state of skimage expecting scaled input at a lot of places, it is indeed an annoying and surprising problem! I don't think this is really buggy behavior on SciPy's side; floating / precision errors are a fact of life sadly. Maybe one could start digging into SciPy's internals if there is anything that can be tweaked but I'm not sure how likely that will help. Clipping the output or raising a warning is a performance cost we likely don't want to pay in general for this function. Summoning the experience of @scikit-image/core for sage advice. 🧙 |
Oh, and I don't think this (from the docstring)
is the cause as this behavior also happens with the one-dimensional filter. |
Hey, there hasn't been any activity on this issue for more than 180 days. For now, we have marked it as "dormant" until there is some new activity. You are welcome to reach out to people by mentioning them here or on our forum if you need more feedback! If you think that this issue is no longer relevant, you may close it by yourself; otherwise, we may do it at some point (either way, it will be done manually). In any case, thank you for your contributions so far! |
Hi all, apologies for the silence here. Here are potential suggestions for course of action:
It's tempting to ignore the problem because we are going to do away with automatic scaling in the future, but, I don't think we can, because this is actually an issue with our manual scaling functions — ie even in the non-auto-scaling future, we still want users to be able to rescale their images and for that to be robust to floating point errors. In fact, on writing that last paragraph, I think that we might want to do both option 1 and option 3. CC @stefanv |
Description
filters.gaussian
produces pixel values outside of the valid range, -1 to 1.This unwanted behavior occurs for certain
sigma
andtruncate
input values when the input image type isuint8
orfloat64
. The behavior does not occur when the input image type isfloat32
.I bet that the cause involves floating-point errors, but I am uncertain of how to address it.
Way to reproduce
The following code block reproduces the behavior and demonstrates how it can lead to errors in subsequent functions.
The ValueError raised by
img_as_ubyte
reads.I tested$N$ failed input combinations. The code that follows the function definition, applies the function to three image types.
gaussian
with varying sigma values, truncate values, and image types. That testing script is pasted below.The defined function conducts the tests. It returns a list of
Version information
The text was updated successfully, but these errors were encountered: