function g = imnegative (f)
%write a matlab function that accepts a  gray or binary image
%and returns the negative of that image
% using the following equations
% for uint8 image data g = 255-f;
%for logical image data g = 1-f
[M N]=size(f);
%preallocating the output arrays
if (islogical(f)==true)
    g= logical(zeros(M,N));%if the image is a Binary image
else
    g = uint8(zeros(M,N));%if the image is a Gray image
end
for x =1 : M
    for y =1 : N
        if (islogical(f(x,y))==true)
            g(x,y)= 1-f(x,y);
        else
            g(x,y)=255-f(x,y);
        end
        
    end
end






