%%% sample Matlab code 

%%% read the image 
f=imread('Fig3.08(a).jpg');

%%% change the format to double 
f=double(f);

%%% find the size of the input image f
[M N]=size(f) 

%%% display the input image f as a gray scale image 
image(f); colormap(gray); title('the input image f');  

%%% compute a log transformation of the form s=T(r)=c*log(1+r) 
c=255/log(1+255); 

%%% plot the log transformation 
x=meshgrid(0:1:255);
y=c*log(1.+x);
figure
plot(x,y,'-'); axis image; title('Transformation s=T(r)=c*log(1+r)'); 

%%% apply the mapping T to the input image f: g(i,j)=T( f(i,j) )  
for i=1:M,
  for j=1:N,
    g(i,j)=c*log(1+f(i,j)); 
  end
end 

figure 

%%% display the output image 
image(g); colormap(gray); title('the output image g(i,j)=T(f(i,j))'); 


%%% write the output image to the file "output.tif" 
g=uint8(g);
imwrite(g,'output.tif', 'tif');


