我需要使用Python 2从磁盘读取 single-channel 32-bit integer TIFF image 来执行一些图像分析 . 我尝试了matplotlib的image.imread,但我无法使代码工作,因为数据被读取为4通道8位整数图像:
>>> import numpy as np
>>> import matplotlib.image as mpimg
>>> img = mpimg.imread('my_image.tif')
>>> img.shape
(52, 80, 4)
>>> img[0:2, 0:2]
array([[[255, 255, 255, 255],
[255, 255, 255, 255]],
[[255, 255, 255, 255],
[255, 255, 255, 255]]], dtype=uint8)
QUESTION :是否可以使用matplotlib读取单通道32位整数图像?
我知道有其他方法可以在Python中读取这样的图像,例如使用PIL中的Image.open:
>>> from PIL import Image
>>> img = np.asarray(Image.open('my_image.tif'))
>>> img.dtype
dtype('int32')
>>> img.shape
(52, 80)
>>> img[0:2, 0:2]