[mmdatatype] [Up] [mmset2mat] Image Information and Manipulation

mmmat2set
Converts image representation from matrix to set

Synopsis

CV = mmmat2set( A )

Implemented in Python.

Input

A Image Gray-scale (uint8 or uint16) or binary image.

Image in matrix format.

Output

CV Image Gray-scale (uint8 or uint16) or binary image.

Tuple with array of coord and array of values

Return tuple with array of coord and array of values

Source Code

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] Python