Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Converting non-image .tiff data to pseudo-images (8-bit greyscale, high contrast).
from PIL import Image
import numpy as np
import os
for fname in os.listdir("."):
if fname.endswith(".tiff"):
im=Image.open(fname)
arr=np.array(im,dtype=np.uint16)
maxval = np.max(arr[arr>0])
minval = np.min(arr[arr>0])
arr=arr-minval
arrf = np.array(arr,dtype=np.float)
arrf = np.array(np.round(255.0*arrf/(maxval-minval)),dtype=np.uint8)
im8 = Image.fromarray(arrf)
im8 = im8.resize([500,500])
im8.save(fname.strip(".tiff")+".jpg")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.