Tuesday, June 3, 2008

Assignment 7 - Method 1

1. Method 1: Average over all pixels in the destination point.

The Matlab M-file:
function [ smim ] = shrink( picture, f )
Mp = floor(size(picture,1)*f);
Np = floor(size(picture,2)*f);
smim(:,:,1)=zeros(Mp,Np);
smim(:,:,2)=zeros(Mp,Np);
smim(:,:,3)=zeros(Mp,Np);
for i = 0:(Mp-1)
for j = 0:(Np-1)
for x = floor(i/f):ceil((i+1)/f)-1
for y = floor(j/f):ceil((j+1)/f)-1
ival = picture(x+1,y+1,:);
ival = double(ival);
if(x<(i/f));
ival =ival*(1+x-i/f);
end;
if (x+1 > (i+1)/f);
ival = ival*(1+((i+1)/f)-(x+1));
end;
if (y< (j/f));
ival = ival*(1-(j/f)+y);
end;
if (y+1 > (j+1)/f);
ival = ival*(1-(y+1)+(j+1)/f);
end;
smim(i+1,j+1,:) = smim(i+1,j+1,:)+ival;
end;
end;
smim(i+1,j+1,:) = smim(i+1,j+1,:)/(1/f)^2;
smim = smim/255;
end;
end;

The Matlab commands (I'll just show them for the rainbow; the others are similar)

rainbow=imread('rainbow.jpg');
image(shrink(rainbow,0.75))
image(shrink(rainbow,0.25))
image(shrink(rainbow,0.1))

























No comments: