%write a matlab function "ImageAdjust" that accepts image and returns an
%enhancement image using the following linear level adjustment formula
%Padjus(m,n)= Bottom + (P(m,n)-L)/(H-L)*(Top-Bottom)
%where 
%P(m,n) ---original image pixel
%Padjus(m,n)----desired image pixel 
%H ---- maximum pixel level in the original image
%L ---- minimum pixel level in the original image
%Top ---maximum pixel level in the  image desired
%Bottom ---- minimum pixel level in the desired image
% Check the class of the input image in your code, to determine the correct
% values for Bottom and Top
%Use low level processing
%the output image must be in uint8 class
function  g = ImageAdjust (f)
[M N]= size(f);
if strcmp(class(f),'double')
    g = zeros(M,N);
    Bottom =0;
    Top = 1;
elseif strcmp(class(f),'uint8')
    g = uint8(zeros(M,N));
    Bottom =0;
    Top = 255;
elseif strcmp(class(f),'uint16')
    g = uint16(zeros(M,N));
    Bottom =0;
    Top = 65535;
else
    error('The class of the image is not supported by IPT');
end
L = min(f(:));
H = max(f(:));
for x =1:M
    for y= 1:N
       g(x,y)=uint8(Bottom + ((f(x,y)-L)/(H-L))*(Top - Bottom));
    end
end

