imresize(...'bilinear') and interp2(...'linear') return different results
5 views (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
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')
imresize(x, [2 2], 'bilinear','Antialiasing',false)
interp2(x, [1.5 3.5], [1.5 3.5].', 'linear')
0 Comments
More Answers (0)
See Also
Categories
Find more on Splines in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!