【发布时间】:2021-05-28 03:09:14
【问题描述】:
我无法拆分 BigTiff。我最初使用来自这个question 的@Ivan 代码。由于我使用的是大于 4GB 的 .tif,因此我不得不对其进行一些修改。枕头does not supportBigTiffs。所以我最终使用了tifffile。代码正在运行,尽管图像没有被剪切到box 参数。我认为它必须这样做 tifffile 将图像读取为 numpy array 并且实际上没有被任何东西剪辑???
我还注意到,当这段代码运行时,我的记忆力即将耗尽。我尝试将数据类型分配给未分配的 8 位,这非常有帮助。我也应该压缩它吗?我不想过多地更改数据,因为我将对它们进行分类并且不想丢失/更改数据。
import os
from itertools import product
import tifffile
def tile(filename, dir_in, dir_out, d):
name, ext = os.path.splitext(filename)
img = tifffile.imread(os.path.join(dir_in, filename))
print(type(img))
w = img.shape[0]
h = img.shape[1]
grid = list(product(range(0, h - h % d, d), range(0, w - w % d, d)))
for i, j in grid:
box = (j, i, j + d, i + d)
out = os.path.join(dir_out, f'{name}_{i}_{j}{ext}')
img = img.clip(box)
img = img.astype('uint8')
tifffile.imsave(out, img)
tile('Orthomosaic_export_MonFeb01193821460106.tif',
r'D:\ortho',
r'D:\model_images',
1000)
【问题讨论】: