Older Newer
Mon, 23 Dec 2019 03:05:31 . . . . SyneRyder [First function definition]


Changes by last author:

Added:
= cosineInterpolate =

== Syntax ==

int cosineInterpolate(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 cosine 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. Cosine interpolation can create a slightly crisper/sharper result than linear interpolation.

== Example ==

This example performs a kind of cosine interpolated zoom operation.

<code>

%fml

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

ctl[1]: CHECKBOX, Text="Use Cosine Interpolation", Val=1

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, interpolatedlwr, interpolated;

if (ctl(1)) {

interpolatedtop = cosineInterpolate(topleft, topright, srcx - floor(srcx));

interpolatedlwr = cosineInterpolate(lwrleft, lwrright, srcx - floor(srcx));

interpolated = cosineInterpolate(interpolatedtop, interpolatedlwr, srcy - floor(srcy));

}

else {

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

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

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

}

pset(x, y, z, interpolated);

}

}

}

return true;

}

</code>

== Comment ==

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

== See Also ==

iget, (cubicInterpolate)?, (hermiteInterpolate)?, linearInterpolate