[iatile] [Up] [iameshgrid] Image Information and Manipulation

iaind2sub
Convert linear index to double subscripts.

Synopsis

x, y = iaind2sub( dim, i )

Implemented in Python.

Input

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

Dimension.

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

Index.

Output

x Image. Gray-scale (uint8 or uint16) or binary image (logical).
y Image. Gray-scale (uint8 or uint16) or binary image (logical).

Examples

>>> f = Numeric.array([[0,6,0,2],[4,0,1,8],[0,0,3,0]])

              
>>> print f
[[0 6 0 2]
 [4 0 1 8]
 [0 0 3 0]]
>>> i = Numeric.nonzero(Numeric.ravel(f))

              
>>> (x,y) = iaind2sub(f.shape, i)

              
>>> print x
[0 0 1 1 1 2]
>>> print y
[1 3 0 2 3 2]
>>> print f[x[0],y[0]]
6
>>> print f[x[4],y[4]]
8

Source Code

def iaind2sub(dim, i):
    from Numeric import asarray
    i = asarray(i)
    x = i / dim[1]
    y = i % dim[1]
    return x, y
    
[iatile] [Up] [iameshgrid] http://www.python.org