Bicubic interpolation direct interpolation formula Matlab source code

Can anyone help by sharing the source code of the bicubic image interpolation algorithm using/involving 'direct interpolation formula'? See the figure below?
Also, here's an incomplete (and possibly erroneous) example showing the 'direct interpolation formula' -- V(m',n'):
a = y2-y;
b = x2-x;
d1 = -a*((1-a)^2)*(-b*((1-b)^2))*img(x0,y0); %%(m-1,n-1)
d2 = (1-2*(b^2) + (b^3))*img(x0,y1); %%(m,n-1)
d3 = b*(1+b-(b^2))*img(x0,y2); %%(m+1,n-1)
d4 = -(b^2)*(1-b)*img(x0,y3); %%(m+2,n-1)
d5 = (1-2*(a^2)+(a^3))*(-b*((1-b)^2))*img(x1,y0); %%(m-1,n)
d6 = (1-2*(b^2)+(b^3))*img(x1,y1); %%(m,n)
d7 = b*(1+b-(b^2))*img(x1,y2); %%(m+1,n)
d8 = -(b^2)*(1-b)*img(x1,y3); %%(m+2,n)
d9 = a*(1+a-(a^2))*(-b*((1-b)^2))*img(x2,y0); %%(m-1,n+1)
d10 =(1-2*(b^2)+(b^3))*img(x2,y1); %%(m,n+1)
d11 = b*(1+b-(b^2))*img(x2,y2); %%(m+1,n+1)
d12 = -(b^2)*(1-b)*img(x2,y3); %%(m+2,n+1)
d13 = -(a^2)*(1-a)*(-b*((1-b)^2))*img(x3,y0); %%(m-1,n+2)
d14 =(1-2*(b^2) + (b^3))*img(x3,y1); %%(m,n+2)
d15 = b*(1+b-(b^2))*img(x3,y2); %%(m+1,n+2)
d16 = -(b^2)*(1-b)*img(x3,y3); %%(m+2,n+2)
V(m',n') = (d1 + d2 + d3 + d4 + d5 + d6 + d7 + d8 + d9 + d10 + d11 + d12 + d13 + d14 + d15 + d16);
PS: I don't want the source code shown here: https://thilinasameera.wordpress.com/2010/12/24/digital-image-zooming-sample-codes-on-matlab/. Also, I don't want to use 'interp2' or any other shortcut.

8 comentarios

Stephen23
Stephen23 el 15 de Jun. de 2018
Editada: Stephen23 el 15 de Jun. de 2018
"Also, I don't want to use 'interp2' or any other shortcut."
Inbuilt functions are not "shortcuts", they are just well tested versions of algorithms. A general rule in programming is to not write code that has already been written, so what is your need to avoid using interp2 ?
The better we can understand exactly what you are trying to achieve, the better the advice you will get.
Gobert
Gobert el 15 de Jun. de 2018
Editada: Gobert el 15 de Jun. de 2018
I SIMPLY want a 'bicubic image interpolation algorithm' source code that works as requested above. If you can help, please do! Thank you!
Can anyone help with the bicubic image interpolation by making all steps as clear as the following bilinear image interpolation code?
function [Y] = bilinear_code(I, ratio)
[h, w] = size(I);
H = (ratio * h);
W = (ratio * w);
Y = zeros(H,W);
hs = (h/H);
ws = (w/W);
for i=1:H
y = (hs * i) + (0.5 * (1 - 1/ratio));
for j=1:W
x = (ws * j) + (0.5 * (1 - 1/ratio));
%// Any values out of acceptable range
x(x < 1) = 1;
x(x > h - 0.001) = h - 0.001;
x1 = floor(x);
x2 = x1 + 1;
y(y < 1) = 1;
y(y > w - 0.001) = w - 0.001;
y1 = floor(y);
y2 = y1 + 1;
%// 4 Neighboring Pixels
NP1 = I(y1,x1);
NP2 = I(y1,x2);
NP3 = I(y2,x1);
NP4 = I(y2,x2);
%// 4 Pixels Weights
PW1 = (y2-y)*(x2-x);
PW2 = (y2-y)*(x-x1);
PW3 = (x2-x)*(y-y1);
PW4 = (y-y1)*(x-x1);
Y(i,j) = PW1 * NP1 + PW2 * NP2 + PW3 * NP3 + PW4 * NP4;
end
end
end
Robert Sir, Have you corrected the bicubic code sir, if you corrected can you send the corrected code.
Shubha B.
Shubha B. el 19 de Feb. de 2021
Editada: Shubha B. el 19 de Feb. de 2021
send the completed Bicubic code
The same question can be asked to you: why do you want to avoid interp2?
To understand the theory concept correctly. For above written code I am not getting the theory for that.
If your main point is understanding the theory, does the exact implementation matter?

Iniciar sesión para comentar.

Respuestas (1)

Why not just use interp2? The help for the 'cubic' method states:
'cubic' - bicubic interpolation as long as the data is
uniformly spaced, otherwise the same as 'spline'
If you're not allowed to use interp2 because this is homework, tell us what's blocking you from completing the implementation and we may be able to offer guidance.

1 comentario

I didn't want to use 'interp2' or any other short-cut. What is intriguing to me is simply the 'geometric transformation' that will enable accessing (x0, y0), etc., at the edges of an image, without generating errors (even if it requires padding that image, first).

Iniciar sesión para comentar.

Categorías

Más información sobre Interpolation en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 15 de Jun. de 2018

Comentada:

Rik
el 23 de Feb. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by