# Understanding MATLAB/Mathematica's bilinear interpolation

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.

• It might help to clean up some of the acronyms that you have, and to post a self-contained MATLAB example. – Jason R Feb 21 '14 at 12:22
• @JasonR Done. I am very new to this site, though am active on the LaTeX board. There we often use MWE for "minimal working example". I've also put in some MATLAB code. Thanks. – GregH Feb 21 '14 at 13:22
• What if you pass in an image that is taller than one row? I don't have the Image Processing Toolbox, so I can't see for myself. Another thing to try with MATLAB is 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. – Jason R Feb 21 '14 at 13:24
• @JasonR I started with larger images then realized that my code wasn't matching what Mathematica was giving me. It was close, but not equal. In trying to figure out what was going on, I started looking at minimal examples. Stepping through the MATLAB code for imresize might help, thanks. – GregH Feb 21 '14 at 14:42

imresize gets you different results on Matlab and Octave. The one in Octave calls the interp2 function, which with 'bilinear' method will return you [100 75 50 25 0].
Probably you can edit imresize_old to see more source code content than imresize.