Wednesday, June 18, 2008

Assign 8, Q1b

Using the function written already and fx=0.5, fy=1...

I get the following modified image by typing:

a=imread("ppic1.jpg");
b=double(a)/255;
c=shrinkimg(b,0.5,1);

Then usual imwrite and imshow process gives you:

Assign 8, Q1

Here we had to try and shrink the image along the 'x' and 'y' axis using different values of 'f' (the shrink factor). In this case I did fx=1 and fy=0.5.

Here are my octave commands:

# note that "lt"= less than and "gt"=greater than...

function s=shrinkimg(img,fx,fy);
xp=floor(size(img,1)*fx);
yp=floor(size(img,2)*fy);
s(:,:,1)=zeros(xp,yp);
s(:,:,2)=zeros(xp,yp);
s(:,:,3)=zeros(xp,yp);
for i=0:(xp-1);
for j=0:(yp-1);
for x=floor(i/fx):ceil((i+1)/fx)-1;
for y=floor(j/fy):ceil((j+1)/fy)-1;
ival=img(x+1,y+1,:)
if(x"lt"i/fx);
ival=ival*(1-i/fx+x);
end;
if (x+1"gt"(i+1)/fx);
ival=ival*(1-(i+1)/fx+x+1);
end;
if (y"lt"i/fy);
ival=ival*(1-j/fy+y);
end;
if (y+1"gt"(j+1)/fy);
ival=ival*(1-(y+1)+(j+1)/fy);
end;
s(i+1,j+1,:)=s(i+1,j+1,:)+ival;
end;
end;
s(i+1,j+1,:)=s(i+1,j+1,:)/((1/(fx*fy))^2);
end;
end;
endfunction;


Now since I am using a function...all I need to enter on the following lines of octave is:

a=imread("imagename.jpg");
b=double(a)/255;
c=shrinkimg(b,1,0.5);
imwrite("out.jpg", c(:,:,1),c(:,:,2),c(:,:,3));

open new terminal:

a=imread("out.jpg");
b=double(a)/255;
imshow(b);

The resulting image is the following:

Assign 7, Q1-method1

Finally got method 1 to work. Please see octave code below and resulting images...





Friday, June 13, 2008

Assignment 7, Q1-method 2

I am having difficulty getting method 1 to work properly but have completed this question using method 2. Please see a copy of my octave command and resulting images.

Please note that I created a "shrinkimg function" in octave and used it repeatedly to shrink my images by factors of 0.75, 0.25 and 0.1. Please click on the octave for more details as I have included # comments # to my code.



To use the function again you simply have to:

1) load your image - octave>A=imread("imagename.jpg");
2) apply shrink function - octave>B=shrinkimg(A, f); # f=0.75, 0.25, 0.1...
3) double your B - octave> C=double(B)/255;
4) then imwrite your new image C...

Here are my new images following the shrink function applied to my first picture.



Here are my new images following the shrink function applied to my second picture.

Sunday, June 8, 2008

Assign 6, Q3c

Here is my first picture on the website:



Here are the commands I used to find the average colour and the subsequent colour 'chip' produced:





Please click on the octave picture for a 'closer view' of the code.

Here is the average colour chip and octave code of my second website image.







I have noticed that if there are a lot of different (major) colours present in a given image, then the less spectacular the colour chip becomes.

Example:

Assign 6, Q2

To create a 256x256 matrix with 1s in the (i, i+1) position and zeros everywhere else using the tril and/or triu functions in octave.

Here is what tril and triu mean:



Here are one line commands in octave that give you a 9x9 matrix with 1s in the (i,i+1) position and zeros everywhere else using the tril and triu command.



To make a 256x256 matrix with 1s in the (i,i+1) position and zeros everywhere else we simply write:

triu(ones(256),1)-triu(ones(256),2).

Assign #5, Q3bc

Just for fun...wanted to see how the rotation of bigT looked like without skewing by s=1 yet...

Here is the picture I got:



As you can see, the image is not very clear.

Applying a skewing factor first and then rotating the new image by pi/4, probably would not look very clear either. Here are the octave commands and resulting new image.