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

skimage.transform.rescale fails for scale < 0.2 #5252

Closed
pyscorcher opened this issue Feb 27, 2021 · 4 comments · Fixed by #5256
Closed

skimage.transform.rescale fails for scale < 0.2 #5252

pyscorcher opened this issue Feb 27, 2021 · 4 comments · Fixed by #5256
Labels
📄 type: Documentation Updates, fixes and additions to documentation

Comments

@pyscorcher
Copy link

Description

The function skimage.transform.rescale throws an error for for scale < 0.2, which is quite unexpected if you're just trying to use the rescale function. I get following error messages for these small scale factors:

SOME_PATH\skimage\transform\_warps.py:115: RuntimeWarning: divide by zero encountered in true_divide
  factors = (np.asarray(input_shape, dtype=float) /
Traceback (most recent call last):
  File "PATH_TO\my_script.py", line 5, in <module>
    img = transform.rescale(img, scale=0.1)  # error
  File "SOME_PATH\skimage\transform\_warps.py", line 290, in rescale
    return resize(image, output_shape, order=order, mode=mode, cval=cval,
  File "SOME_PATH\skimage\transform\_warps.py", line 147, in resize
    image = ndi.gaussian_filter(image, anti_aliasing_sigma,
  File "SOME_PATH\scipy\ndimage\filters.py", line 341, in gaussian_filter
    gaussian_filter1d(input, sigma, axis, order, output,
  File "SOME_PATH\scipy\ndimage\filters.py", line 257, in gaussian_filter1d
    lw = int(truncate * sd + 0.5)
OverflowError: cannot convert float infinity to integer
Process finished with exit code 1

Way to reproduce

from skimage import transform
import numpy as np
img = np.zeros((30, 40, 3))
img = transform.rescale(img, scale=0.2)  # ok
img = transform.rescale(img, scale=0.1)  # error

Version information

# Paste the output of the following python commands
from __future__ import print_function
import sys; print(sys.version)
import platform; print(platform.platform())
import skimage; print("scikit-image version: {}".format(skimage.__version__))
import numpy; print("numpy version: {}".format(numpy.__version__))
3.7.3 (default, Mar 27 2019, 17:13:21) [MSC v.1915 64 bit (AMD64)]
Windows-10-10.0.19041-SP0
scikit-image version: 0.14.2
numpy version: 1.16.2
@rfezzani
Copy link
Member

rfezzani commented Mar 1, 2021

Thank you @pyscorcher for the report, I can reproduce the bug.

In the example that you provided, the input image shape is (30, 40, 3) and when you apply a scale factor of 0.1, the output image shape is obtained as round(0.1 * [30, 40, 3]) = round([3, 4, 0.3]), which is [3, 4, 0]. This last 0 is the root of the problem.

I assume that this behavior is expected, but the raised error is extremely confusing 😕.

@hmaarrfk
Copy link
Member

hmaarrfk commented Mar 1, 2021

Thanks for getting to the bottom of that @rfezzani

@pyscorcher to help you with your work, there is a multichannel parameter that also exists in version 0.14.2
https://scikit-image.org/docs/0.14.x/api/skimage.transform.html#rescale

I think that should help you. Let us know!

@pyscorcher
Copy link
Author

@rfezzani Thanks for explaining and for the PR!
@hmaarrfk That is very good to know, thank you very much!

@ntjess
Copy link

ntjess commented Jun 21, 2021

Is this issue fixed in 0.18.1?

I face something similar when (x,y) resized dimensions are 0:

from skimage import transform as trans
import numpy as np

x = np.zeros((1,1), bool)
y = trans.resize(x, (0,0))

This raises the unhelpful error message numpy.linalg.LinAlgError: SVD did not converge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📄 type: Documentation Updates, fixes and additions to documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants