I try to resize an image with MATLAB and there was something strange to understand directly about imresize function with bilinear mode.
I will give you examples to make sure what's the problem. Say, the followings are 1D-matrix.
A: [0 1 2]
B: [1 2 0 5]
the linear interpolation of scaling A to [1,5] in 1D array, so far as I know, makes
A: [0, 0.5, 1, 1.5, 2]
However, from MATLAB,
imresize(A,[1,5],'bilinear')
shows
[0, 0.4, 1, 1.6, 2.0]
Also,
imresize(B,[1,5],'bilinear')
imresize(B,[1,10],'bilinear')
each, shows
[1.0 1.7 1.0 1.5 2.0]
[1.0 1.1667 1.16111 1.8889 1.0000 0.1111 1.9444 4.1667 5.0000]
I found a lot of questions and answers from different forums and none of them makes me be satisfied, in terms of generality.
However, I found the answer from a line of code in 'imresize.m',
u = x/scale + 0.5 * (1-1/scale)
where u
determines the index of output matrix. From the above, I realize how the strange outputs are made by imresize with bilinear
But the question is,
I don't understand the meaning of 0.5 * (1-1/scale)
.
Without 0.5 * (1-1/scale)
, u = x/scale
shows the original algorithm which can output
A: [0, 0.5, 1, 1.5, 2]
, which is truly linear.
Then, why do we need the term 0.5 * (1-1/scale)
? What is the purpose and meaning?