Thursday, June 5, 2008

Assignment #7

Well, I'm so excited! I finally got all the functions to work. I have not been able to call them into Octave, but I can copy and paste now! Here are the Octave codes. I am not redoing this assignment with the functions since I have done the assignment already the long way.

Method 1:
function [smallimage]=shrink1(picture,f)
Mp=floor(size(picture,1)*f);
Np=floor(size(picture,2)*f);
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/f):ceil((i+1)/f)-1;
for y=floor(j/f):ceil((j+1)/f)-1;ival=picture(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;
smallimage(i+1,j+1,:)=smallimage(i+1,j+1,:)+ival;
end;
end;
smallimage(i+1,j+1,:)=smallimage(i+1,j+1,:)*(f^2);
end;
end;
endfunction;
Octave commands to display images:
A=imread('picturename.jpg');
B=shrink1(A,f); #where f represents the percent of shrinkage
imshow(double(B)/255);

Method 2:
function [smallimage]=shrink2(picture,f);
Mp=floor(size(picture,1)*f);
Np=floor(size(picture,2)*f);
smallimage(:,:,1)=zeros(Mp,Np);
smallimage(:,:,2)=zeros(Mp,Np);
smallimage(:,:,3)=zeros(Mp,Np);
for i=1:(Mp-1);
for j=1:(Np-1);
a=round(i/f);
b=round(j/f);
smallimage(i,j,:)=picture(a,b,:);
end;
end;
endfunction;
Octave commands to display images:
A=imread('picturename.jpg');
B=shrink2(A,f); #where f represents the percent of shrinkage
imshow(double(B)/255);

Method 3:
function [smallimage]=shrink3(picture,f);
picture=double(picture);
Mp=floor(size(picture,1)*f);
Np=floor(size(picture,2)*f);
for i=0:(Mp-1);
for j=0:(Np-1);
a=i/f;
b=j/f;
r=floor(a);
s=floor(b);
if (r>0) & (r<256)>0) & (s<256); for k=1:3; smallimage(i,j,k)=[1-a+r,a-r]*[picture(r,s,k),picture(r,s+1,k); picture(r+1,s,k), picture(r+1,s+1,k)]*[1-b+s; b-s];
end;
end;
end;
end;
endfunction;
Octave commands to display images:
A=imread('picturename.jpg');
B=shrink3(A,f); #where f represents the percent of shrinkage
imshow(double(B)/255);

Question #1

Average over all Pixels in the Destination Point

Method 1: Spectrum
largeimage=double(imread("spectrum.jpg"));
f=0.75;
Mp=floor(size(largeimage,1)*f);
Np=floor(size(largeimage,2)*f);
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/f):ceil((i+1)/f)-1;
for y=floor(j/f):ceil((j+1)/f)-1;
ival=largeimage(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;
smallimage(i+1,j+1,:)=smallimage(i+1,j+1,:)+ival;
end;
end;
end;
end;
smallimage=smallimage*f^2;
imshow(double(smallimage)/255);

f=0.75;


f=0.25;


f=0.1



Method 1:Picture1
largeimage=double(imread("picture1.jpg"));
f=0.75; (continue by following the commands Under Method 1 above)

f=0.75;




f=0.25;



f=0.1;


Method 1:Picture2
largeimage=double(imread("picture2.jpg"));
f=0.75; (continue by following the commands Under Method 1 above)

f=0.75;



f=0.25;


f=0.1;


Take the Nearest Neighbour

Method 2:Spectrum
largeimage=imread("spectrum.jpg");
f=0.75;
Mp=floor(size(largeimage,1)*f);
Np=floor(size(largeimage,2)*f);
smallimage(:,:,1)=zeros(Mp,Np);
smallimage(:,:,2)=zeros(Mp,Np);
smallimage(:,:,3)=zeros(Mp,Np);
for i=1:Mp;
for j=1:Np;
a=round(i/f);
b=round(j/f);
smallimage(i,j,:)=largeimage(a,b,:);
end;
end;
imshow(double(smallimage)/255);


f=0.75;


f=0.25;

f=0.1;

Method 2: Picture1

largeimage=double(imread("picture1.jpg"));
f=0.75; (continue by following the commands Under Method 2 above)

f=0.75;

f=0.25;

f=0.1;



Method 2: Picture2
largeimage=double(imread("picture2.jpg"));

f=0.75; (continue by following the commands Under Method 2 above)

f=0.75;


f=0.25;


f=0.1;



Take a Bilinear Interpolation of the Larger Image

Method 3: Spectrum
largeimage=double(imread("spectrum.jpg"));
f=0.75;
Mp=floor(size(largeimage,1)*f);
Np=floor(size(largeimage,2)*f);
for i=0:Mp-1;
for j=0:Np-1;
a=i/f;
b=j/f;
r=floor(a);
s=floor(b);
if (r>0) & (r<256)>0) & (s<256); k="1:3;" f="0.75;" href="http://bp3.blogger.com/_fF9V0SbP11I/SEnp18hhf8I/AAAAAAAAAQk/4wlaBPzco9Y/s1600-h/Ass+7+Spectrum+Method+3+F%3D0.75.JPG">
f=0.25;

f=0.1;


Method 3: Picture1
largeimage=double(imread("picture1.jpg")); f=0.75; (continue by following the commands Under Method 3 above)

f=0.75;

f=0.25;




f=0.1;


Method 3: Picture2
largeimage=double(imread("picture2.jpg")); f=0.75; (continue by following the commands Under Method 3 above)

f=0.75;

f=0.25;

f=0.1;


No comments: