bilinear interpolation for image amplification (MATLAB implementation)

Source: Internet
Author: User
bilinear interpolation for Image amplification first, the algorithm pseudo-code


Second, the realization

1. Experimental platform and data

This algorithm uses MATLAB language implementation, the experimental platform for Windows 8 32-bit operating system, 4GB memory (usable as 2.31GB), matlab2013b.


Data 1: size: 256*256 of the Lena grayscale image, the implementation of the algorithm will be twice times the amplification operation, as shown in Figure 1:


Figure 1 Grayscale image Lena.png

Data 2: color RGB image of size: 670*502, it will be twice times smaller using the algorithm implemented, as shown in Figure 1 below:

Figure 2 color RGB image he.jpeg 2. Experimental program source code

IMBLIZOOM.M File Source

function [ZI] = Imblizoom (I,ZMF)

%----------------------bilinear interpolation to scale matrices or images---------------------------

% Input:

% I: Image file name or matrix (integer value (0~255))

% ZMF: Zoom factor, which is the multiple of scale

% Output:

% scaled image matrix ZI

% Usage:

% ZI = sselmhsic (' Imagefilename ', ZMF)

% ZMF Zoom to image I and display

% Or:

% ZI = Sselmhsic (I,ZMF)

% ZMF to the matrix I zoom and display

%    ...

%-------------------------------------------------------------------

%%%% Authors:zhi Liu

%%%% Xidian University Student

%%%% email:zhiliu.mind@gmail.com

%%%% date:16-12-2013

Percent STEP1 preprocessing of data

If ~exist (' I ', ' var ') | | IsEmpty (I)

Error (' Input image i ' is undefined or empty. ');

End

If ~exist (' zmf ', ' var ') | | IsEmpty (ZMF) | | Numel (ZMF) ~= 1

The error (' displacement vector zmf ' is undefined or is empty or the element in ZMF exceeds 2. ');

End

If Isstr (I)

[I,m] = Imread (I);

End

If ZMF <= 0

The error (' Zoom multiplier ZMF value should be greater than 0. ');

End

Percent STEP2 the size of the new image with the original image and scaling factor, and creates a new image.

[Ih,iw,id] = size (I);

Zih = round (IH*ZMF); % calculates the scaled image height, the most recent rounding

ZIW = round (IW*ZMF); % calculates the scaled image width, the most recent rounding

ZI = zeros (zih,ziw,id); % Create New image

Percent Step3 extension Matrix I edge

IT = zeros (ih+2,iw+2,id);

IT (2:ih+1,2:iw+1,:) = I;

It (1,2:iw+1,:) =i (1,:,:); IT (ih+2,2:iw+1,:) =i (IH,:,:);

It (2:ih+1,1,:) =i (:, 1,:); IT (2:ih+1,iw+2,:) =i (:, IW,:);

It (:) = i (:); it (1,iw+2,:) = I (1,iw,:);

It (ih+2,1,:) = I (ih,1,:); IT (ih+2,iw+2,:) = I (ih,iw,:);

The percent STEP4 is mapped to the original image (II,JJ) by a pixel (ZI,ZJ) of the new image and interpolated.

For ZJ = 1:ziw% on-column image-by-element scanning

For Zi = 1:zih

II = (zi-1)/ZMF; JJ = (zj-1)/ZMF;

i = floor (ii); j = Floor (JJ); % rounding Down

u = ii-i; v = jj-j;

i = i + 1; j = j + 1;

ZI (zi,zj,:) = (1-u) * (1-v) *it (i,j,:) + (1-u) *v*it (i,j+1,:) ...

+ u* (1-v) *it (i+1,j,:) +u*v*it (i+1,j+1,:);

End

End

ZI = Uint8 (ZI);

Percent% display the same-present matrix p as an image

Figure

Imshow (I,M);

Axis on

Title ([' Original image (Size: ', Num2str (IH), ' * ', num2str (IW), ' * ', num2str (ID), ') ');

Figure

Imshow (ZI,M);

Axis on

Title ([' Scaled Image (size: ', Num2str (Zih), ' * ', num2str (ZIW), ' * ', num2str (ID) ', ') ');

End 3. Experimental results 1) Data 1

Enter Imblizoom (' Lena.png ', 2) in the Command window, and the result is as follows in Figure 3 and figure 4 below:


Figure 3 Operation result of Lena.png 1 (original)


Fig. 4 operation result of Lena.png 2 (figure enlarged twice times) 2) Data 2


Figure 5 He.jpeg Run result 1 (original)


Figure 6 He.jpeg Run result 2 (image zoomed out twice times)

Figure 3~ Figure 6 shows that the program is correct and the effect is very good after zooming in and out. For application and other functions, please review the code comments.

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.