Tuesday, May 27, 2008

Assignment 5

Assignment 5

1. Find octave commands for constructing a 256x256 matrix with entries of 0 everywhere except inside the circle with radius 50 where the values are 1.

A=zeros(256);
for x=1:256;for y=1:256;
if (x-128)^2+(y-128)^2<=2500;
A(x,y)=1;
endif;
endfor;
endfor;
Imshow(A*256)









2. Give octave commands to draw the top part of figure 6.4 in the book.

A=zeros(256);
B=zeros(256);
C=zeros(256);
for x=1:256;for y=1:256;
if (x-93)^2+(y-128)^2<=2500;
A(x,y)=1;
endif;
if (x-153)^2+(y-93)^2<=2500;
B(x,y)=1;
endif;
if (x-153)^2+(y-153)^2<=2500;
C(x,y)=1;
endif;
endfor;
endfor;
E(:,:,1)=A*255;
E(:,:,2)=B*255;
E(:,:,3)=C*255;
imshow (E)



3. Consider the black and white image from the matrix. Skew the image by a factor of s pixels. Rotate the image theta degrees

bigT=255*ones(256);
bigT(30:79,64:191)=zeros(50,128);
bigT(50:199,111:146)=zeros(150,36);

BIG T










bigT=255*ones(256);
bigT(30:79,64:191)=zeros(50,128);
bigT(50:199,111:146)=zeros(150,36);
function retval=newy(x,y,s)
retval=y+mod(x*s,256)+1;
endfunction
for x=1:256;
for y=1:256;
y1=int32(newy(x,y,1));
if(y1>256)
y1=y1-256;
endif;
bigT1(x,y1)=bigT(x,y);
endfor;
endfor;
imshow(bigT1)



Skew by a factor of 0.9 and 1














Rotation of 5pi/3

bigT=255*ones(256);
bigT(30:79,64:191)=zeros(50,128);
bigT(50:199,111:146)=zeros(150,36);
bigT2=ones(256);
for x=1:256;
for y=1:256;
xnew=int32(mod(x*cos(5*pi/3)-y*sin(5*pi/3),256)+1);
ynew=int32(mod(x*cos(5*pi/3)+y*sin(5*pi/3),256)+1);
bigT2(xnew,ynew)=bigT(x,y);
endfor
endfor; imshow(bigT2)

1 comment:

Mike Zabrocki said...

I was expecting some pockmarks on your rotated images. Any idea why you aren't getting those?
Your code seems as though it would produce them.