[mmdatatype] [Up] [mmset2mat] | Image Information and Manipulation |
Return tuple with array of pixel coordinates and array of corresponding pixel values. The input image is in the matrix format, like the structuring element, where the origin (0,0) is at the center of the matrix.
>>> f=uint8([[1,2,3],[4,5,6],[7,8,9]])
>>> i,v=mmmat2set(f)
>>> print i
[[-1 -1] [-1 0] [-1 1] [ 0 -1] [ 0 0] [ 0 1] [ 1 -1] [ 1 0] [ 1 1]]
>>> print v
[1 2 3 4 5 6 7 8 9]
>>> f=uint8([[1,2,3,4],[5,6,7,8]])
>>> i,v=mmmat2set(f)
>>> print i
[[ 0 -1] [ 0 0] [ 0 1] [ 0 2] [ 1 -1] [ 1 0] [ 1 1] [ 1 2]]
>>> print v
[1 2 3 4 5 6 7 8]
def mmmat2set(A): from Numeric import take, ravel, nonzero, transpose, NewAxis if len(A.shape) == 1: A = A[NewAxis,:] offsets = nonzero(ravel(A) - mmlimits(A)[0]) if len(offsets) == 0: return ([],[]) (h,w) = A.shape x = range(2) x[0] = offsets/w - (h-1)/2 x[1] = offsets%w - (w-1)/2 x = transpose(x) CV = x,take(ravel(A),offsets) return CV
[mmdatatype] [Up] [mmset2mat] | ![]() |
Copyright (c) 2003, Roberto A. Lotufo, UNICAMP-University of Campinas; Rubens C. Machado, CenPRA-Renato Archer Research Center. |