## resample

resample — shrink, expand, rotate with a choice of interpolators

## Stability Level

Stable, unless otherwise indicated

## Synopsis

    #include <vips/vips.h>

    int                 im_affinei                          (VipsImage *in,
                                                             VipsImage *out,
                                                             VipsInterpolate *interpolate,
                                                             double a,
                                                             double b,
                                                             double c,
                                                             double d,
                                                             double dx,
                                                             double dy,
                                                             int ox,
                                                             int oy,
                                                             int ow,
                                                             int oh);
    int                 im_affinei_all                      (VipsImage *in,
                                                             VipsImage *out,
                                                             VipsInterpolate *interpolate,
                                                             double a,
                                                             double b,
                                                             double c,
                                                             double d,
                                                             double dx,
                                                             double dy);
    int                 im_shrink                           (VipsImage *in,
                                                             VipsImage *out,
                                                             double xshrink,
                                                             double yshrink);
    int                 im_rightshift_size                  (VipsImage *in,
                                                             VipsImage *out,
                                                             int xshift,
                                                             int yshift,
                                                             int band_fmt);
    int                 im_match_linear                     (VipsImage *ref,
                                                             VipsImage *sec,
                                                             VipsImage *out,
                                                             int xr1,
                                                             int yr1,
                                                             int xs1,
                                                             int ys1,
                                                             int xr2,
                                                             int yr2,
                                                             int xs2,
                                                             int ys2);
    int                 im_match_linear_search              (VipsImage *ref,
                                                             VipsImage *sec,
                                                             VipsImage *out,
                                                             int xr1,
                                                             int yr1,
                                                             int xs1,
                                                             int ys1,
                                                             int xr2,
                                                             int yr2,
                                                             int xs2,
                                                             int ys2,
                                                             int hwindowsize,
                                                             int hsearchsize);

## Description

Resample an image in various ways, using a VipsInterpolator to generate intermediate values.

## Details

### im_affinei ()

    int                 im_affinei                          (VipsImage *in,
                                                             VipsImage *out,
                                                             VipsInterpolate *interpolate,
                                                             double a,
                                                             double b,
                                                             double c,
                                                             double d,
                                                             double dx,
                                                             double dy,
                                                             int ox,
                                                             int oy,
                                                             int ow,
                                                             int oh);

This operator performs an affine transform on an image using `interpolate`.

The transform is:

X = `a` * x + `b` * y + `dx` Y = `c` * x + `d` * y + `dy`

x and y are the coordinates in input image. X and Y are the coordinates in output image. (0,0) is the upper left corner.

The section of the output space defined by `ox`, `oy`, `ow`, `oh` is written to `out`. See `im_affinei_all()` for a function which outputs all the transformed pixels.

See also: `im_affinei_all()`, VipsInterpolate.

`in` : | input image
`out` : | output image
`interpolate` : | interpolation method
`a` : | transformation matrix
`b` : | transformation matrix
`c` : | transformation matrix
`d` : | transformation matrix
`dx` : | output offset
`dy` : | output offset
`ox` : | output region
`oy` : | output region
`ow` : | output region
`oh` : | output region
Returns : | 0 on success, -1 on error

### im_affinei_all ()

    int                 im_affinei_all                      (VipsImage *in,
                                                             VipsImage *out,
                                                             VipsInterpolate *interpolate,
                                                             double a,
                                                             double b,
                                                             double c,
                                                             double d,
                                                             double dx,
                                                             double dy);

As `im_affinei()`, but the entire image is output.

See also: `im_affinei()`, VipsInterpolate.

`in` : | input image
`out` : | output image
`interpolate` : | interpolation method
`a` : | transformation matrix
`b` : | transformation matrix
`c` : | transformation matrix
`d` : | transformation matrix
`dx` : | output offset
`dy` : | output offset
Returns : | 0 on success, -1 on error

### im_shrink ()

    int                 im_shrink                           (VipsImage *in,
                                                             VipsImage *out,
                                                             double xshrink,
                                                             double yshrink);

Shrink `in` by a pair of factors with a simple box filter.

You will get aliasing for non-integer shrinks. In this case, shrink with this function to the nearest integer size above the target shrink, then downsample to the exact size with `im_affinei()` and your choice of interpolator.

`im_rightshift_size()` is faster for factors which are integer powers of two.

See also: `im_rightshift_size()`, `im_affinei()`.

`in` : | input image
`out` : | output image
`xshrink` : | horizontal shrink
`yshrink` : | vertical shrink
Returns : | 0 on success, -1 on error

### im_rightshift_size ()

    int                 im_rightshift_size                  (VipsImage *in,
                                                             VipsImage *out,
                                                             int xshift,
                                                             int yshift,
                                                             int band_fmt);

Shrink `in` by a pair of power-of-two factors, shifting to give output of the specified band format. This is faster than `im_shrink()`.

See also: `im_shrink()`, `im_affinei()`.

`in` : | input image
`out` : | output image
`xshift` : | horizontal shrink
`yshift` : | vertical shrink
`band_fmt` : | output format
Returns : | 0 on success, -1 on error

### im_match_linear ()

    int                 im_match_linear                     (VipsImage *ref,
                                                             VipsImage *sec,
                                                             VipsImage *out,
                                                             int xr1,
                                                             int yr1,
                                                             int xs1,
                                                             int ys1,
                                                             int xr2,
                                                             int yr2,
                                                             int xs2,
                                                             int ys2);

Scale, rotate and translate `sec` so that the tie-points line up.

See also: `im_match_linear_search()`.

`ref` : | reference image
`sec` : | secondary image
`out` : | output image
`xr1` : | first reference tie-point
`yr1` : | first reference tie-point
`xs1` : | first secondary tie-point
`ys1` : | first secondary tie-point
`xr2` : | second reference tie-point
`yr2` : | second reference tie-point
`xs2` : | second secondary tie-point
`ys2` : | second secondary tie-point
Returns : | 0 on success, -1 on error

### im_match_linear_search ()

    int                 im_match_linear_search              (VipsImage *ref,
                                                             VipsImage *sec,
                                                             VipsImage *out,
                                                             int xr1,
                                                             int yr1,
                                                             int xs1,
                                                             int ys1,
                                                             int xr2,
                                                             int yr2,
                                                             int xs2,
                                                             int ys2,
                                                             int hwindowsize,
                                                             int hsearchsize);

Scale, rotate and translate `sec` so that the tie-points line up.

Before performing the transformation, the tie-points are improved by searching an area of `sec` of size `hsearchsize` for a match of size `hwindowsize` to `ref`.

This function will only work well for small rotates and scales.

See also: `im_match_linear()`.

`ref` : | reference image
`sec` : | secondary image
`out` : | output image
`xr1` : | first reference tie-point
`yr1` : | first reference tie-point
`xs1` : | first secondary tie-point
`ys1` : | first secondary tie-point
`xr2` : | second reference tie-point
`yr2` : | second reference tie-point
`xs2` : | second secondary tie-point
`ys2` : | second secondary tie-point
`hwindowsize` : | half window size
`hsearchsize` : | half search size
Returns : | 0 on success, -1 on error