% DIGITAL IMAGE PROCESSING -ELEN512 %
% LAKSHMI CHAITANYA CHAVA %
% PROJECT-2 MAKEUPTEST PROGRAM NO-1 FROM THE GIVEN MAKEUP TEST %
% This is a function of filtering by using 3*3 mask and it is checked by
% the image 'monalisa.gif'%
I=double(imread('monalisa.gif')); % 1) imread returns the image data in 
                                  % the array I which is a grayscale
                                  % image where I is a two-dimensional
                                  % (M-by-N) array.where M is number of
                                  % rows and N is number of columns
                                  % 2) double should be overloaded for any
                                  % object when it makes sense to convert
                                  % it to a double-precision value.
[R,C]=size(I)                     % for the size of the matrix array of 
                                  % the given image where R is number of 
                                  % rows and C is number of columns 
colormap gray                     % gray returns a linear grayscale colormap.

for x=1:R                         % row value stored one at a time in the 
                                  % variable x up to the end, are eexecuted.
for y=1:C                         % column value stored one at a time in the
                                  % variable x up to the end, are executed.
switch x>=1 & y>=1                % the filtering is shown by using the 
                                  % switch case where x,y,z,R&C are the
                                  % variables used in the filtering by
                                  % using the 3*3 mask.
case x==1 & y==1                  % "==" check the condition of "="
Z=I(x,y+1)+I(x+1,y+1)+I(x,y)+I(x+1,y);
case x==R & y==C
Z= I(x,y)+I(x-1,y)+I(x,y-1)+I(x-1,y-1);
case x==1 & y<C
Z= I(x,y)+I(x+1,y)+I(x,y+1)+I(x+1,y+1)+I(x,y-1)+I(x+1,y-1);
case y==C & x>1
Z= I(x,y)+I(x-1,y)+I(x,y-1)+I(x-1,y-1)+I(x+1,y)+I(x+1,y-1);
case y==1 & x<R
Z= I(x,y)+I(x+1,y)+I(x,y+1)+I(x+1,y+1)+I(x-1,y)+I(x-1,y+1);
case x==R & y>1
Z= I(x,y)+I(x-1,y)+I(x,y-1)+I(x-1,y-1)+I(x,y+1)+I(x-1,y+1);
case x>1 & x<R & y>1 & y<C
Z= I(x,y)+I(x+1,y-1)+I(x-1,y)+I(x-1,y+1)+I(x+1,y)+I(x,y+1)+I(x+1,y+1)+I(x,y-1)+I(x-1,y-1);
end
F(x,y)=Z/9;                    % according to the formula 
end
end
imagesc(F);                    %imagesc function scales image data to the full
                               %range of the given image and displays the image. 
%END                               