| [mmshow] [Up] [mmplot] | Visualization |
Implemented in Python.
| y | Image Binary image.
shaded image. |
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.
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
| [mmshow] [Up] [mmplot] | |
| Copyright (c) 2003, Roberto A. Lotufo, UNICAMP-University of Campinas; Rubens C. Machado, CenPRA-Renato Archer Research Center. |