[Numpy-discussion] Matlab/Numpy index order

Chris Colbert sccolbert at gmail.com
Tue May 12 16:32:40 EDT 2009


This is interesting.

I have always done RGB imaging with numpy using arrays of shape (height,
width, 3). In fact, this is the form that PIL gives when calling
np.asarray() on a PIL image.

It does seem more efficient to be able to do a[0],a[1],a[2] to get the R, G,
and B channels respectively. This, obviously is not currently the case.

Would it be better for me to switch to this way of doing things  and/or work
a patch for PIL so that the array is built in the form (3, height, width)?

Chris



On Tue, May 12, 2009 at 4:14 PM, David Warde-Farley <dwf at cs.toronto.edu>wrote:

>
> On 12-May-09, at 3:55 PM, Ryan May wrote:
> >
> > It's going to be faster to do it without the transpose.  Besides,
> > for numpy,
> > that imshow becomes:
> >
> >    imshow(b[0])
> >
> > Which, IMHO, looks better than Matlab.
>
> You're right, that is better, odd how I never thought of doing it like
> that. I've been stuck in my Matlab-esque world with dstack() as my
> default mental model of how images/matrices ought to be stacked.
>
> Am I right in thinking that b[0] is stored in a big contiguous block
> of memory, thus making the read marginally faster than slicing on the
> third?
>
> David
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20090512/d62d3ca9/attachment.html>


More information about the NumPy-Discussion mailing list