【python图像处理】tiff文件的保存与解析
生活随笔
收集整理的這篇文章主要介紹了
【python图像处理】tiff文件的保存与解析
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
tiff文件是一種常用的圖像文件格式,支持將多幅圖像保存到一個文件中,極大得方便了圖像的保存和處理。python中支持tiff文件處理的是libtiff模塊中的TIFF類(libtiff下載鏈接https://pypi.python.org/pypi/libtiff/)。
這里主要介紹tiff文件的解析和保存,具體見如下代碼:
from libtiff import TIFF from scipy import misc##tiff文件解析成圖像序列 ##tiff_image_name: tiff文件名; ##out_folder:保存圖像序列的文件夾 ##out_type:保存圖像的類型,如.jpg、.png、.bmp等 def tiff_to_image_array(tiff_image_name, out_folder, out_type): tif = TIFF.open(tiff_image_name, mode = "r")idx = 0for im in list(tif.iter_images()):#im_name = out_folder + str(idx) + out_typemisc.imsave(im_name, im)print im_name, 'successfully saved!!!'idx = idx + 1return##圖像序列保存成tiff文件 ##image_dir:圖像序列所在文件夾 ##file_name:要保存的tiff文件名 ##image_type:圖像序列的類型 ##image_num:要保存的圖像數(shù)目 def image_array_to_tiff(image_dir, file_name, image_type, image_num):out_tiff = TIFF.open(file_name, mode = 'w')#這里假定圖像名按序號排列for i in range(0, image_num):image_name = image_dir + str(i) + image_typeimage_array = Image.open(image_name)#縮放成統(tǒng)一尺寸img = image_array.resize((480, 480), Image.ANTIALIAS)out_tiff.write_image(img, compression = None, write_rgb = True)out_tiff.close()return
2017.05.05
總結(jié)
以上是生活随笔為你收集整理的【python图像处理】tiff文件的保存与解析的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【python图像处理】txt文件数据的
- 下一篇: 【python图像处理】几何图形的绘制与