I have a simple problem, but I can not find a good solution.
I want to take a multidimensional 2D array that represents a grayscale image and convert it to an RGB PIL image using some matplotlib color maps.
I can get reasonable PNG output using the pyplot.figure.figimage :
dpi = 100.0 w, h = myarray.shape[1]/dpi, myarray.shape[0]/dpi fig = plt.figure(figsize=(w,h), dpi=dpi) fig.figimage(sub, cmap=cm.gist_earth) plt.savefig('out.png')
Although I could adapt this to get what I want (perhaps using StringIO to get a PIL image), I wonder if there is an easier way to do this, since this seems like a very natural problem of rendering an image. Let's say something like this:
colored_PIL_image = magic_function(array, cmap)
Thanks for reading!
python numpy matplotlib python-imaging-library color-mapping
heltonbiker Jun 09 2018-12-12T00: 00Z
source share