2
I’m trying to implement the bicubic interpolation algorithm but I’m having a lot of difficulty with the correct interpolated values( is not related to taking the values of the original matrix but rather the relationship of the distance weights).
Following the idea of this boy here (this case is for bilinear interpolation but helps to understand the idea of weights) : https://stackoverflow.com/questions/16341167/bilinear-interpolation
In this case, the weights for a factor 2 magnification image would be : 0 0.5 1
( here would change to next pixel of the original image).
But in a bicubic interpolation 16 pixels are used as shown in the following image :
What creates type one " masks 4x4 " of the original pixels, ie only change the index when x or y pass 3. I made a logic for this index and it works but my doubt is related to dx and to dy because they will have to go from 0 to 3 ( because it is the horizontal and vertical distance ) weighted between 0 and 1 right ? that is, for a magnification of factor 2 they will have to go from 0 0.5 1 1.5 2 2.5 3
( weighted would be 0 0.1666 0.25 0.5 0.666 0.83 1
) ?
I’m doing with these weights and playing in the polynomial, which can be seen here : http://www.paulinternet.nl/? page=Bicubic
But the values are very much to whom the desired ( although it is taking the right pixels and doing the right algorithm).
Is this the idea of the manipulation of weighted weights ? Or is it incorrect ?
If you can explain this algorithm in a more exemplified way to see if I’m thinking the right way I would appreciate it.
EDITED :
For example, consider the following matrix :
If we were to increase it in order 2 would be with their respective weights would be something like :
If we do
P= Cubo(pixel[index],pixel[index+1],pixel[index+2],pixel[index+3],dx);
Q= Cubo(pixel[index+4],pixel[index+5],pixel[index+6],pixel[index+7],dx);
R= Cubo(pixel[index+8],pixel[index+9],pixel[index+10],pixel[index+11],dx);
S= Cubo(pixel[index+12],pixel[index+13],pixel[index+14],pixel[index+15],dx);
matriz[i][j] =Cubo(P,Q,R,S,dy);
where the cube would be this function :
Cubo(double[] p, double x) {
return p[1] + 0.5 * x*(p[2] - p[0] + x*(2.0*p[0] - 5.0*p[1] + 4.0*p[2] - p[3] + x*(3.0*(p[1] - p[2]) + p[3] - p[0])));
}
If we do this for the value of row 0 and column 1 ( dx = 0.1666 and dy=0) it will generate { 5.04 ,1.98, 1.69, 3.02}
and the result of that matriz[i][j] =Cubo(5.04 ,1.98, 1.69, 3.02, dy)
will be 1.98
while should give something between 8 e 5
.
Does anyone know what’s going wrong ?
Mark the question the tag in which language this is being done.
– Sam