Sunday, June 8, 2008

Assignment 8 Question 3

function [smallimage]=enlarge3(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;

From assignment 7 spectrum.jpg (f=0.75) size(80 149 3)
(f=1.25) size(99 185 3)



(f=0.25) size(26 49 3)

(f=2) size (51 97 3)

(f=0.1) size(9 19 3)

(f=2) size(17 37 3)




From assignment 7 picture1.jpg
(f=0.75) size (112 119 3)

(f=1.25) size (139 147 3)

(f=0.25) size (36 39 3)

(f=2) size (71 77 3)

(f=0.1) size (14 15 3)

(f=2) size( 27 29 3)



From assignment 7 picture2.jpg
(f=0.75) size (116 119 3)



(f=1.25) size(144 147 3)


(f=0.25) size(38 39 3)

(f=2) size (75 77 3)




(f=0.1) size (14 15 3)


(f=2) size (27 29 3)

Assignment 8 Question 2 "Nearest Neighbour"

function [smallimage]=enlarge2(picture,f);
Mp=floor(size(picture,1)*f);
Np=floor(size(picture,2)*f);
smallimage(:,:,1)=zeros(Mp-1,Np-1);
smallimage(:,:,2)=zeros(Mp-1,Np-1);
smallimage(:,:,3)=zeros(Mp-1,Np-1);
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;


Original size(109 200 3)
From Assignment 7 Method 2 (f=0.75)
size ( 80 149 3)



f(1.25)
size(99 198 3)

From Assignment 7 Method 2 (f=0.25)
size (26 49 3)

size(51 97 3)

From Assignment 7 Method 2 (f=0.1)
size (9 19 3)

(f=2)
size( 17 37 3 )

From Assignment 7 Method 2 (f=0.75)

Original size (151 160 3)

size ( 112 119 3)

(f=1.25)
size (139 147 3)


From Assignment 7 Method 2 (f=0.25)size( 36 39 3)

(f=2) size(71 77 3)

From Assignment 7 Method 2 (f=0.1)

size(14 15 3)


(f=2)size( 27 29 3)



Original size(157 160 3)

From Assignment 7 Method 2 picture 2(f=0.75)
size(116 119 3)


(f=1.25) size( 144 147 3)


From Assignment 7 Method 2 picture 2(f=0.25)

size (38 39 3)


(f=2)

size ( 75 77 3)


From Assignment 7 Method 2 picture 2(f=0.1)
size(14 15 3)


(f=2)
size(27 29 3)

Assignment #8 Question 1 a,b,c

Question 1abc:
function [T]=distort(picture,fx,fy);
picture=double(picture);
Mp=floor(size(picture,1)*fx);
Np=floor(size(picture,2)*fy);
T(:,:,1)=zeros(Mp,Np);
T(:,:,2)=zeros(Mp,Np);
T(:,:,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=picture(x+1,y+1,:);
if (x<(i/fx)); ival=ival*(1+x-(i/fx)); end; if (x+1>(i+1)/fx);
ival=ival*(1-(x+1)+((i+1)/fx));
end;
if (y<(j/fy));ival=ival*(1+y-(j/fy)); end; if (y+1>(j+1)/fy);
ival=ival*(1-(y+1)+((j+1)/fy));
end;
T(i+1,j+1,:)=T(i+1,j+1,:)+ival;
end;
end;
T(i+1,j+1,:)=T(i+1,j+1,:)*((fx*fy)^2);
end;
end;
endfunction;

(fx=1, fy=0.5)

(fx=0.5, fy=1)
(fx=0.2, fy=0.8)



Since my first picture was very dark, I decided to use picture2 however, this method since produced very dark images especially when fx=0.2 and fy=0.8.

(fx=1, fy=0.5)

(fx=0.5, fy=1)

(fx=0.2, fy=0.8)

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="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiB7yEo5bCy00LsEN8K9JQkJP3K0azGOwd3GkJm9_k38I0MJ97be_04tL4mT7w4N20hui_xb57SX9-GTsfQatUwgVSL-L0VPZMAVgWvhJBHssR0j0a6dx_deRzXOS1dxeKT5Z2xkoZw_kVR/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;