Matlab imresize with bilinear methods computes different result than bilinear interpolation

Alec Jacobson

May 12, 2016

weblog/

Strangely, it seems that matlab's builtin function imresize does not reproduce the usual bilinear interpolation.

Let's consider a toy 4x4 image:

F = matrixnormalize(magic(4));

input image

BF = imresize(F,[256 256],'bilinear');

imresize bilinear

Compare that to explicitly computing the bilinear interpolation:

[X,Y] = meshgrid(1:size(F,2),1:size(F,1));
[BX,BY] = meshgrid(linspace(1,size(F,2),size(BF,2)),linspace(1,size(F,1),size(BF,1)));
BF2 = interp2(X,Y,F,BX,BY,'bilinear');

imresize bilinear

The difference is obvious in the corners and along the edges. The imresize result has some flat (piecewise constant) patches). Why? It actually looks as if the image was padded by repeated values before upsampling.