[Numpy-discussion] Counting the Colors of RGB-Image

Torgil Svensson torgil.svensson@gmail....
Sat Jan 21 07:49:24 CST 2012


unique has an option to get indexes out which you can use in
combination with sort to get the actual counts out.

tab0 = zeros( 256*256*256 , dtype=int)
col=ravel(((im0[...,0].astype('u4')*256+im0[...,1])*256)+im0[...,2])
col,idx=unique(sort(col),True)
idx=hstack([idx,[2500*2500]])
tab0[col]=idx[1:]-idx[:-1]
tab0.shape=(256,256,256)

As Chris pointed out, if each pixel were 4 bytes you could probably
just use im0.view('>u4') for histogram values.

//Torgil



On Wed, Jan 18, 2012 at 10:26 AM,  <apo@pdauf.de> wrote:
>
> Sorry,
>
> that i use this way to send an answer to Tony Yu , Nadav Horesh , Chris Barker.
> When iam direct answering on Your e-mail i get an error 5.
> I think i did a mistake.
>
> Your ideas are very helpfull and the code is very fast.
>
> Thank You
>
> elodw
>
>
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>


More information about the NumPy-Discussion mailing list