Function iatcrgb2ind

Synopse

True color RGB to index image and colormap.

  • fi,cm = iatcrgb2ind(f)
    • fi,cm: Image.
    • f: Image. True color RGB image.
01. import numpy as np
02. 
03. def iatcrgb2ind(f):
04. 
05.     f = np.asarray(f)
06.     r, g, b = f[0].astype(np.int), f[1].astype(np.int), f[2].astype(np.int)
07.     c = r + 256*g + 256*256*b
08. 
09.     (t,i) = np.unique(c,return_inverse=True)
10. 
11.     n = len(t)
12.     rt = np.reshape(map(lambda k:int(k%256), t), (n,1))
13.     gt = np.reshape(map(lambda k:int((k%(256*256))/256.), t), (n,1))
14.     bt = np.reshape(map(lambda k:int(k), t/(256*256.)), (n,1))
15. 
16.     cm = np.concatenate((rt, gt, bt), axis=1)
17.     fi = i.reshape(r.shape)
18.     return fi,cm

Description

Converts a true color RGB image to the format of index image and a colormap.

Examples

Example 1

01. from ia636 import iatcrgb2ind
02. 
03. r = array([[4,5,6],[4,2,4]])
04. g = array([[0,1,2],[0,4,0]])
05. b = array([[1,0,2],[1,2,2]])
06. f = array([r,g,b])
07. print 'f\n',f
08. (fi, tm) = iatcrgb2ind(f)
09. print 'fi (indices)=\n',fi
10. print 'tm (colortable)=\n',tm
f
[[[4 5 6]
  [4 2 4]]

 [[0 1 2]
  [0 4 0]]

 [[1 0 2]
  [1 2 2]]]
fi (indices)=
[[1 0 3]
 [1 4 2]]
tm (colortable)=
[[5 1 0]
 [4 0 1]
 [4 0 2]
 [6 2 2]
 [2 4 2]]