Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What replaces scipy.misc.bytescale?

I am running old code using scipy 1.3.1 with the following import:

from scipy.misc import bytescale

with the following error:

ImportError: cannot import name 'bytescale'

I see that bytescale has been removed since 1.3 (source). The thread suggests that the scikit-image util module would be a good replacement, but does not offer one.

What is a good alternative to the now deprecated scipy.misc.bytescale()?

like image 297
Borealis Avatar asked Mar 03 '23 04:03

Borealis


2 Answers

I think there is no direct equivalent (be able to specify high and low) but you can use things like skimage.util.img_as_ubyte for scaling between 0 and 255, skimage.util.img_as_uint for scaling between 0 and 65535. Check them here: https://scikit-image.org/docs/stable/api/skimage.util.html (The img_as_* stuffs)

like image 53
2 revs Avatar answered Mar 11 '23 08:03

2 revs


skimage.util.img_as_ubyte is a replacement for scipy.misc.bytescale

the scipy.misc.bytescale doc states the following:

Byte scaling means converting the input image to uint8 dtype and scaling the range to (low, high) (default 0-255). If the input image already has dtype uint8, no scaling is done.

the skimage.util.img_as_ubyte doc states the following:

Convert an image to 8-bit unsigned integer format. Negative input values will be clipped. Positive values are scaled between 0 and 255.

like image 36
Borealis Avatar answered Mar 11 '23 08:03

Borealis