[Numpy-discussion] Finding Unique Pixel Values

Ian Mallett geometrian@gmail....
Fri Jul 23 00:54:05 CDT 2010


On Thu, Jul 22, 2010 at 10:05 PM, Charles R Harris <
charlesr.harris@gmail.com> wrote:

> Is that what you want, or do you just want to know how many unique indices
> there are? As to encoding the RGB, unless there is a existing program your
> best bet is probably to use a dot product, i.e., if pix_data is (n,3) uint8,
> then
>
> pix_index = np.dot(pix_data, array([1, 2**8, 2**16], dtype=uint32)
>
> then check out the documentation for np.unique.
>
I like the dot product idea for the indices.

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?

Thanks,
Ian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20100722/14247694/attachment.html 


More information about the NumPy-Discussion mailing list