簡體   English   中英

numpy.array()不能將tiff圖像轉換為2D數組

[英]numpy.array() is not converting tiff image to 2D array

我一直試圖找出為什么numpy.array()方法將我的tiff圖像轉換為對象(dtype = object)。 我嘗試了其他tiff圖像,但沒有遇到此問題。 我很確定它必須與如何獲取“ actin2.tif”圖像有關。 我只需要能夠將此特殊的tiff圖像轉換為2D數組。 這是我的代碼如下所示:

>>> 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)

我最終需要能夠操縱圖像中像素的值,而如果不將圖像轉換為2D數組,則無法做到這一點。 當前,這是我嘗試操作數組時拋出的錯誤:

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數組。

我試過更改mode和dtype,但是似乎不起作用,有什么建議嗎?

遇到同樣的問題。 原來我們運行的是PIL而不是Pillow。 這為我們解決了它:

sudo pip卸載PIL

sudo pip安裝枕頭-U

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM