如何用python讀取和寫入TIFF文件
- 2020 年 1 月 8 日
- 筆記
用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
