[Numpy-discussion] Finding Unique Pixel Values

Ian Mallett geometrian at gmail.com
Fri Jul 23 04:01:13 EDT 2010


On Fri, Jul 23, 2010 at 12:13 AM, Jon Wright <wright at esrf.fr> wrote:

> Ian Mallett wrote:
> >
> > To the second, actually, I need to increment the number of times the
> > index is there.  For example, if b=[1,5,6,6,6,9], then a[6-1] would have
> > to be incremented by +3 = +1+1+1.  I tried simply a[b-1]+=1, but it
> > seems to only increment values once, even if there are more than one
> > occurrence of the index in "b".  What to do about that?
>
> Is this what you mean?
>
> >>> numpy.bincount( [1,5,6,6,6,9] )
> array([0, 1, 0, 0, 0, 1, 3, 0, 0, 1])
>
Well, I've implemented it thusly:

pixel_data =
np.cast['int16'](255.0*glReadPixels(0,0,patch_view.width,patch_view.height,GL_RGB,GL_FLOAT)).reshape((-1,3))
pixel_data = np.dot(pixel_data,np.array([65025,255,1]))
count = np.bincount(pixel_data)[1:]
self.visibility[poly1num][0:count.shape[0]] += count

And it works!  Thanks everyone!

Ian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20100723/5211c46d/attachment.html>


More information about the NumPy-Discussion mailing list