Created
February 9, 2018 12:01
-
-
Save CnrLwlss/5ad5f460f98e6dee555b64d69d07c27f to your computer and use it in GitHub Desktop.
Converting non-image .tiff data to pseudo-images (8-bit greyscale, high contrast).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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