|
|
|
|
|
by dahart
4615 days ago
|
|
Love PIL/Pillow, for just about the easiest image I/O there is. I've been using it recently and needed a bit more industrial strength and speed than the library provides. PIL supports converting an image to/from a NUMPY array! (And the execution speed difference is definitely worth the effort...) Now my template for a new PIL script looks like this (all error checking removed for simplicity): from PIL import Image import numpy as np im = Image.open(args.input) rgb8 = np.array(im)[...,:3] rgb = rgb8.astype('float') / 256. # ... do stuff to 'rgb' using np rgb8 = np.clip(rgb * 256., 0, 255).astype('uint8') im = Image.fromarray(rgb8) im.save(args.output) |
|