I am using the Matlab/Octave imresize()
function which resamples a given 2D array. I want to understand how a particular interpolation algorithm used in imresize
works.
(I am using octave on windows)
e.g.
A = 1 2
3 4
is a 2D array. Then I use the command
b=imresize(a,2,'linear');
basically upsampling row and columns by 2.
The output is
1.0000 1.3333 1.6667 2.0000
1.6667 2.0000 2.3333 2.6667
2.3333 2.6667 3.0000 3.3333
3.0000 3.3333 3.6667 4.0000
I don't understand how this linear interpolation is working. It is said to use bilinear interpolation, but how does it pad the data at boundaries and how does it get the output that it is getting?
Second example: For
A =
1 2 3 4
5 6 7 8
0 1 2 3
1 2 3 4
how does imresize(a,1.5,'linear')
give the following output?
1.00000 1.60000 2.20000 2.80000 3.40000 4.00000
3.40000 4.00000 4.60000 5.20000 5.80000 6.40000
4.00000 4.60000 5.20000 5.80000 6.40000 7.00000
1.00000 1.60000 2.20000 2.80000 3.40000 4.00000
0.40000 1.00000 1.60000 2.20000 2.80000 3.40000
1.00000 1.60000 2.20000 2.80000 3.40000 4.00000
As you can see, in your example, each corner point is one of your original input values.
The intermediate values are derived via linear interpolation in each direction. So for instance, to calculate b(3,2)
:
b(1,2)
is 1/3 of the way between b(1,1)
and b(1,4)
. So:
b(1,2) = (1/3)*b(1,4) + (2/3)*b(1,1)
b(4,2)
is 1/3 of the way between b(4,1)
and b(4,4)
. So:
b(4,2) = (1/3)*b(4,4) + (2/3)*b(4,1)
b(3,2)
is 2/3 of the way between b(1,2)
and b(4,2)
. So:
b(3,2) = (2/3)*b(4,2) + (1/3)*b(1,2)