Saturday, May 31, 2008

Assignment #6

1. Use bilinear interpolation on the skewed and rotated image from Assignment 5.

bigT=255.0*ones(256);
bigT(30:79,64:191)=zeros(50,128);
bigT(50:199,111:146)=zeros(150,36);
newmatrix=255*ones(256);
for x=1:256; for y=1:256;
u=x*cos(5*pi/6)+y*sin(5*pi/6);
v=-x*sin(5*pi/6)+y*cos(5*pi/6);
a=u;
b=mod((v-2*u),256)+1;
r=floor(a);
s=floor(b);
if ((r>0) & (r<256)>0) & (s<256));
newmatrix(x,y)=[1-a+r, a-r]*[bigT(r,s),bigT(r,s+1); bigT(r+1,s),bigT(r+1,s+1)]*[1-b+s;b-s];
end; end; end; imshow(newmatrix)


2. Create a 256 x 256 matrix with 1's in the i,i+1 positions.

A=tril(ones(256),1);
B=tril(ones(256),0);
A-B


3. Determine the average colour:

a) F(:,:,1)=ones(100);
F(:,:,2)=tril(ones(100));
F(:,:,3)=zeros(100);

size(F)
ans=
100 100 3

aveF=sum(sum(M))/100/100
aveF=
ans(:,:,1)=1
ans(:,:,2)=0.50500
ans(:,:,3)=0

A(:,:,1)=1;
A(:,:,2)=0.505;
A(:,:,3)=0;



b) Using the rainbow picture from Assignment 4:

A=zeros(256);
B=ones(256);
C=[ones(256,1)*[255:-1:0]/255];
D=[ones(256,1)*[0:1:255]/255];

R(:,:,1)=B;
R(:,:,2)=D;
R(:,:,3)=A;

Y(:,:,1)=C;
Y(:,:,2)=B;
Y(:,:,3)=A;

G(:,:,1)=A;
G(:,:,2)=B;
G(:,:,3)=D;

Cy(:,:,1)=A;
Cy(:,:,2)=C;
Cy(:,:,3)=B;

Bl(:,:,1)=D;
Bl(:,:,2)=A;
Bl(:,:,3)=B;

Ma(:,:,1)=B;
Ma(:,:,2)=A;
Ma(:,:,3)=C;

RB=[R,Y,G,Cy,Bl,Ma];

size(RB)
ans:
256 1536 3
aveRB=sum(sum(RB))/256/1536
aveRB=
ans(:,:,1)=0.50000
ans(:,:,2)=0.50000
ans(:,:,3)=0.50000




b) I am still trying to get images into Octave...

No comments: