Saturday, May 24, 2008

Assignment #5



1. Here are the commands that create a white circle in a black square:

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;
imshow(A*255)





2. To get the three circles, in colour:


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. bigT=255.0*ones(256);
bigT(30:79,64:191)=zeros(50,128);
bigT(50:199,111:146)=zeros(150,36);
imshow(bigT)


bigT1=255*ones(256);
function retval=newy(x,y,s)
retval=y+mod(x*s,256)+1;
endfunction

for x=1:256;
f or y=1:256;
y1=int32(newy(x,y,2));

if(y1>256)
y1=y1-256;
end;

bigT1(x,y1)=bigT(x,y);
endfor;
endfor;




bigT2=ones(256);
for x=1:256;
for y=1:256;

newx=int32(mod(x*cos(5*pi/6)-y*sin(5*pi/6),256)+1);
newy=int32(mod(x*sin(5*pi/6)+y*cos(5*pi/6),256)+1);

bigT2(newx,newy)=bigT1(x,y);

end;
end;










There's still something not quite right, but it's late and I keep making the same mistakes...like Arnold, I'll be back.


Another look at #3. I have deleted 3.0.0 and am using 3.0.1 again. After trying out several versions of the code posted by classmates, I have a somewhat different set of images. Here goes:

The original BigT:

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

The resized (*2) bigT1

for x=1:256;
for y=1:256;
y1=mod(2*x+y,256)+1;
bigT1(x,y)=bigT(x,y1);
end;
end;




The rotated bigT:

f or x=1:256;
for y=1:256;
x2=x*cos(5*pi/6)-y*sin(5*pi/6);
y2=x*sin(5*pi/6)+y*cos(5*pi/6);
x3=round(x2);
y3=round(y2);
bigT2(mod(x3,256)+1,mod(y3,256)+1)=bigT(x,y);
end;
end;


The resized and rotated bigT:

bigT=255*ones(256);
bigT(30:79,64:191)=zeros(50,128);
bigT(50:199,111:146)=zeros(150,36);
for x=1:256;
for y=1:256;
y1=mod(2*x+y,256)+1;
bigT1(x,y)=bigT(x,y1);
end;
end;

for x=1:256;
for y=1:256;
x2=x*cos(5*pi/6)-y*sin(5*pi/6);
y2=x*sin(5*pi/6)+y*cos(5*pi/6);
x3=round(x2);
y3=round(y2);
bigT2(mod(x3,256)+1,mod(y3,256)+1)=bigT1(x,y);
end;
end;


No comments: