Author Topic: interpolating values  (Read 4075 times)

0 Members and 1 Guest are viewing this topic.

Offline Kirl

  • Senior Member
  • Pentium
  • ********
  • Posts: 1217
  • Karma: 230
    • View Profile
    • Homepage
interpolating values
« on: March 14, 2012 »
I need to interpolate 4 values, am I right that interpolation is basically calculating an average?

Code: [Select]
(value1 + value2 + value3 + value4) /4;
I never had any kind of formal math training so I'm mostly clueless when it comes to specific terms.
www.kirl.nl
Challenge Trophies Won:

Offline hellfire

  • Sponsor
  • Pentium
  • *******
  • Posts: 1294
  • Karma: 466
    • View Profile
    • my stuff
Re: interpolating values
« Reply #1 on: March 14, 2012 »
That's one possible method.
If your values have a spatial relationship you might want to consider gauss filter, median cut or linear regression, too.
Challenge Trophies Won:

Offline Kirl

  • Senior Member
  • Pentium
  • ********
  • Posts: 1217
  • Karma: 230
    • View Profile
    • Homepage
Re: interpolating values
« Reply #2 on: March 15, 2012 »
Thanks! Wikipedia is normally my fist stop for finding anything, but the mathematical notation is near impossible to decipher. Theory is often sufficient, but I find most of wikipedia's math articles are lacking in clarity as well.

I should probably just find some math training.  :whisper:
www.kirl.nl
Challenge Trophies Won:

Offline hellfire

  • Sponsor
  • Pentium
  • *******
  • Posts: 1294
  • Karma: 466
    • View Profile
    • my stuff
Re: interpolating values
« Reply #3 on: March 15, 2012 »
Wikipedia is normally my fist stop for finding anything, but the mathematical notation is near impossible to decipher.
Maybe I can omit the math with a simple example.
Imagine a set of values "v" over the x axis:
Code: [Select]
int v[]= { 1, 3, 6, 5, 8,12,11,14 };
int x[]= { 0, 1, 2, 3, 4, 5, 6, 7 };

Let's take an averaging radius of 2 values, so for eg x=3 you'd weight the values 1..5.
The unweighted approach:
Code: [Select]
average= ( v[1] + v[2] + v[3] + v[4] + v[5] ) / 5;
       = ( 3 + 6 + 5 + 8 + 12 ) / 5 = 6.8

The gauss filter calculates a weighted average by taking the distance into account (the bigger the distance, the smaller the weight):
Code: [Select]
float maximum= 0.4;
float medium= 0.25;
float small= 0.05;
average= v[1]*small + v[2]*medium +  v[3]*maximum  + v[4]*medium + v[5]*small;
       = 6.25
Notice that the sum of all weights is 1.0.

For median cut you'd sort all values in the averaging range and pick the center.
Anomalies are expected to gather at the upper and lower end (so the center element is usually pretty average):
Code: [Select]
v[1..5]: 3, 6, 5, 8,12
sorted:  3, 5, 6, 8,12
center:  6
Challenge Trophies Won:

Offline ttemper

  • Amiga 1200
  • ****
  • Posts: 267
  • Karma: 7
    • View Profile
Re: interpolating values
« Reply #4 on: March 15, 2012 »
@hellfire, great explanation on the different techniques. pixels will never look the same! :P K++

Offline Kirl

  • Senior Member
  • Pentium
  • ********
  • Posts: 1217
  • Karma: 230
    • View Profile
    • Homepage
Re: interpolating values
« Reply #5 on: March 15, 2012 »
Yes, an excellent explanation of the various forms, thanks a lot!

Proably best to replace the wikipedia articles with your post!  ;D
www.kirl.nl
Challenge Trophies Won: