function g = imnegative1 (f)
%write a matlab function that accepts a  gray or binary image
%and displays the negative of that image using the following equations
%for uint8 image data   : output image      g = 255-f;
%for logical image data : output image      g = 1-f;
%for double image data  : output image      g = 1-f;

%preallocating the output images (arrays) depends on their types
[M N]=size(f);
 if(class(f)=='uint8')
    g = uint8(zeros(M,N)); %if the image is a Gray image
 elseif (class(f)=='double')
    f = mat2gray(f);
    g = double(zeros(M,N));
 elseif (class(f)=='logical')
    g = logical(zeros(M,N));%if the image is a Binary image
 else
     error('Unkown image type');
end
for x =1 : M
    for y =1 : N
       if (class(f)=='double')
        g(x,y) = 1-f(x,y);      %if the image data is double
       elseif (class(f)=='uint8')
        g(x,y) = 255-f(x,y);    %if the image data is unit8
       else 
        g(x,y)=1-f(x,y);        %if the image is logical
       end        
    end
end






