[Numpy-discussion] Finding Unique Pixel Values

Charles R Harris charlesr.harris@gmail....
Fri Jul 23 00:05:55 CDT 2010

On Thu, Jul 22, 2010 at 9:59 PM, Ian Mallett <geometrian@gmail.com> wrote:

> Hi again,
> I've condensed the problem down a lot, because I both presented it in an
> overcomplicated way, and did not explain it particularly well.
> Condensed problem:
> a = np.zeros(num_patches)
> b = np.array(...) #created, and is size 512^512 = 262,144
> #Each value in "b" is an index into "a".
> #For each occurrence of a given index in "b", increment the corresponding
> value in "a" by +1.
> #How should I do that?
> Simpler, and more importantly, better explained problem.  Help?
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,

pix_index = np.dot(pix_data, array([1, 2**8, 2**16], dtype=uint32)

then check out the documentation for np.unique.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20100722/e9f43cce/attachment-0001.html 

More information about the NumPy-Discussion mailing list