Saturday, June 14, 2008

Assignment # 8

1. Modify assignment 7 so that you can scale in the x and y directions by different factors.

function small=scale(largeimage,fx,fy);
mp=floor(size(largeimage,1)*fx);
np=floor(size(largeimage,2)*fy);
small(:,:,1)=zeros(mp,np);
small(:,:,2)=zeros(mp,np);
small(:,:,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;
small(i+1,j+1,:)=small(i+1,j+1,:)+ival;
end;
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)



a) fx=1, fy=.5

















b) fx=.5 fy=1
















c) fx=.2 fy=.8


















2. Enlarge color images that you scaled down in assignment #7 using a factor of 1/f. Use nearest neighbour approximation.

function largeimage=growing(small,f)
mp=size(small,1);
np=size(small,2);
newmp=floor(size(small,1)*f);
newnp=floor(size(small,2)*f);
for i=0:(newmp-1)
for j=0:(newnp-1)
a=round((i/f)+1);
b=round((j/f)+1);
if(a greater 0)&(a less mp)&(b greater 0)&(b less np)
largeimage(i+1,j+1,:)=small(a,b,:);
end
end
end
end
A=imread("Rainbow2.jpg");
B=growing((double(A)/255),(4/3));
imshow(B)




f = 4/3

















f=4/3















f = 4





















f=4





















f = 4
























3. Enlarge images from assignment #7 by 1/f. Use bilinear interpolation.

function largeimage=growing(small,f)
rows=size(small,1);
cols=size(small,2);
mp=floor(size(small,1)*f);
np=floor(size(small,2)*f);
for i=1:(mp-1);
for j=1:(np-1);
a=i/f+1;
b=j/f+1;
r=floor(a);
s=floor(b);
if(r greater 0)&(r less rows)&(s greater 0)&(s less cols)
for k = 1:3;
largeimage(i,j,k)=[1-a+r, a-r]*double([small(r,s,k),small(r,s+1,k);small(r+1,s,k),small(r+1,s+1,k)])*[1-b+s;b-s];
end
end
end
end
endfunction
A=imread("CHALLENGE.jpg");
B=growing((double(A)/255),(4));
imshow(B)

























































































4. Bilinear interpolation seems to be the best at preserving resoltution. I am basing this on the rainbow image only because that image seemed to be preserved quite well under the transformation of shrinking or enlarging.My other two images were dark to begin with so I could not tell with those two images.





5. Start with an original and make a new image.


































No comments: