建设银行交罚款网站,品牌建设总结报告,站长之家seo,wordpress活动背景使用python操作一批同样分辨率的图片#xff0c;合并为tiff格式的文件。由于opencv主要用于读取单帧的tiff文件#xff0c;对多帧的文件支持并不好。通过搜索发现了两个比较有用的包#xff1a;TiffCapture和tifffile。两者都可用pip安装。其中前者主要用于读取tiff文件…背景使用python操作一批同样分辨率的图片合并为tiff格式的文件。由于opencv主要用于读取单帧的tiff文件对多帧的文件支持并不好。通过搜索发现了两个比较有用的包TiffCapture和tifffile。两者都可用pip安装。其中前者主要用于读取tiff文件后者可读可写。最终选择tifffile来合成tiff图片文件。安装tifffilepip install tifffile原理及代码我的图片是8 bit灰度图。每次读取之后先升维new_gray gray_img[np.newaxis, ::]然后再使用np.append添加到数组里。每append一次相当于tiff增加一帧图片。tiff_list np.append(tiff_list, new_gray, axis0)所有操作完毕则一次性保存到磁盘。tifffile.imsave( out_tiff_path, tiff_list )下面是我的完整代码import cv2import tifffileimport timeimport numpy as npimport timeimport osimg_path ../word_allout_txt_path ../out_word_all.boxout_tiff_path ../out_word_all.tiftiff_list Nonewith open(out_txt_path, wb) as f:dir_list os.listdir(img_path)cnt_num 0for dir_name in dir_list:dir_path os.path.join(img_path, dir_name)img_list os.listdir(dir_path)pwd os.getcwd()os.chdir(dir_path)for img in img_list:print(dir_path:{}.format(dir_path))gray_img cv2.imread(img, cv2.IMREAD_GRAYSCALE)new_gray gray_img[np.newaxis, ::]print(gray_img shape:{}, new_gray shape:{}.format(gray_img.shape, new_gray.shape))#global cnt_numif cnt_num 0:print(cnt_num 0)tiff_list new_grayelse:print(np.append)tiff_list np.append(tiff_list, new_gray, axis0)print(tiff_list shape:{}.format(tiff_list.shape))content {} 2 2 60 60 {}.format(dir_name, cnt_num)print(content)f.write(content.encode(UTF-8))cnt_num 1os.chdir(pwd)tifffile.imsave( out_tiff_path, tiff_list )print(tiff_list shape:{}.format(tiff_list.shape))以上这篇pythontifffile之tiff文件读写方式就是小编分享给大家的全部内容了希望能给大家一个参考也希望大家多多支持云海天教程。