pip install pillow
python from PIL import Image
img = Image.open("input.tif") img_array = np.array(img)
https://pillow.readthedocs.io/en/stable/reference/Image.html
https://stackoverflow.com/questions/56174099/how-to-load-images-larger-than-max-image-pixels-with-pil
## PIL.Image.DecompressionBombError: Image size (400000000 pixels) exceeds limit of 178956970 pixels, could be decompression bomb DOS attack. Image.MAX_IMAGE_PIXELS = None
## Traceback (most recent call last): ## File "<stdin>", line 1, in <module> ## File "PIL/Image.py", line 3280, in open ## raise UnidentifiedImageError(msg) ## PIL.UnidentifiedImageError: cannot identify image file 'input.tif'
img = Image.open("input.tif")
img.mode ## LA, PA, or RGBA
img_alpha = img.getchannel("A") img_alpha_array = np.array(img_alpha)
## Binarization (as needed) img_alpha_array = np.where(img_alpha_array == 0, 1, 0).astype(np.uint8) #img_alpha_array = np.where(img_alpha_array == 0, 255, 0).astype(np.uint8)
img_out = Image.fromarray(img_alpha_array, mode="L") img_out.save("output.tif")