[Image-SIG] How to create a new RGB image from an mxnx3 numpy array

David Goldsmith d_l_goldsmith at yahoo.com
Sat Oct 4 18:40:19 CEST 2008

Awesome, thanks Ned!  FTR (in case it helps others): Ned's "solution" was, formally, among the first things (if not the first thing) I tried, but...for my RGB table, I was using a colormap salvaged from some previous work in matlab using the scipy sub-package scipy.io.mio.  All that data was in floating point in the interval [0,1], which I knew, but by the time I guessed that I probably needed to convert it to [0,255], I think I must've made some other change somewhere else and/or neglected to simultaneously enforce that the m x n x 3 array be numpy.uint8 so that, between those other two problems, the solution to my problem was being "masked". :-(  Anyway, thanks again!


--- On Sat, 10/4/08, Ned Batchelder <ned at nedbatchelder.com> wrote:

> From: Ned Batchelder <ned at nedbatchelder.com>
> Subject: Re: [Image-SIG] How to create a new RGB image from an mxnx3 numpy array
> To: d_l_goldsmith at yahoo.com
> Cc: image-sig at python.org
> Date: Saturday, October 4, 2008, 7:59 AM
> I use code like this:
>     pixels = numpy.zeros((200, 300, 3), dtype=numpy.uint8)
>     //.. write data into the pixels array ..
>     im = Image.fromarray(pixels)
> --Ned.
> http://nedbatchelder.com
> David Goldsmith wrote:
> > Hi!  I've been over and over the handbook, tried
> everything I could think of, and still can't figure it
> out: how the heck does one get an m x n x 3 numpy array
> interpreted as an RGB image?  I tried fromarray, both with
> the whole array, and trying to merge the three images
> resulting from fromarray-ing the three m x n sub-arrays,
> creating the image first and then using putdata in various
> ways, etc., etc.  Please help.  Thanks.
> >
> > DG
> >
> > PS: Also, more discussion of the Palette concept in
> the handbook would be nice (e.g., what's its relation,
> if any, to the concept of colormaps, as used, e.g., in
> matlab and matplotlib).  Thanks again.
> >
> >
> >       
> > _______________________________________________
> > Image-SIG maillist  -  Image-SIG at python.org
> > http://mail.python.org/mailman/listinfo/image-sig
> >
> >
> >
> >   
> -- 
> Ned Batchelder, http://nedbatchelder.com


More information about the Image-SIG mailing list