Function iameshgrid

namespace:ia636
page:iameshgrid

Synopse

Create two 2-D matrices of indexes.

  • x, y = iameshgrid(vx, vy)
    • x: Image.
    • y: Image.
    • vx: Image. Vector of indices of x coordinate.
    • vy: Image. Vector of indices of y coordinate.
1. from numpy import *
2. 
3. def iameshgrid(vx, vy):
4. 
5.     x = resize(vx, (len(vy), len(vx)))
6.     y = transpose(resize(vy, (len(vx), len(vy))))
7.     return x, y

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 coordinate convention. arange1 is for x (horizontal), and arange2 is for y (vertical). To use Python convention, prefer the function indices().

Equation

Examples

Example 1

1. from ia636 import iameshgrid
2. 
3. (x, y) = iameshgrid(arange(1,3,0.5), arange(2,4,0.6))
4. print x
5. print y
6. print x + y
[[ 1.   1.5  2.   2.5]
 [ 1.   1.5  2.   2.5]
 [ 1.   1.5  2.   2.5]
 [ 1.   1.5  2.   2.5]]
[[ 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]]
[[ 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]]

Example 2

1. from ia636 import ianormalize
2. (x, y) = iameshgrid(range(256), range(256))
3. adshow(x)
4. adshow(y)
5. adshow(ianormalize(x + y))
6. z = sqrt((x-127)**2 + (y-127)**2)
7. adshow(ianormalize(z))

See Also

  • indices -Return an array representing the indices of a grid