[wxpython-users] Fast(er) pixel level access
Folkert Boonstra
F.Boonstra at inter.nl.net
Tue May 6 03:54:17 PDT 2008
Folkert Boonstra schreef:
> Christopher Barker schreef:
>
>> Folkert Boonstra wrote:
>>
>>> Just an update on how far i got with getting it faster.
>>> Replacing loops with list comprehensions is a major enhancement:
>>>
>> I'm a bit surprised -- I thought list comprehensions gave you almost
>> the same byte code. I learn something new every day.
>>
>> Anyway, you can easily get a 10X or so speed up for this kind of
>> thing with numpy -- it really is the tool for the job, it's well worth
>> learning
Chris,
Thanks for your suggestion(s)!. It is now fast enough for 512x512 size
images.
Now I have to look at the drawing of bitmaps again.
The rules are now implemented solely with numpy. The lichenWithDeath
rule is ugly currently (although still fast). Is there a way to do the
convolve only once?
def parity(self):
kernel = NU.array([[0,1,0],[1,1,1],[0,1,0]]).astype(NU.uint8)
mask = (NI.convolve(self.bufbw, kernel) == 1).astype(NU.uint8)
self.bufbw = mask
self.buf = NU.array(self.DA, copy=1)
NU.putmask(self.buf, mask, self.LA)
def life(self):
kernel = NU.array([[1,1,1],[1,0,1],[1,1,1]]).astype(NU.uint8)
mask = (NI.convolve(self.bufbw, kernel) == 1).astype(NU.uint8)
self.bufbw = mask
self.buf = NU.array(self.DA, copy=1)
NU.putmask(self.buf, mask, self.LA)
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)
maskl = mask3 + mask7 + mask8
maskd = mask4
self.bufbw = maskl
self.buf = NU.array(self.DA, copy=1)
NU.putmask(self.buf, maskl, self.LA)
NU.putmask(self.buf, maskd, self.DA)
Folkert
More information about the wxpython-users
mailing list