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

Delbert Franz ddf@iqdotdt....
Thu Feb 26 23:27:57 CST 2009

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:)

   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

#1  The way it would be done in a compiled language, like Fortran where it
would run in a small fraction of 
a second instead of several minutes:)  But what I want to ultimately
accomplish is hard to do in Fortran!

 for i in range(9252):
    for j in range(7420):
        for k in range(3):
            doqq[i,j,k] = ctab[doq[i,j],k]

#2  Try to use some special numpy features:

for i in doq.flat:
    doqq.flat = ctab[i,0:3]

#3 Variation of #1

for i in range(9252):
   for j in range(7420):
      doqq[i,j,] = ctab[doq[i,j],]

All of these use too many element accesses, which are slow.  My searching
and reading the
documentation has not given me an approach that avoids these low-level and
(in python/numpy) accesses.  I suspect there is a clever way to do this but
as a newbie
I'm having some rough going on getting this process to be much faster. 


       Delbert Franz


View this message in context: http://www.nabble.com/Speedup-creation-of-a-3-color-array-from-a-2-d-color-index-array-a-color-lut-tp22236421p22236421.html
Sent from the Numpy-discussion mailing list archive at Nabble.com.

More information about the Numpy-discussion mailing list