Sunday, June 8, 2008

Assignment 6

Q(1)

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





















2 (a). Create a 256 x 256 matrix with 1s in the (i,i+1) position and zeros elsewhere: (Octave commands) >x=tril(ones(256),1);
>y=tril(ones(256),0);
>x-y #yields matrix with 1s in diagonal



for picture type imshow(ans) to get











>
An alternative method using the command "tril" for "lower triangle" of matrix is


x=[tril(ones(256,1))-tril(ones(256),0);
imshow(x)

ex for a 5 X 5 matrix----> x= [tril(ones(5,1)-tril(ones(5),0); yields

01000
00100
00010
00001



3a) R=ones(100);G=tril(ones(100));B=zeros(100);

x(:,:,1)=(ones(100));x(:,:,2)=tril(ones(100));x(:,:,3)=zeros(100);
imshow(x);











sum(sum(x))/100/100


Octave output


ans(:,:,1) = 1
ans(:,:,2) = 0.50500
ans(:,:,3) = 0





3(b) Images processing from www.pbase.com

My assigned images are pic1= 2nd row 2nd column, and pic2= 7th row, 2nd column

Both images saved in folder called "images" in my C drive

pkg load image;

cd'C:\images'

a=imread("pic1.jpg");

b= double(a)/255;

size(b)

Octave gives:

106 107 3

No comments: