Next: regrid3, Previous: regex, Up: Internal Routines [Contents][Index]

`regrid(`

`x`, `xgrid`, `ygrid`, `sx`, `sy`)

Maps a 2D image onto a specified grid and returns the mapped image. Uses nearest-neighbor interpolation.

`x`the two-dimensional image to be remapped.

`xgrid ygrid`the remapping cell grid: the coordinates of the corners of the remapped image in the coordinate system of the old image. Must be 2D arrays.

`sx sy`The interpolation grid dimensions within each grid cell. Must be scalars.

If `ngx`

, `ngy`

are the dimensions of the grid, then the
dimensions of the resulting image are equal to `(ngx-1)*sx`

and
`(ngy-1)*sy`

, respectively.

Areas in the remapped image for which there is no equivalent data in the original image are set to zero.

Identity mapping, i.e., mappings that return an exact copy of image
`x`

, are given by `regrid(x,cx,cy,nx,ny)`

with ```
nx =
dimen(x,0)/ngx
```

, `ny = dimen(x,1)/ngy`

, ```
cx =
indgen(fltarr(ngx,ngy),0)*dimen(x,0)/(ngx - 1)
```

and ```
cy =
indgen(cx,1)*dimen(x,1)/(ngy - 1)
```

, with `ngx`

and `ngy`

integers greater than 1. Some examples of linear remappings, with
`nx`

, `ny`

, `cx`

, and `cy`

as above for ```
ngx =
2
```

and `ngy = 2`

, are:

- change in scale
`regrid(x,cx,cy,nx/2,ny/2)`

makes the image half the size.- cropping
`regrid(x,cx/2,cy/2,nx/2,ny/2)`

selects the lower half of the image, i.e.,`x(0:nx/2-1,0:ny/2-1)`

.- translation
`regrid(x,cx+100,cy,nx,ny)`

shifts the image over 100 pixels to the left (in the direction of negative x).- rotation around the origin
`regrid(x,cx*cos(phi)+cy*sin(phi),-cx*sin(phi)+cy*cos(phi),nx,ny)`

rotates the image counterclockwise over angle`phi`

, i.e., the positive x axis rotates over angle`phi`

in the direction of the positive y axis.

If you need to combine some of these operations, then perform them on
`cx`

, `cy`

, `nx`

, and `ny`

, and only then apply them
to the image. For example, to rotate the image over 1 radian around
point `(100,200)`

and expand it by a factor of 3, you could do

cx2 = cx - 100 ; translate cy2 = cy - 200 cx3 = cx2*cos(1)+cy2*sin(1) ; rotate cy3 = -cx2*sin(1)+cy2*cos(1) cx4 = cx3 + 100 ; translate back cy4 = cx4 + 200 y = regrid(x,cx,cy,nx*3,ny*3)

See also: compress, expand, regrid3, regrid3ns

• regrid Details: |

Next: regrid3, Previous: regex, Up: Internal Routines [Contents][Index]