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

issues with floating point inputs to blob_log, blob_dog, blob_doh #5224

Open
grlee77 opened this issue Feb 5, 2021 · 1 comment
Open

issues with floating point inputs to blob_log, blob_dog, blob_doh #5224

grlee77 opened this issue Feb 5, 2021 · 1 comment
Labels

Comments

@grlee77
Copy link
Contributor

grlee77 commented Feb 5, 2021

Description

The blob detection functions all use img_as_float internally to convert integer inputs to normalized floats.

However, if the input is already a float, but has not been normalized, computation can take a very long time.

There is also a separate issue for blob_doh only in that float32 or float16 inputs will result in an error when calling a Cython function that expects double precision.

Way to reproduce

To reproduce, try the docstring example for blob_doh, but casting the input to float. It will get stuck running for a very long time:

from skimage import data, feature
img = data.coins().astype(float)  # non-normalized float
# will get stuck running for a long time
feature.blob_doh(img)

# ValueError: Buffer dtype mismatch, expected 'double_t' but got 'float'
feature.blob_doh(img.astype(np.float32))

Version information

scikit-image version: 0.19.0.dev0

Possible Solution

blob_doh should probably just use img_as_float64 internally so that accuracy is good for the integral_image computation and the input to the Cython function will always be float64.

I assume the slow operation is due to something like a poor default setting for thresholds in the case of non-normalized data. Should we add a check for the input range something like the following, or what is the best way to handle this?

    if image.dtype.kind == 'f':
        if image.max() > 1.0 or image.min() < 0:
            raise ValueError(
                "input image with floating point type must have values normalized to "
                "[0.0, 1.0]")
@odoublewen
Copy link
Contributor

I ran up against this a couple weeks ago. I have unit tests that create "corner case" images, weird artifactural things that should never really happen, but I test them to indentify images that my analysis pipeline can't handle.

Anyway, this simple case will cause blob_log to hang (indefinitely?):

import numpy as np
import skimage
image = np.zeros([100, 100])
image[40:80, 40:80] = 10.0
skimage.feature.blob_log(image, threshold=None, threshold_rel=None)

This is skimage '0.19.0'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants