Saturday, June 14, 2008

Assignment # 7 - part two (finished)

Images using method 1
















images using method 3
















Method 1- average over all pixels in the destination point:

Code:

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

F=imread('raimbowfb.jpg');
image(decrease1(F,.75))

F=imread('raimbowfb.jpg');
image(decrease1(F,.25))

F=imread('raimbowfb.jpg');
image(decrease1(F,.1))

A=imread('bittersweet.jpg');
image(decrease1(A,.75))
>> A=imread('bittersweet.jpg');
image(decrease1(A,.25))
>> A=imread('bittersweet.jpg');
image(decrease1(A,.1)




F=imread('toyboy.jpg');
image(decrease1(F,.1))
>> F=imread('toyboy.jpg');
image(decrease1(F,.25))

For an image toyboy shrunk by a factor of.75, I had to change a second line of the code of the function:
function [B]=decrease1(A,f)
A=double(A)/256;

F=imread('toyboy.jpg');
image(decrease1(F,.75))


Method # 3
Bilinear interpolation of the larger image

Code:

function[B]=decrease3(A,f)
A=double(A)/255
p=floor(size(A,1)*f);
q=floor(size(A,2)*f);
for i=0:p-1
for j=0:q-1
c=i/f;
d=j/f;
r=floor(c);
s=floor(d);
if(r>0)&(r<256)&(s>0)&(s&lgt256)
for k=1:3
B(i,j,k)=[1-c+r,c-r]*[A(r,s,k),A(r,s+1,k);
A(r+1,s,k),A(r+1,s+1,k)]*[1-d+s;d-s];
end
end
end
end



A=imread('rainbowfb.jpg'
image(decrease3(A,.75))
image(decrease3(A,.25))
image(decrease3(A,.1))


A=imread('bittersweet.jpg');
image(decrease3(A,.75))
image(decrease3(A,.25))
image(decrease3(A,.1))

A=imread('toyboy.jpg');
image(decrease3(A,.75))
image(decrease3(A,.25))
image(decrease3(A,.1))

Pictures obtained using method 3- bilinear interpolation seem to be the most clear.

No comments: