[iacolormap] [Up] [iargb2hsv] | Color Processing |
Converts a true color RGB image to the format of index image and a colormap.
>>> import Numeric
>>> r = [[4,5,6],[4,2,4]]
>>> g = [[0,1,2],[0,4,0]]
>>> b = [[1,0,2],[1,2,2]]
>>> f = Numeric.zeros((3,2,3))
>>> f[0,:,:], f[1,:,:], f[2,:,:] = r, g, b
>>> print f
[[[4 5 6] [4 2 4]] [[0 1 2] [0 4 0]] [[1 0 2] [1 2 2]]]
>>> (fi, tm) = iatcrgb2ind(f)
>>> print fi
[[1 0 3] [1 4 2]]
>>> print tm
[[5 1 0] [4 0 1] [4 0 2] [6 2 2] [2 4 2]]
def iatcrgb2ind(f): from Numeric import asarray, reshape, concatenate f = asarray(f) r, g, b = f[0,:,:], f[1,:,:], f[2,:,:] c = r + 256*g + 256*256*b (t,i,fi) = iaunique(c) siz = len(t) rt = reshape(map(lambda k:int(k%256), t), (siz,1)) gt = reshape(map(lambda k:int((k%(256*256))/256.), t), (siz,1)) bt = reshape(map(lambda k:int(k), t/(256*256.)), (siz,1)) cm = concatenate((rt, gt, bt), axis=1) fi = reshape(fi, (f.shape[1], f.shape[2])) return fi,cm
[iacolormap] [Up] [iargb2hsv] | |