I mainly referred to it here, but I felt that there was a problem with the coefficient he deduced. Using his formula to apply the enlarged image directly would have a grid, maybe it was a deviation I understood.
So I re-deduced the four coefficients.
This is okay. His code is of great reference value.
Program code:
Main. m
Clear all; close all; clc; W = 2; % zoom in or out width H = 2; fill in or zoom in height img1_imread('lena.jpg '); % imshow (IMG ); [m n] = size (IMG); imgn = zeros (H * m, w * n); rot = [H 0 0; 0 w 0; 0 0 1]; % transformation matrix X = H * u, y = W * vfor I = 1: H * m for j = 1: W * n pix = [I J 1]/rot; float_y = pix (1)-floor (pix (1); float_x = pix (2)-floor (pix (2); If pix (1) <2% border processing, you can also use the border extension commonly used in Convolution to prevent out-of-bounds pix (1) = 2; end if pix (1)> m-2 pix (1) = m-2; end if pix (2) <2 pix (2) = 2; end if pix (2)> N-2 pix (2) = n-2; end pix_up = floor (pix (1 )); pix_left = floor (pix (2); P = IMG (pix_up-1: pix_up + 2, pix_left-1: pix_left + 2); imgn (I, j) = bicubicinterpolate (p, float_x + 1, float_y + 1); endendfigure, imshow (uint8 (imgn ))
Bicubicinterpolate. m
Function Re = bicubicinterpolate (p, x, y) % first interpolation, then column interpolation arr = zeros (); for I = Arr (I) = cubicinterpolate (P (I, 1: 4), x); End Re = cubicinterpolate (ARR, Y); End
Cubicinterpolate. m
function re=cubicInterpolate(p,x) p=double(p);% re=p(2) + 0.5 * x*(p(3) - p(1) + x*(2.0*p(1) - 5.0*p(2) + 4.0*p(3) - p(4) + x*(3.0*(p(2) - p(3)) + p(4) - p(1)))); a=(p(4)-3*p(1)+3*p(2)-p(1))/10; b=(p(3)-2*p(2)+p(1))/2-2*a; c=p(2)-p(1)-a-b; d=p(1); re=a*x^3+b*x^2+c*x+d;end
:
Source image
Dual-cube interpolation effect
Bilinear interpolation effect
The difference is not big, but it is better to take it seriously.