3
$\begingroup$

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.

$\endgroup$
4
  • $\begingroup$ It might help to clean up some of the acronyms that you have, and to post a self-contained MATLAB example. $\endgroup$
    – Jason R
    Commented Feb 21, 2014 at 12:22
  • $\begingroup$ @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. $\endgroup$
    – GregH
    Commented Feb 21, 2014 at 13:22
  • 1
    $\begingroup$ 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. $\endgroup$
    – Jason R
    Commented Feb 21, 2014 at 13:24
  • $\begingroup$ @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. $\endgroup$
    – GregH
    Commented Feb 21, 2014 at 14:42

2 Answers 2

2
$\begingroup$

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].

However, it seems like there is some extra processing in Matlab. It performs affine transformation on the image. The interpolation is calculated on each pixel in the output image, then inverse map onto the indices of the pixels in the input image with the contributing weights. So I guess the mapped coordinates are not distributed uniformly (not exactly at 1.5 and 2.5 between [1,2], and [2,3] in your case).

Probably you can edit imresize_old to see more source code content than imresize.

$\endgroup$
1
$\begingroup$

A good answer is posted at https://mathematica.stackexchange.com/questions/42825/understanding-bilinear-imageresize/42842?noredirect=1#42842, the Mathematica StackExchange site.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.