[iaind2sub] [Up] [ianeg] Image Information and Manipulation

iameshgrid
Create two 2-D matrices of indexes.

Synopsis

x, y = iameshgrid( vx, vy )

Implemented in Python.

Input

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

Vector of indices of x coordinate.

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

Vector of indices of y coordinate.

Output

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

2-D matrix of indexes of x coordinate.

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

2-D matrix of indexes of y coordinate.

Description

This function generates 2-D matrices of indices of the domain specified by arange1 and arange2. This is very useful to generate 2-D functions. Note that unlike other functions, the order of the parameters uses the cartesian coordenate convention. arange1 is for x (horizontal), and arange2 is for y (vertical).

Equation

Examples

>>> (x, y) = iameshgrid(Numeric.arange(1,3,0.5), Numeric.arange(2,4,0.6))

              
>>> print x
[[ 1.   1.5  2.   2.5]
 [ 1.   1.5  2.   2.5]
 [ 1.   1.5  2.   2.5]
 [ 1.   1.5  2.   2.5]]
>>> print y
[[ 2.   2.   2.   2. ]
 [ 2.6  2.6  2.6  2.6]
 [ 3.2  3.2  3.2  3.2]
 [ 3.8  3.8  3.8  3.8]]
>>> print x + y
[[ 3.   3.5  4.   4.5]
 [ 3.6  4.1  4.6  5.1]
 [ 4.2  4.7  5.2  5.7]
 [ 4.8  5.3  5.8  6.3]]
>>> (x, y) = iameshgrid(range(256), range(256))

              
>>> iashow(x)
(256, 256) Min= 0 Max= 255 Mean=127.500 Std=73.90
>>> iashow(y)
(256, 256) Min= 0 Max= 255 Mean=127.500 Std=73.90
>>> iashow(x + y)
(256, 256) Min= 0 Max= 510 Mean=255.000 Std=104.51
>>> z = Numeric.sqrt((x-127)**2 + (y-127)**2)

              
>>> iashow(z)
(256, 256) Min= 0.0 Max= 181.019335984 Mean=97.946 Std=36.46
x y
x + y z

Source Code

def iameshgrid(vx, vy):
    from Numeric import resize, transpose
    x = resize(vx, (len(vy), len(vx)))
    y = transpose(resize(vy, (len(vx), len(vy))))
    return x, y
    
[iaind2sub] [Up] [ianeg] http://www.python.org