【发布时间】:2018-11-22 03:22:35
【问题描述】:
如果我想根据图像中的像素值填充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和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和false。
那为什么呢?
【问题讨论】:
标签: python numpy types numpy-dtype