ianshow - Image graphic representation useful for illustration, accepts overlay color planes

Synopse

ianshow creates a graphical representation of an image with numerical values suitable for illustration.

  • g = ianshow(f,X1,X2,X3,X4,X5,X6,X7)
    • Output
      • g: RGB color image ready for adshow
    • Input
      • f: 2D gray scale image.
      • X1: 2D boolean image, red overlay
      • X2: 2D boolean image, green overlay
      • X3: 2D boolean image, red overlay
      • X4: 2D boolean image, red overlay
      • X5: 2D boolean image, red overlay
      • X6: 2D boolean image, red overlay

Description

The ianshow function creates a graphical representation of an image where each pixel is represented by a square and its pixel values are printed. It is possible to color each pixel using overlayed boolean images.

Function Code

01. import ia636 as ia
02. import numpy as np
03. 
04. def t(s,dt=1):
05.    a = ia.iatext(s)
06.    b = np.pad(a,((6+3-dt,6+3-dt),(0+3-dt,0+3-dt)),'constant', constant_values=((False,False),(False,False)))
07.    c = np.pad(b,((dt,dt),(dt,dt)),'constant', constant_values=((True,True),(True,True)))
08.    return c
09. 
10. def timg(f,dt=1):
11. 
12.   tFalse = t('   ',dt)
13.   dy, dx = tFalse.shape
14.   tTrue = np.zeros_like(tFalse)
15.   z = np.empty(tuple(np.array(f.shape) * np.array([dy,dx]))).astype(bool)
16.   if f.dtype == 'bool':
17.     for x in np.arange(f.shape[-1]):
18.       for y in np.arange(f.shape[-2]):
19.         if f[y,x]:
20.           z[y*dy:y*dy+dy,x*dx:x*dx+dx] = tFalse
21.         else:
22.           z[y*dy:y*dy+dy,x*dx:x*dx+dx] = tTrue
23.     z=~np.pad(z,((1,1),(1,1)),'constant')
24.   else:
25.     for x in np.arange(f.shape[-1]):
26.       for y in np.arange(f.shape[-2]):
27.         z[y*dy:y*dy+dy,x*dx:x*dx+dx] = t('%3d' % f[y,x],dt)
28.     z=np.pad(~z,((1,1),(1,1)),'constant')
29.   return z
30. 
31. def ianshow(X, X1=None, X2=None, X3=None, X4=None, X5=None, X6=None):
32.   x = timg(X)
33.   x1,x2,x3,x4,x5,x6 = None,None,None,None,None,None
34.   if X1 is not None:
35.     x1 = ~timg(X1,3)
36.   if X2 is not None:
37.     x2 = ~timg(X2,3)
38.   if X3 is not None:
39.     x3 = ~timg(X3,3)
40.   if X4 is not None:
41.     x4 = ~timg(X4,3)
42.   if X5 is not None:
43.     x5 = ~timg(X5,3)
44.   if X6 is not None:
45.     x6 = ~timg(X6,3)
46.   return ia.iagshow(x,x1,x2,x3,x4,x5,x6)

Examples

Binary example:

1. import ia636 as ia
2. 
3. f = arange(30).reshape(5,6)
4. print 'f\n',f
5. adshow(ia.ianshow(f>2,f>20,f>25))
f
[[ 0  1  2  3  4  5]
 [ 6  7  8  9 10 11]
 [12 13 14 15 16 17]
 [18 19 20 21 22 23]
 [24 25 26 27 28 29]]

Gray-scale example:

1. fb1 = f>100
2. fb2 = fb1.copy()
3. fb3 = fb1.copy()
4. fb1[::2,::2] = True
5. fb2[3:5, 1:2] = True
6. fb3[1,:] = True
7. 
8. adshow(ia.ianshow(f,fb1,fb2,fb3))

See Also

  • iagshow - Display gray scale image overlayed by binary images as color layers.
  • adshow - Display image in Adessowiki.

Contributions

  • Roberto Lotufo, 18ago2013: initial function.