将图像转换为ndarray,反之亦然

时间:2019-07-24 15:07:07

标签: python-3.x numpy python-imaging-library

我有此图像和以下python代码。 black and white

import numpy as np
from PIL import Image
image = Image.open("File.png")
image = image.convert("1")
image.show()
bw = np.asarray(image).copy()
im01 = np.where(bw, 0, 1)
new_img = Image.fromarray(im01)
new_img.show()   

new image

由于图像是黑白的,因此我可以将im01视为2D ndarray,在184x184矩阵中为0和1为黑白像素。

Image.fromarray()为什么不起作用? 有什么我想念的吗?

0 个答案:

没有答案