Chris,
I am trying to extract the blueest pixels from a wx.Image.
Offline you gave me some pseudocode that very nearly compiles.
If you"d rather I take this question to the numpy list, I
understand, but I am learning FloatCanvas simultaniously :-)
And numpy is a bit over my head -- as I am studying the
380 page doc.
here is the code (in a literate style):
<code>
import wx
import numpy as N
path = "8bitchart01_small.tiff"
image = wx.Image(path, wx.BITMAP_TYPE_ANY)
w, h = image.GetWidth(), image.GetHeight()
# Rappin page 362, Smart page 285
d = N.fromstring(image.GetData(), N.uint8)
# > now you can re-shape the numpy array to fit your data: -CB
d.reshape(w, h, 3)
# > which will clean up your later code: # CB
# > for x in range(x1, x2): # paul
# > for y in range(y1, y2):
# > i = (y * w + x) * 3 # stride Smart page 285
# > red, grn, blu = d[i], d[i+1], d[i+2]
# > this could then be: [IT COMPILES TO HERE]
#red, grn, blu = d[x,y] # returns NameError: name 'x' is not defined
red, grn, blu = d[:,:] # so paul tries an xy slice,
# gets IndexError: too many indices
# > but, you can get rid of the loops:
# > if (rmin <= red <= rmax) and \
# > (gmin <= grn <= gmax) and \
# > (bmin <= blu <= bmax):
# > this could all be done in one fell swoop:
rmin, rmax, gmin, gmax, bmin, bmax = 0,178,0,178,100,255
line_pix = ((rmin <= d[:,:,0] <= rmax) &
(gmin <= d[:,:,1] <= gmax) &
(bmin <= d[:,:,2] <= bmax))
# d(line_pix) = 0 # black
# returns: SyntaxError: can't assign to function call
# d(~line_pix) = 255 # white -CB
# > or maybe:
d = N.where(d, line_pix, 0, 255)
</code>
_______________________________________________
FloatCanvas mailing list
[email protected]
http://mail.mithis.com/cgi-bin/mailman/listinfo/floatcanvas