我正在尝试将 numpy 数组转换为 PIL.Image。但它给出的是黑色图像。 numpy 数组由 skimage 的 pyramid_gaussian 方法返回

I am trying to convert a numpy array to PIL.Image. But it is giving black images. The numpy array is returned by pyramid_gaussian method from skimage

这是我的代码

   import numpy as np
   from PIL import Image
   from skimage.transform import pyramid_gaussian
   image =  Image.open('/home/sumith/Downloads/AFW/testimages/3854178896.jpg')
   rows, cols, dim = np.asarray(image).shape
   pyramid = tuple(pyramid_gaussian(image, downscale=2,))

   count = 0
   for pyr in pyramid[0:8]:
   row, col, dim = (np.asarray(pyr).shape)
   count += 1
   #io.imsave('/home/sumith/imagepyramids/'+count.__str__()+".jpg", pyr)
   print(type(pyr))
   image = Image.fromarray(pyr.astype('uint8'), 'RGB')
   image.save('/home/sumith/imagepyramids/'+count.__str__()+".jpg")

当我打印类型 (pyr) 时,它显示为但是当我尝试从 PIL 图像转换和保存它时,金字塔中的所有图像都将是黑色的。但是如果我使用 io.imsave 保存它,它工作正常。我需要将图像金字塔的图像输入神经网络,所以如果我可以将它作为 PIL.Image 提供,那么它将非常有帮助。 提前致谢!!黑色图像看起来像这样 black-image

检查 pyr 中的值。也许它们的值介于 0 和 ` 之间,而您的 RGB 图像的值应该介于 0 和 255 之间。