Sunday, June 22, 2008

Assign 8 Q1

1. Modify assignment 7 problem #1 so that you can scale in
the x and y directions by different factors.Scale one of the
two pictures that you downloaded from the web
(whichever looks better) by
(a) fx = 1.0 , fy = 0.5
(b) fx = 0.5, fy = 1.0
(c) fx = 0.2, fy = 0.8

function small=scale(largeimage,fx,fy);
Mp=floor(size(largeimage,1)*fx);
Np=floor(size(largeimage,2)*fy);
smallimage(:,:,1)=zeros(Mp,Np);
smallimage(:,:,2)=zeros(Mp,Np);
smallimage(:,:,3)=zeros(Mp,Np);
for i=0:(Mp-1);
for j=0:(Np-1);
for x=floor(i/fx):ceil((i+1)/fx)-1;
for y=floor(j/fy):ceil((j+1)/fy)-1;
ival=largeimage(x+1,y+1,:)
ival=double(ival);
if (x less i/fx)
ival=ival*(1-i/fx+x)
end;
if (x+1 greater (i+1)/fx)
ival=ival*(1-(i+1)/fx+x+1);
end;
if(y less i/fy)
ival=ival*(1-j/fy+y);
end;
if (y+1 greater (j+1)/fy)
ival=ival*(1-(j+1)/fy+y+1);
end;
smallimage(i+1,j+1,:)=smallimage(i+1,j+1,:)+ival;
end;
small(i+1,j+1,:)=small(i+1,j+1,:)/((1/fx)*(1/fy));
end;
end;
endfunction
A=imread("CokeCan.jpg");
B=scale((double(A)/255),1,.5);
imshow(B)

No comments: