I am a beginner when it comes to Python and coding. I am trying to compress a 30GB TIFF stack into a smaller TIFF stack and has loseless compression. I came across a few people using the code line ZIP_DEFLATE
in to do this. But, I haven't been successful in implementing such codes for compressing my TIFF files. Would you mind helping me with compiling a small code for this? Or any advice that will help with building such a code. My input raw TIFF files are single TIFF stacks that is around 30GB.
Thank you
EDIT.
Currently I stitched up a code from various sources (code below). When I run this it reads by input TIFF stack and creates an output file that is around 50% smaller. Is there anyway to compress it even more?
import os, random
import zipfile
from zipfile import ZIP_DEFLATED
from tifffile import imread, imsave
import time
import skimage
from skimage import io
from skimage.util import img_as_ubyte
from skimage import img_as_uint
Data_folder = "/Test_Input" #@param {type:"string"}
Result_folder = "/Test_output" #@param {type:"string"}
for image in os.listdir(Data_folder):
timelapse = imread(Data_folder+"/"+image)
short_name = os.path.splitext(image)
n_timepoint = timelapse.shape[0]
Output_stack= timelapse
for t in range(n_timepoint):
print("Frame number: "+str(t))
img_t = timelapse[t]
Output_stack_16= img_as_uint(Output_stack, force_copy=False)
os.chdir(Result_folder)
imsave(str(short_name[0])+".tif", Output_stack_16, compress=ZIP_DEFLATED)