|
a |
|
b/bilinear.m |
|
|
1 |
function [im_zoom] = bilinear( array_recon ) |
|
|
2 |
%bilinear interpolation of an image is done here |
|
|
3 |
a=array_recon; |
|
|
4 |
factor=1; %zooming factor |
|
|
5 |
|
|
|
6 |
[m n d] = size(a); %2 dimentional array values |
|
|
7 |
rows=factor*m; |
|
|
8 |
columns=factor*n; |
|
|
9 |
|
|
|
10 |
for i=1:rows |
|
|
11 |
x=i/factor; |
|
|
12 |
x1=floor(x); %bilinear in X direction |
|
|
13 |
x2=ceil(x); |
|
|
14 |
if x1==0 |
|
|
15 |
x1=1; |
|
|
16 |
end |
|
|
17 |
xrem=rem(x,1); |
|
|
18 |
for j=1:columns |
|
|
19 |
y=j/factor; |
|
|
20 |
|
|
|
21 |
y1=floor(y); %bilinear in Y direction |
|
|
22 |
y2=ceil(y); |
|
|
23 |
if y1==0 |
|
|
24 |
y1=1; |
|
|
25 |
end |
|
|
26 |
yrem=rem(y,1); |
|
|
27 |
|
|
|
28 |
BottomLeft=a(x1,y1,:); |
|
|
29 |
TopLeft=a(x1,y2,:); |
|
|
30 |
BottomRight=a(x2,y1,:); |
|
|
31 |
TopRight=a(x2,y2,:); |
|
|
32 |
|
|
|
33 |
R1=BottomRight*yrem+BottomLeft*(1-yrem); |
|
|
34 |
R2=TopRight*yrem+TopLeft*(1-yrem); |
|
|
35 |
|
|
|
36 |
im_zoom(i,j)=R1*xrem+R2*(1-xrem); |
|
|
37 |
end |
|
|
38 |
end |
|
|
39 |
%size(im_zoom) |
|
|
40 |
%size(imagebig) |
|
|
41 |
%ssd=sum(sum(sum((imagebig-im_zoom).*(imagebig-im_zoom)))) |
|
|
42 |
%imwrite(im_zoom,'bilinear zoom.png'); |
|
|
43 |
%imshow(im_zoom); |
|
|
44 |
|
|
|
45 |
end |
|
|
46 |
|