# Theory of Bicubic interpolation

82 views (last 30 days)
Shubha B. on 23 Feb 2021
Commented: Shubha B. on 25 Feb 2021
For the bicubic code which is given in the this link https://www.mathworks.com/matlabcentral/answers/405846-bicubic-interpolation-direct-interpolation-formula-matlab-source-code, where can I get the expalnation of this code. The explanation which is given in the link https://en.wikipedia.org/wiki/Bicubic_interpolation
is not matching.
KALYAN ACHARJYA on 23 Feb 2021

Bruno Luong on 24 Feb 2021
Edited: Bruno Luong on 24 Feb 2021
In 2D you do in one direction followedred by another.
%%
x = [-1:2];
y = [-1:2];
[X,Y] = meshgrid(x,y);
xq = rand;
yq = rand;
Z = rand(size(X));
Zq = interp2(x,y,Z,xq,yq,'bicubic')
% Check bicubic formula
Pl = [1.5,-2.5,0,1];
Pr = [-0.5,2.5,-4,2];
cubicp = @(x) (x<=1).*polyval(Pl,x) + (x>1 & x<2).*polyval(Pr,x);
cubic = @(x) cubicp(abs(x));
Zq = 0;
[~,i0] = histc(xq,x);
[~,j0] = histc(yq,y);
for i = i0-1:i0+2
for j = j0-1:j0+2
k = sub2ind(size(Z),j,i);
Zq = Zq + cubic(X(k)-xq)*cubic(Y(k)-yq)*Z(k);
end
end
Zq
Shubha B. on 25 Feb 2021
thank you sir.

### Community Treasure Hunt

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

Start Hunting!

Translated by