如果我想让一个数组填充0
或1
取决于图像中的像素值,我写这个:
image = "example.jpg"
imageOpen = Image.open(image)
bwImage = imageOpen.convert("1", dither=Image.NONE)
bw_np = numpy.asarray(bwImage)
print(type(bw_np[0, 0]))
结果 :
<class 'numpy.bool_'>
由于.convert
双层模式"1"
,数组必须充满1
and 0
。https://pillow.readthedocs.io/en/3.1.x/reference/Image.html#PIL.Image.Image.convert
当我尝试更简单的事情时:
bw_np = numpy.asarray([0, 1])
print(type(bw_np[0]))
结果 :
<class 'numpy.int32'>
但不是第二个例子,第一个例子充满了true
and false
。所以为什么 ?