0

I'm trying to compress a bunch of tiff files with the pillow package. However, when I'm executing the code in python3.7.13 in Spyder IDE within the Anaconda3 environment, the Kernel restarts in the line in which the tiff file should be compressed. I tried different compression methods (e.g. "group4", "zlib", "deflate", etc..). I also tried other packages like libtiff and tifffile, but the same problem occurs here as well.

    import os
    import glob
    from PIL import Image, TiffTags
    from IPython.display import display
    
    import numpy as np
    images = [file for file in os.listdir("C:/Home/Slicer/tif") if file.endswith('tif')]
    #search for alle the images in the path
    for image in images:
        img_name = str(image)
        img = Image.open("C:/Home/Slicer/tif/"+img_name)
        print(img_name + str(img))
        display(img)
        #save tiff file with new name 
        img.save("C:/Home/Slicer/tif/" + "compressed" + img_name, compression="tiff_lzw")

Console output

Lars
  • 1
  • You need `libtiff` installed for reading/writing compressed TIFFs. Here's how to check https://stackoverflow.com/a/71113132/2836621 – Mark Setchell May 23 '22 at 10:46
  • Hello, I checked with the suggested code. According to the output libtiff seems to be installed: --- LIBTIFF support ok, loaded 4.2.0 -------------------------------------------------------------------- TIFF image/tiff Extensions: .tif, .tiff Features: open, save, save_all -------------------------------------------------------------------- – Lars Jun 09 '22 at 06:16

0 Answers0