Wednesday, June 18, 2008

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:

No comments: