I am trying to get a working understanding of how to resize images using bilinear and bicubic transformations. I coded a resizing function based on things I've read here and Wikipedia, etc., but I get different results than what MATLAB and Mathematica give.
A minimal working example is the image im=[100 50 0]
in MATLAB or im={1, .5, 0}
in Mathematica. My algorithm (and "common sense") tells me that resizing this image to 5 pixels should give
im=[100 75 50 25 0]
and i={1, .75, .5, .25, 0}
, respectively. However, I get
im=[100 80 50 20 0]
and i={1, .8, .5, .2, 0}
from MATLAB and Mathematica when forcing the bilinear method. Specifically, the MATLAB commands
im=[100 50 0];
imresize(im,[1,5],'bilinear')
returns
ans = 100.0000 80.0000 50.0000 20.0000 0
They are obviously doing the same, different thing than my code (and common sense).
Can someone explain their algorithm to me? I am guessing it my mistakes relate to how to "index" the new image. The original image, with only one row, has a constant "y
" value of 1, with columns x=1,2,3
. I am assuming that the new image could be viewed as having columns indexed as x=1, 1.5, 2, 2.5, 3
, and interpolation is needed to compute the values of f(1.5,1)
and f(2.5,1)
.
Thanks.
edit imresize
. Many of the toolbox functions are just implemented using.m
scripts. You can look at the code and even step through it with the debugger to see exactly what it's doing. $\endgroup$imresize
might help, thanks. $\endgroup$