def iacolorhist(f, mask=None):
from Numeric import asarray, nonzero, ravel, zeros, Int32, ones, transpose, put, NewAxis
WFRAME=5
f = asarray(f)
if len(f.shape) == 1: f = f[NewAxis,:]
if not f.typecode() == 'b':
iaerror('error, can only process uint8 images')
return
if not f.shape[0] == 3:
iaerror('error, can only process 3-band images')
return
r,g,b = 1.*f[0,:,:], 1.*f[1,:,:], 1.*f[2,:,:]
n_zeros = 0
if mask:
n_zeros = f.shape[0]*f.shape[1]-len(nonzero(ravel(mask)))
r,g,b = mask*r, mask*g, mask*b
hrg = zeros((256,256), Int32); hbg=hrg+0; hrb=hrg+0
img = 256*r + g; m1 = max(ravel(img))
aux = iahistogram(img.astype(Int32)); aux[0] = aux[0] - n_zeros
put(ravel(hrg), range(m1+1), aux)
img = 256*b + g; m2 = max(ravel(img))
aux = iahistogram(img.astype(Int32)); aux[0] = aux[0] - n_zeros
put(ravel(hbg), range(m2+1), aux)
img = 256*r + b; m3 = max(ravel(img))
aux = iahistogram(img.astype(Int32)); aux[0] = aux[0] - n_zeros
put(ravel(hrb), range(m3+1), aux)
m=max(max(ravel(hrg)),max(ravel(hbg)),max(ravel(hrb)))
hc=m*ones((3*WFRAME+2*256,3*WFRAME+2*256))
hc[WFRAME:WFRAME+256,WFRAME:WFRAME+256] = transpose(hrg)
hc[WFRAME:WFRAME+256,2*WFRAME+256:2*WFRAME+512] = transpose(hbg)
hc[2*WFRAME+256:2*WFRAME+512,WFRAME:WFRAME+256] = transpose(hrb)
return hc