From: John Hunter <jdh2358@gm...> - 2008-11-06 17:26:27
On Thu, Nov 6, 2008 at 9:00 AM, Nils Wagner
> Hi all,
> Is it possible to combine jpegs with matplotlib or PIL ?
> Any pointer would be appreciated.
if you have PIL installed, you can load them into mpl with imread, and
then set the alpha channel to make one partially transparent, and then
overlay them as in the layer images example
Below is some example code that loads a jog into RGB data, and then
embeds it in RGBA with an alpha mask of 0.5. Note however, that mpl
is not a general image processing library, so you will probably have
better luck with PIL. I'm no PIL expert, so can't help there...
In : from matplotlib.image import imread
In : im = imread('lena.jpg')
In : im.shape
Out: (512, 512, 3)
In : import numpy as np
In : rgba = np.zeros((512,512,4))
In : im.dtype
In : im = im.astype(float)/255.
In : rgba[:,:,:3] = im
In : rgba[:,:,-1] = 0.5