<div>in my endless pursuit of perfomance, i'm searching for a quick way to create a 3d histogram from a 3d rgb image. </div>
<div> </div>
<div>Here is what I have so far for a (16,16,16) 3d histogram:</div>
<div> </div>
<div>def hist3d(imgarray):<br> histarray = N.zeros((16, 16, 16))<br> temp = imgarray.copy()<br> (i, j) = imgarray.shape[0:2]<br> temp = (temp - temp % 16) / 16<br> for a in range(i):<br> for b in range(j):<br>
(b1, b2, b3) = temp[a, b, :]<br> histarray[b1, b2, b3] += 1<br> return histarray</div>
<div> </div>
<div>this works, but takes about 4 seconds for a 640x480 image. </div>
<div> </div>
<div>I tried doing the inverse of my previous post, namely replacing the nested for loop with:</div>histarray[temp[:,:,0], temp[:,:,1], temp[:,:,2]] += 1
<div> </div>
<div> </div>
<div>but that doesn't work for whatever reason. It gives me number, but they're incorrect. </div>
<div> </div>
<div>Any ideas?</div>
<div> </div>
<div>Chris</div>