Function iagshow

Synopse

Overlay color planes on a gray scale image ready for display.

  • g = iagshow(f, X1, X2, X3, X4, X5, X6)
    • g: Output. RGB Image.
    • f: Image. Gray Scale input image.
    • X1: binary image. Overlay as Red.
    • X2: binary image. Overlay as Green.
    • X3: binary image. Overlay as Blue.
    • X4: binary image. Overlay as Magenta.
    • X5: binary image. Overlay as Yellow.
    • X6: binary image. Overlay as Cyan.
01. import numpy as np
02. 
03. def iagshow(X, X1=None, X2=None, X3=None, X4=None, X5=None, X6=None):
04. 
05.     if X.dtype == np.bool: X = np.where(X,255,0).astype('uint8')
06.     r = X
07.     g = X
08.     b = X
09.     if X1 is not None: # red 1 0 0
10.       if (X1.dtype != np.bool): raise Exception,'X1 must be binary overlay'
11.       r = np.where(X1,255,r)
12.       g = np.where(~X1,g,0)
13.       b = np.where(~X1,b,0)
14.     if X2 is not None: # green 0 1 0
15.       if (X2.dtype != np.bool): raise Exception,'X2 must be binary overlay'
16.       r = np.where(~X2,r,0)
17.       g = np.where(X2,255,g)
18.       b = np.where(~X2,b,0)
19.     if X3 is not None: # blue 0 0 1
20.       if (X3.dtype != np.bool): raise Exception,'X3 must be binary overlay'
21.       r = np.where(~X3,r,0)
22.       g = np.where(~X3,g,0)
23.       b = np.where(X3,255,b)
24.     if X4 is not None: # magenta 1 0 1
25.       if (X4.dtype != np.bool): raise Exception,'X4 must be binary overlay'
26.       r = np.where(X4,255,r)
27.       g = np.where(~X4,g,0)
28.       b = np.where(X4,255,b)
29.     if X5 is not None: # yellow 1 1 0
30.       if (X5.dtype != np.bool): raise Exception,'X5 must be binary overlay'
31.       r = np.where(X5,255,r)
32.       g = np.where(X5,255,g)
33.       b = np.where(~X5,b,0)
34.     if X6 is not None: # cyan 0 1 1
35.       if (X6.dtype != np.bool): raise Exception,'X6 must be binary overlay'
36.       r = np.where(~X6,r,0)
37.       g = np.where(X6,255,g)
38.       b = np.where(X6,255,b)
39.     return np.array([r,g,b])

Description

Creates a RGB image from the input grayscale image f, overlayed by optional binary planes, each one with a different color. This function is useful to display results of segmentation or when one wants to highlight a particular region of the image.

Examples

1. import numpy as np
2. import ia636
3. from iagshow import iagshow
4. 
5. f = np.arange(25).reshape(5,5)
6. print iagshow(f,f>20)
[[[  0   1   2   3   4]
  [  5   6   7   8   9]
  [ 10  11  12  13  14]
  [ 15  16  17  18  19]
  [ 20 255 255 255 255]]

 [[  0   1   2   3   4]
  [  5   6   7   8   9]
  [ 10  11  12  13  14]
  [ 15  16  17  18  19]
  [ 20   0   0   0   0]]

 [[  0   1   2   3   4]
  [  5   6   7   8   9]
  [ 10  11  12  13  14]
  [ 15  16  17  18  19]
  [ 20   0   0   0   0]]]
1. f = adread('cameraman.tif')
2. g = iagshow(f, f>230)
3. print ia636.iaimginfo(g)
4. adshow(g,'pixels with values above 230 are shown in red')
<type 'numpy.ndarray'> (3, 256, 256) uint8 0.000000 255.000000

pixels with values above 230 are shown in red

1. f = ia636.iagaussian((256,256), transpose([[128,128]]), [[50*50,0],[0,80*80]])
2. fn = ia636.ianormalize(f, [0,255])
3. adshow(fn,title='original')
4. f1 = iagshow(fn, fn > 20, fn > 30, fn > 40, fn > 50, fn > 60, fn > 70)
5. adshow (f1, title='overlaied')

original

overlaied

See Also

iagshow - display a binary, gray-scale or color image