【问题标题】:Pillow black & white image scaling does not working枕头黑白图像缩放不起作用
【发布时间】:2020-06-30 21:06:29
【问题描述】:

假设我正在创建具有 4 个白色像素的黑白 32*32 图像

from PIL import Image
import numpy as np

img = np.zeros([32, 32])
img[4:6, 1:3] = 1
Image.fromarray(img, 'L').resize([1024, 1024], Image.LANCZOS).show()

使用所有图像重采样方法,我得到了全黑的图像。不明白这里有什么问题。 我也试过img[4:, 1:] = 1,结果相同。

【问题讨论】:

    标签: python image python-imaging-library


    【解决方案1】:

    我怀疑你想要这个:

    from PIL import Image 
    import numpy as np 
    
    img = np.zeros((32, 32),np.uint8) 
    img[4:6, 1:3] = 255 
    Image.fromarray(img, 'L').resize((1024, 1024), Image.LANCZOS).save('result.png')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-02-20
      • 2017-06-04
      • 1970-01-01
      • 1970-01-01
      • 2020-03-28
      • 2013-05-18
      • 1970-01-01
      相关资源
      最近更新 更多