Older Newer
Mon, 23 Dec 2019 03:01:59 . . . . SyneRyder [Add return value]


Changes by last author:

Added:
= linearInterpolate =

== Syntax ==

int linearInterpolate(int v1, int v2, double x)

== Arguments ==

:v1

::The first value to interpolate between

:v2

::The second value to interpolate between

:x

::The point between the two values to interpolate at, a floating value between 0.0 and 1.0.

== Return ==

The integer result of interpolating between the two values.

== Description ==

Interpolates between two values according to a linear function. If you have values at two known points, you can estimate (interpolate) the value somewhere between those two points using this function. This is useful if you need to estimate a pixel value "between" the actual pixels, for example when zooming into an image. Linear interpolation assumes that the values continue like a straight line between those two points.

== Example ==

This example performs a kind of bilinear zoom operation.

<code>

%fml

ctl[0]: STANDARD, Text="Zoom", Val=100

ForEveryTile: {

for (y=0; y < Y; y++) {

for (x=0; x < X; x++) {

for (z=0; z < Z; z++) {

double srcx = 100.0 * x / ctl(0);

double srcy = 100.0 * y / ctl(0);

int topleft = src((int)floor(srcx), (int)floor(srcy), z);

int topright = src((int)ceil(srcx), (int)floor(srcy), z);

int lwrleft = src((int)floor(srcx), (int)ceil(srcy), z);

int lwrright = src((int)ceil(srcx), (int)ceil(srcy), z);

int interpolatedtop = linearInterpolate(topleft, topright, srcx - floor(srcx));

int interpolatedlwr = linearInterpolate(lwrleft, lwrright, srcx - floor(srcx));

int interpolated = linearInterpolate(interpolatedtop, interpolatedlwr, srcy - floor(srcy));

pset(x, y, z, interpolated);

}

}

}

return true;

}

</code>

== Comment ==

To perform bilinear interpolation across an image, it is easier to use the iget function, which does the hard work for you.

== See Also ==

iget, cosineInterpolate, (cubicInterpolate)?, (hermiteInterpolate)?