Skimage调整大小功能返回黑色图像

时间:2019-01-30 12:08:08

标签: resize scikit-image

我正在尝试调整使用matplotlib的imread函数加载的某些图像的大小。 例子:

plt.figure()
plt.imshow(imgs[0])
plt.colorbar()
plt.grid(False)
plt.show()

enter image description here

但是,当我尝试应用调整大小功能然后重新绘制时:

def rescale_image(img):
    """Rescale the jpg range of 0-255 to 0-1"""
    img = resize(img, (100, 100), anti_aliasing=True)
    return img /255
#imgs = [rescale_image(i) for i in imgs]

io = rescale_image(imgs[0])
plt.figure()
plt.imshow(io)
plt.colorbar()
plt.grid(False)
plt.show()

结果是: enter image description here

为什么?

更新:导入语句:

%matplotlib inline
import matplotlib.pyplot as plt
from matplotlib.image import imread
from skimage.transform import resize


imgs = [imread(p) for p in paths_list]# paths list is generated by glob.glob on the folder of images

1 个答案:

答案 0 :(得分:1)

您的图像开始时的像素范围为0.1.1。调整大小时,除以255,因此范围现在为0..0.003,因此看起来是黑色的。

解决方案?

更改此行:

return img /255

对此:

return img