-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBi-Linear-Interpolation.m
66 lines (50 loc) · 1.29 KB
/
Bi-Linear-Interpolation.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
%%
clear;
im1=imread('lena.bmp');
im=im2double(im1);
imshow(im);
figure(1);
%Get orginal Image Size
xScale=2;
yScale=1;
[OrginaSizeY,OrginalSizeX]=size(im);
NewSizeY=floor(yScale*OrginaSizeY);
NewSizeX=floor(xScale*OrginalSizeX);
%Vreate new matrix of given size to keep grayscale info
NewImg=double(zeros(NewSizeY,NewSizeX));
%Find weighted average of 4 serounding pixle (Weight depends on distance from calucalted pixel) and save its value to new map
for x=(0:NewSizeX-1)
for y=(0:NewSizeY-1)
%Find top left pixel
Ax=floor(x/xScale);
Ay=floor(y/yScale);
%Handle borders
if(Ax==0)
Ax=1;
end
if(Ay==0)
Ay=1;
end
%Calculate postion of remaining 3 pixles
Bx=Ax+1;
By=Ay;
Cx=Ax+1;
Cy=Ay+1;
Dy=Ay+1;
Dx=Ax;
%Calcualte propotion of distance between calualted pixel and
%horizontal and vertiacla surrounding pixels
i=x/xScale-Ax;
j=y/yScale-Ay;
%Save value of surounding pixels
A=im(Ay,Ax);
B=im(By,Bx);
C=im(Cy,Cx);
D=im(Dy,Dx);
%Calculate weighted average
NewImg(y+1,x+1)=[1-i i]*[A D;B C]*[1-j;j];
end
end
figure(2);
%Show scaled img
imshow((NewImg));