I am having trouble splitting a BigTiff. I am orginally using @Ivan code from this question. I had to modify it a bit since I am using a .tif that was larger than 4GB. Pillow does not support BigTiffs. So I ended up using tifffile
. The code is running, though the image is not being clipped to the box
parameter. I am thinking it has to do that tifffile
reads the image in as a numpy array
and is not actually being clipped by anything???
I've also noticed that when this code is running my memory is just about maxing out. I tried assigning the data type to a unassigned 8-bit and that drastically helped. Should I compress it as well? I don't want to change the data too much since I will be classifying them and do not want to lose/change data.
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)