Derivation of bilinear interpolation algorithm and code realization _ bilinear interpolation

Source: Internet
Author: User

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)


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.