[Numpy-discussion] Speedup creation of a 3-color array from a 2-d color-index array a color lut

Robert Kern robert.kern at gmail.com
Fri Feb 27 15:44:57 EST 2009


On Fri, Feb 27, 2009 at 14:41, Delbert Franz <ddf at iqdotdt.com> wrote:
>
>> Message: 2
>> Date: Thu, 26 Feb 2009 23:32:35 -0600
>> From: Robert Kern <robert.kern at gmail.com>
>> Subject: Re: [Numpy-discussion] Speedup creation of a 3-color array
>>       from a  2-d color-index array a color lut
>> To: Discussion of Numerical Python <numpy-discussion at scipy.org>
>> Message-ID:
>>       <3d375d730902262132k5a011d14t84317458f9b6cf87 at mail.gmail.com>
>> Content-Type: text/plain; charset=UTF-8
>>
>> On Thu, Feb 26, 2009 at 23:27, Delbert Franz <ddf at iqdotdt.com> wrote:
>> >
>> > I have ?geotiff files of scanned paper maps that use an indexed color scheme
>> > with a 256-element
>> > color lookup table (color lut) and a 9252 by 7420 array ?of uint8 elements.
>> > The color is given by
>> > three values. ?I want to create an array with shape: (9252, 7420, 3) so that
>> > I can display the
>> > image without creating internal array working space in Matplotlib that
>> > exeeds 2^31 bytes.
>> >
>> > The following three approaches work in that the correct image is displayed,
>> > but all of them
>> > are waaaaay too slow:)
>> >
>> > ?Let
>> > ? doq have shape (9252, 7420) and have uint8 elements
>> > ? ctab have shape (256, 3) and have uint8 elements.
>> > ? doqq have shape (9252, 7420, 3) and have unit8 elements
>>
>> doqq = ctab[doq]
>>
> Thanks, Robert!  It works just fine but it "blows my mind":)  Never would of
> thought of trying that.  I'll have to work hard at getting my "mind around" how
> Numpy "views the universe".

The full range of indexing is discussed here:

  http://docs.scipy.org/doc/numpy/reference/arrays.indexing.html

> I'm just starting to come to terms with what
> "object oriented" means in Python.  In 46 years of developing software, one
> is always on a learning curve, sometimes relatively flat, but sometimes
> nearly vertical--this was a moment on the vertical:)

Good. That means you're learning quickly.  :-)

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
  -- Umberto Eco



More information about the NumPy-Discussion mailing list