%Program by Chandra Kambhamettu. TAs: Conor Gilsenan
%and Sana Malik. 10/02/08

%Program which reads an image and shrinks it by 1/3

clear;

%Read the image; make sure image is in the same directory
%as the matlab program

I=imread('fruits-picture.jpg');

%Pick out 300 by 300 region from the image

for i=1:300
    for j=1:300
        I1(i,j,1)=I(i,j,1);
        I1(i,j,2)=I(i,j,2);
        I1(i,j,3)=I(i,j,3);
    end
 end

%Write the 300 by 300 image as a jpg file

imwrite(I1,'Image_300By300.jpg');

%Pick every thrid element of the image and
%assign into I2
for i=3:3:300
   for j=3:3:300
       I2(i/3,j/3,1)=I1(i,j,1);
       I2(i/3,j/3,2)=I1(i,j,2);
       I2(i/3,j/3,3)=I1(i,j,3);
   end
end

%Write out the shrunk image
imwrite(I2,'Image_reduced.jpg');
