# mmmat2set
Converts image representation from matrix to set

## Synopsis

CV = mmmat2set( A )

Implemented in Python.

### Input

A | Image Image in matrix format, where the origin (0,0) is at the center of the matrix.

### Output

CV | Image Tuple with array of pixel coordinates and array of corresponding pixel values

## Description

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.

## Examples

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

When image size is even, the origin is at the nearest top-left neighbor pixel of the center of the matrix

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

## 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

## See also

mmset2mat | Converts image representation from set to matrix
mmseshow | Display a structuring element as an image.

[`mmdatatype`] [Up] [`mmset2mat`] |
Copyright (c) 2003, Roberto A. Lotufo, UNICAMP-University of Campinas; Rubens C. Machado, CenPRA-Renato Archer Research Center.