[wxpython-users] Fast(er) pixel level access

Christopher Barker Chris.Barker at noaa.gov
Tue May 6 10:00:11 PDT 2008


Folkert Boonstra wrote:
> The lichenWithDeath
> rule is ugly currently (although still fast). Is there a way to do the
> convolve only once?

This is really one for the numpy list, but since you asked:

>     def lichenWithDeath(self):
>         kernel = NU.array([[1,1,1],[1,0,1],[1,1,1]]).astype(NU.uint8)
>         mask3  = (NI.convolve(self.bufbw, kernel) == 3).astype(NU.uint8)
>         mask4  = (NI.convolve(self.bufbw, kernel) == 4).astype(NU.uint8)
>         mask7  = (NI.convolve(self.bufbw, kernel) == 7).astype(NU.uint8)
>         mask8  = (NI.convolve(self.bufbw, kernel) == 8).astype(NU.uint8)

sure:
Conv = NI.convolve(self.bufbw, kernel)
mask3  = (Conv == 3).astype(NU.uint8)
mask4  = (Conv == 4).astype(NU.uint8)
mask7  = (Conv == 7).astype(NU.uint8)
mask8  = (Conv == 8).astype(NU.uint8)

it might be faster to do:

maskl = (Conv == 3).astype(NU.uint8)
maskl += (Conv == 7).astype(NU.uint8)
maskl += (Conv == 8).astype(NU.uint8)

allocating fewer temporary arrays can help.

>         self.buf = NU.array(self.DA, copy=1)

you can spell this:

self.buf = self.DA.copy()

I think it's a bit cleaner.

-Chris



-- 
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov


More information about the wxpython-users mailing list