[mmshow] [Up] [mmplot] Visualization

mmbshow
Generate a graphical representation of overlaid binary images.

Synopsis

y = mmbshow( f1, f2 = None, f3 = None, factor = 17 )

Implemented in Python.

Input

f1 Image Binary image.
f2 Image Binary image.

Default: None

f3 Image Binary image.

Default: None

factor Double

Expansion factor for the output image. Use odd values above 9.

Default: 17

Output

y Image Binary image.

shaded image.

Description

Generate an expanded binary image as a graphical representation of up to three binary input images. The 1-pixels of the first image are represented by square contours, the pixels of the optional second image are represented by circles and for the third image they are represented by shaded squares. This function is useful to create graphical illustration of small images.

Examples

>>> f1=mmtext('b')

              
>>> f2=mmtext('w')

              
>>> g2=mmbshow(f1,f2)

              
>>> mmshow(g2)

              
>>> f3=mmtext('x')

              
>>> g3=mmbshow(f1,f2,f3)

              
>>> mmshow(g3);

            
g2 g3

Source Code

def mmbshow(f1, f2=None, f3=None, factor=17):
    from Numeric import NewAxis, zeros, resize, transpose, floor, arange, array
    if f1.shape == ()    : f1 = array([f1])
        if len(f1.shape) == 1: f1 = f1[NewAxis,:]
        if (`f1.shape` != `f2.shape`) or \
           (`f1.shape` != `f3.shape`) or \
           (`f2.shape` != `f3.shape`):
           print 'Different sizes.'
           return None
        s = factor
        if factor < 9: s = 9
        h,w = f1.shape
        y = zeros((s*h, s*w))
        xc = resize(range(s), (s,s))
        yc = transpose(xc)
        r  = int(floor((s-8)/2. + 0.5))
        circle = (xc - s/2)**2 + (yc - s/2)**2 <= r**2
        r = arange(s) % 2
        fillrect = resize(array([r, 1-r]), (s,s))
        fillrect[0  ,:] = 0
        fillrect[s-1,:] = 0
        fillrect[:  ,0] = 0
        fillrect[:  ,s-1] = 0
        for i in range(h):
            for j in range(w):
                m, n = s*i, s*j
                if f1 and f1[i,j]:
                    y[m     ,n:n+s] = 1
                    y[m+s-1 ,n:n+s] = 1
                    y[m:m+s ,n    ] = 1
                    y[m:m+s ,n+s-1] = 1
                if f2 and f2[i,j]:
                    y[m:m+s, n:n+s] = y[m:m+s, n:n+s] + circle
                if f3 and f3[i,j]:
                    y[m:m+s, n:n+s] = y[m:m+s, n:n+s] + fillrect
        y = y > 0
    return y
    

See also

mmshow Display binary or gray-scale images and optionally overlay it with binary images.
mmseshow Display a structuring element as an image.
[mmshow] [Up] [mmplot] Python