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

2012-01-23 Thread Chris Barker
On Wed, Jan 18, 2012 at 1:26 AM,  a...@pdauf.de wrote:
 Your ideas are very helpfull and the code is very fast.

I'm curios -- a number of ideas were floated here -- what did you end up using?

-Chris


--

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/ORR            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

chris.bar...@noaa.gov
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


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

2012-01-23 Thread elodw
  Am 23.01.2012 18:17, schrieb Chris Barker:
 On Wed, Jan 18, 2012 at 1:26 AM,a...@pdauf.de  wrote:
 Your ideas are very helpfull and the code is very fast.
 I'm curios -- a number of ideas were floated here -- what did you end up 
 using?

 -Chris


I'am sorry but  when i see the code of Torgil Svenson,
I think, the game is over.

I use the follow. code:

t0=clock()

tt = n_im2.view()
tt.shape = -1,3
ifl = tt[...,0].astype(np.int)*256*256 + tt[...,1].astype(np.int)*256 + 
tt[...,2].astype(np.int)
colors, inv = np.unique(ifl,return_inverse=True)

zus = np.array([colors[-1]+1])
colplus = np.hstack((colors,zus))
ccnt = np.histogram(ifl,colplus)[0]

t1=clock()
print (t1-t0)
t0=t1


 --

 Christopher Barker, Ph.D.
 Oceanographer

 Emergency Response Division
 NOAA/NOS/ORR(206) 526-6959   voice
 7600 Sand Point Way NE   (206) 526-6329   fax
 Seattle, WA  98115   (206) 526-6317   main reception

 chris.bar...@noaa.gov
 ___
 NumPy-Discussion mailing list
 NumPy-Discussion@scipy.org
 http://mail.scipy.org/mailman/listinfo/numpy-discussion

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


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

2012-01-21 Thread Torgil Svensson
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,  a...@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

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


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

2012-01-18 Thread apo

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


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

2012-01-17 Thread Chris Barker
Here's a thought:

Too bad numpy doesn't have a 24 bit integer, but you could tack a 0
on, making your image 32 bit, then use histogram2d to count the
colors.

something like (untested):

# create the 32 bit image
32bit_im = np.zeros((w, h), dtype = np.uint32)
view = 32bit_im.view(dtype = np.uint8).reshape((w,h,4))
view[:,:,:3] = im

# histogram it:
bins = # this is the trick -- setting your bins right
   # remember that histrogram is designed for floats, so
you're bin boundaries shold be between the inteer values you want.

colors = np.histogram(32bit_im, bins=bins)



NOTE: the image processing scikit may well have somethign already --
histogramming an image is a common process.

-Chris




On Sun, Jan 15, 2012 at 9:40 AM, Nadav Horesh nad...@visionsense.com wrote:
 im_flat = im0[...,0]*65536 + im[...,1]*256 +im[...,2]
 colours = np.unique(im_flat)

    Nadav

 
 From: numpy-discussion-boun...@scipy.org
 [numpy-discussion-boun...@scipy.org] On Behalf Of Tony Yu [tsy...@gmail.com]
 Sent: 15 January 2012 18:03
 To: Discussion of Numerical Python
 Subject: Re: [Numpy-discussion] Counting the Colors of RGB-Image



 On Sun, Jan 15, 2012 at 10:45 AM, a...@pdauf.de wrote:


 Counting the Colors of RGB-Image,
 nameit im0 with im0.shape = 2500,3500,3
 with this code:

 tab0 = zeros( (256,256,256) , dtype=int)
 tt = im0.view()
 tt.shape = -1,3
 for r,g,b in tt:
  tab0[r,g,b] += 1

 Question:

 Is there a faster way in numpy to get this result?


 MfG elodw


 Assuming that your image is made up of integer values (which I guess they'd
 have to be if you're indexing into `tab0`), then you could write:

 rgb_unique = set(tuple(rgb) for rgb in tt)

 I'm not sure if it's any faster than your loop, but I would assume it is.

 -Tony

 ___
 NumPy-Discussion mailing list
 NumPy-Discussion@scipy.org
 http://mail.scipy.org/mailman/listinfo/numpy-discussion




-- 
--

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/ORR            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

chris.bar...@noaa.gov
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


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

2012-01-15 Thread apo

Counting the Colors of RGB-Image, 
nameit im0 with im0.shape = 2500,3500,3
with this code:

tab0 = zeros( (256,256,256) , dtype=int)
tt = im0.view()
tt.shape = -1,3
for r,g,b in tt:
 tab0[r,g,b] += 1

Question:

Is there a faster way in numpy to get this result?


MfG elodw




___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


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

2012-01-15 Thread Tony Yu
On Sun, Jan 15, 2012 at 10:45 AM, a...@pdauf.de wrote:


 Counting the Colors of RGB-Image,
 nameit im0 with im0.shape = 2500,3500,3
 with this code:

 tab0 = zeros( (256,256,256) , dtype=int)
 tt = im0.view()
 tt.shape = -1,3
 for r,g,b in tt:
  tab0[r,g,b] += 1

 Question:

 Is there a faster way in numpy to get this result?


 MfG elodw


Assuming that your image is made up of integer values (which I guess they'd
have to be if you're indexing into `tab0`), then you could write:

 rgb_unique = set(tuple(rgb) for rgb in tt)

I'm not sure if it's any faster than your loop, but I would assume it is.

-Tony
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


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

2012-01-15 Thread Nadav Horesh
im_flat = im0[...,0]*65536 + im[...,1]*256 +im[...,2]
colours = np.unique(im_flat)

   Nadav


From: numpy-discussion-boun...@scipy.org [numpy-discussion-boun...@scipy.org] 
On Behalf Of Tony Yu [tsy...@gmail.com]
Sent: 15 January 2012 18:03
To: Discussion of Numerical Python
Subject: Re: [Numpy-discussion] Counting the Colors of RGB-Image



On Sun, Jan 15, 2012 at 10:45 AM, a...@pdauf.demailto:a...@pdauf.de wrote:

Counting the Colors of RGB-Image,
nameit im0 with im0.shape = 2500,3500,3
with this code:

tab0 = zeros( (256,256,256) , dtype=int)
tt = im0.view()
tt.shape = -1,3
for r,g,b in tt:
 tab0[r,g,b] += 1

Question:

Is there a faster way in numpy to get this result?


MfG elodw

Assuming that your image is made up of integer values (which I guess they'd 
have to be if you're indexing into `tab0`), then you could write:

 rgb_unique = set(tuple(rgb) for rgb in tt)

I'm not sure if it's any faster than your loop, but I would assume it is.

-Tony
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion