python - 如何连接使用内存映射 IO 填充的两个 TIFF 文件
问题描述
我正在尝试编写一个 python 函数,它将在组合多个 TIFF 文件后输出单个 TIFF 文件。我有一个包含大量 TIFF 文件的文件夹,我正在尝试将每个 TIFF 文件加入到一个文件中。我必须将数据加载为 numpy 数组,并且还应该使用内存映射 IO 进行填充。
解决方案
未经测试的例子,这应该给你一个想法:
from pathlib import Path
import numpy as np
import tifffile
my_path = Path(r'path/to/tiffs')
output = Path('output.tiff')
tiffs = list(my_path.glob('*.tiff'))
x,y = (512,512) # either hardcode or read from first tiff
output = np.zeros((len(tiffs), x, y))
for i, image in enumerate(tiffs):
a = tifffile.imread(image.open(mode = 'rb'))
output[i, :, : ] = a
tifffile.imsave(output.open(mode='wb'), output)
推荐阅读
- android - MITMProxy 7.0.4 + Android 模拟器 AVD 30
- python - PYTHON 的部分 ROC 曲线的 P 值
- android - 可绘制的单选按钮对 state_checked 没有反应
- python - 使用python将大型xlsx拆分为多个csv文件
- reactjs - 通用 TS 在这种情况下如何工作
- flutter - useTabController 索引永远不会改变
- mysql - mysql.service 的作业失败,因为控制进程以错误代码退出且未启动
- wpf - 旋转大元素以适合 WPF 中的较小容器
- c# - C#如何正确编码可重用类?
- python - Azure 机器学习笔记本上的错误:DataFrame 的真值不明确