Bilinear interpolation is a more important interpolation method, especially in the field of digital image processing. This blog is divided into three parts: one is the derivation of bilinear interpolation algorithm, the second is the implementation of bilinear interpolation algorithm, the third is the results of the operation of the algorithm.
Derivation of a bilinear interpolation algorithm
Two code implementation (MATLAB)
function [out] = Bilinearinterpolation (IM, out_dims) in_rows = size (im,1);
In_cols = size (im,2);
Out_rows = Out_dims (1);
Out_cols = Out_dims (2);
S_r = in_rows/out_rows;
S_c = In_cols/out_cols;
[CF, RF] = Meshgrid (1:out_cols, 1:out_rows);
RF = RF * S_R;
CF = CF * S_c;
R = floor (RF);
c = floor (CF);
R (r < 1) = 1;
C (c < 1) = 1;
R (R > In_rows-1) = in_rows-1;
C (C > in_cols-1) = in_cols-1;
Delta_r = Rf-r;
Delta_c = cf-c;
In1_ind = Sub2ind ([In_rows, In_cols], R, c);
In2_ind = Sub2ind ([In_rows, In_cols], r+1,c);
In3_ind = Sub2ind ([In_rows, In_cols], R, C+1);
In4_ind = Sub2ind ([In_rows, In_cols], r+1, c+1);
out = Zeros (out_rows, out_cols, size (IM, 3));
out = Cast (out, Class (IM)); For idx = 1:size (IM, 3) chan = Double (Im (:,:, IDX)); %//get i ' th channel%//interpolate the Channel tmp = Chan (in1_ind). * (1-delta_r). * (1-delta_c) + ... chan (in2_ind). * (Delta_r). * (1-delta_c) + ... chan (in3_ind). * (1-del
Ta_r). * (Delta_c) + ... chan (in4_ind). * (Delta_r). * (Delta_c);
Out (:,:, idx) = CAST (TMP, Class (IM));
End
Three-bilinear linear interpolation operation result
>>i = Imread (' lena.jpg ');
>> Figure,imshow (I)
>> S = bilinearinterpolation (i,[1000,1000]);
>> Figure,imshow (S)