Python学习之读取TIFF文件

  • opencv读取
#导入cv模块
import cv2 as cv
import numpy as np
#读取图像,支持 bmp、jpg、png、tiff 等常用格式
#第二个参数是通道数和位深的参数,有四种选择,参考https://www.cnblogs.com/goushibao/p/6671079.html
img = cv.imread("filename.tif",2)
print img
#在这里一开始我写成了img.shape(),报错因为img是一个数组不是一个函数,只有函数才可以加()表示请求执行,
#参考http://blog.csdn.net/a19990412/article/details/78283742
print img.shape
print img.dtype 
print img.min()
print img.max()
#创建窗口并显示图像
cv.namedWindow("Image")
cv.imshow("Image",img)
cv.waitKey(0)
#释放窗口
cv.destroyAllWindows() 

但是出现了问题,我的TIFF是signed 16-bit的,用这种方法读出的值域范围0~65535,正常是-32768~32767.可能是opencv只支持unsigned 16-bit.

  • TIFFFILE包
from libtiff import TIFF
tif = TIFF.open('filename.tif', mode='r')
img = tif.read_image()
TIFFReadDirectory: Warning, Unknown field with tag 33550 (0x830e) encountered.
TIFFReadDirectory: Warning, Unknown field with tag 33922 (0x8482) encountered.
TIFFReadDirectory: Warning, Unknown field with tag 34735 (0x87af) encountered.
TIFFReadDirectory: Warning, Unknown field with tag 34737 (0x87b1) encountered.

出现上面的问题,但是貌似没什么影响,日后再探究





你可能感兴趣的:(学习历程,python,图像处理)