如何用python读取和写入TIFF文件

2023-01-31 03:01:07 读取 写入 如何用

python读取TIFF文件,可采用以下代码

framedim = [2048,2048]

nb_elem = framedim[0]*framedim[1]

offset = 4096

fORMatdata = np.uint16

f = open(path, 'rb')

f.seek(offset)#TODO: only header size for tiff !!

d = np.fromfile(f, dtype=formatdata, count=nb_elem).reshape(framedim)

写入TIFF文件,则需要pylibtiff库,具体参见

Http://code.Google.com/p/pylibtiff/

例如

from libtiff import TIFF

tif = TIFF.open(path, 'w')

tif.write_image(image)

image为二维ndarray


相关文章