| [mmmat2set] [Up] [mmreadgray] | Image Information and Manipulation |
Return an image in the matrix format built from a tuple of an array of pixel coordinates and a corresponding array of pixel values
>>> coord=int32([ [ 0,0], [-1,0], [ 1,1]])
>>> A=mmset2mat((coord,))
>>> print A
[[0 1 0] [0 1 0] [0 0 1]]
>>> print mmdatatype(A)
binary
>>> vu = uint8([1,2,3])
>>> f=mmset2mat((coord,vu))
>>> print f
[[0 2 0] [0 1 0] [0 0 3]]
>>> print mmdatatype(f)
uint8
>>> vi = int32([1,2,3])
>>> g=mmset2mat((coord,vi))
>>> print g
[[-2147483647 2 -2147483647] [-2147483647 1 -2147483647] [-2147483647 -2147483647 3]]
>>> print mmdatatype(g)
int32
def mmset2mat(A):
from MLab import max
from Numeric import put, ones, ravel, shape, NewAxis, array, asarray
if len(A) == 2:
x, v = A
v = asarray(v)
elif len(A) == 1:
x = A[0]
v = ones((len(x),), '1')
else:
raise TypeError, 'Argument must be a tuple of length 1 or 2'
if len(x) == 0: return array([0]).astype(v.typecode())
if len(x.shape) == 1: x = x[NewAxis,:]
dh,dw = max(abs(x))
h,w = (2*dh)+1, (2*dw)+1
M=ones((h,w)) * mmlimits(v)[0]
offset = x[:,0] * w + x[:,1] + (dh*w + dw)
put(M,offset,v)
M = M.astype(v.typecode())
return M
| mmmat2set | Converts image representation from matrix to set |
| [mmmat2set] [Up] [mmreadgray] | |
| Copyright (c) 2003, Roberto A. Lotufo, UNICAMP-University of Campinas; Rubens C. Machado, CenPRA-Renato Archer Research Center. |