How to convert a NumPy array to PIL image applying matplotlib colormap

I have a simple problem, but I cannot find a good solution to it. I want to take a NumPy 2D array which represents a grayscale image, and convert it to an RGB PIL image while applying some of the matplotlib colormaps. I can get a reasonable PNG output by using the pyplot.figure.figimage command: dpi … Read more

How to convert a PIL Image into a numpy array?

Alright, I’m toying around with converting a PIL image object back and forth to a numpy array so I can do some faster pixel by pixel transformations than PIL’s PixelAccess object would allow. I’ve figured out how to place the pixel information in a useful 3D numpy array by way of: pic = Image.open(“foo.jpg”) pix … Read more

How to install PIL with pip on Mac OS?

I am trying to install PIL (the Python Imaging Library) using the command: sudo pip install pil but I get the following message: Downloading/unpacking PIL You are installing a potentially insecure and unverifiable file. Future versions of pip will default to disallowing insecure files. Downloading PIL-1.1.7.tar.gz (506kB): 506kB downloaded Running setup.py egg_info for package PIL … Read more

How do I resize an image using PIL and maintain its aspect ratio?

Is there an obvious way to do this that I’m missing? I’m just trying to make thumbnails. 23 s 23 Define a maximum size. Then, compute a resize ratio by taking min(maxwidth/width, maxheight/height). The proper size is oldsize*ratio. There is of course also a library method to do this: the method Image.thumbnail. Below is an … Read more