【发布时间】:2018-05-13 18:51:53
【问题描述】:
我一直试图弄清楚为什么 numpy.array() 方法将我的 tiff 图像转换为对象 (dtype=object)。我用其他 tiff 图像尝试过这个,我没有遇到这个问题。我很确定它与我的“actin2.tif”图像的获取方式有关。我只需要能够将这个特定的 tiff 图像转换为二维数组。这是我的代码的样子:
>>> import numpy
>>> from PIL import Image
>>> a = Image.open('actin2.tif')
>>> a_array = numpy.array(a)
>>> a
<PIL.TiffImagePlugin.TiffImageFile image mode=I;16B size=37x58 at 0x14BBC68>
>>> a_array
array(<PIL.TiffImagePlugin.TiffImageFile image mode=I;16B size=37x58 at 0x14BBC68>, dtype=object)
我最终需要能够操纵图像中像素的值,如果不将图像转换为二维数组,我就无法做到这一点。目前,这是我尝试操作数组时抛出的错误:
structure_masked = numpy.multiply(structure_mask,image)
TypeError: unsupported operand type(s) for *: 'bool' and 'instance'
这是这行代码的结果:
structure_masked = numpy.multiply(structure_mask,image)
“structure_mask”和“image”按照上面提到的相同方式转换为numpy数组。
我已尝试更改模式和 dtype,但这似乎不起作用,有什么建议吗?
【问题讨论】:
-
数组代表什么? RGB 需要三个数组。我认为色相/饱和度需要两个。
-
@xaav 在 numpy 中,这只是一个 4 维数组。
-
第四维是什么?
-
@xaav 抱歉,3 维,但重点是,它将是单个多维数组。
-
你能发布确切的图像吗?它适用于我身上的任意图像。
标签: python arrays image numpy tiff