Wednesday, June 11, 2008

Assignment #8

Question #1
Code for shrinking x and y by different factors(average over all pixels in the destination point)

function [B]=decrease4(A,f1,f2)
A=double(A)/255;
p=floor(size(A,1)*f1);
q=floor(size(A,2)*f2);
for i=1:3 B(:,:,i)=zeros(p,q);
end
for i=0:p-1
for j=0:q-1
for x=floor(i/f1):ceil((i+1)/f1)-1
for y=floor(j/f2):ceil((j+1)/f2)-1
ival=A(x+1,y+1,:);
if (x<i/f1) ival=ival*(1+x-i/f1);
end
if(x+1>(i+1)/f1) ival=ival*(1-(x+1)+(i+1)/f1);
end
if(y<j/f2) ival=ival*(1+y-j/f2);
end
if (y+1>(j+1)/f2) ival =ival*(1-(y+1)+(j+1)/f2);
end
B(i+1,j+1,:)=B(i+1,j+1,:)+ival;
end
end
B(i+1,j+1,:)=B(i+1,j+1,:)/(1/f1)/(1/f2);
end
end

A=imread('bittersweet.jpg');
>> image(decrease4(A,1,.5))

a) f1=1, f2=.5



















b)f1=.5, f2=1





















c) f1=.2 f2=.8




No comments: