imresize(...'bilinear') and interp2(...'linear') return different results

5 views (last 30 days)
x = [0 0 1 1;...
0 0 1 1;...
0 0 0 0;...
0 0 0 0];
imresize(x, [2 2], 'bilinear');
interp2(x, 1.5:2:3.5, (1.5:2:3.5)', 'linear');
I would expect imresize and interp2 to return the same answer above. They do not, however:
>> imresize(x, [2 2], 'bilinear')
ans =
0.1094 0.7656
0.0156 0.1094
>> interp2(x, 1.5:2:3.5, (1.5:2:3.5)', 'linear')
ans =
0 1
0 0
My assumption is that imresize does not adhere to the common definition of bilinear scaling (a linear weighted sum of the immediate 2 neighours in each dimension). Perhaps it is using the (functionally more sensible, but terminology-wise problematic) definition used by ImageMagick, where a triangular function is used as a continouus prototype, meaning that when used for large scale downsampling, more than 4 input samples are used to form one output sample?
https://en.wikipedia.org/wiki/Bilinear_interpolation

Accepted Answer

Rik
Rik on 17 Nov 2020
It is a bit hidden away in the documentation, but it has to do with antialiasing when shrinking an image:
x = [0 0 1 1;...
0 0 1 1;...
0 0 0 0;...
0 0 0 0];
imresize(x, [2 2], 'bilinear')
ans = 2×2
0.1094 0.7656 0.0156 0.1094
imresize(x, [2 2], 'bilinear','Antialiasing',false)
ans = 2×2
0 1 0 0
interp2(x, [1.5 3.5], [1.5 3.5].', 'linear')
ans = 2×2
0 1 0 0

More Answers (0)

Tags

Products


Release

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!