% Test the intensity transformation 
% AUTHOR:   Borgo-Soranzo-Grassi  2012      

load mandrill             % load a MATLAB image. X is the image.
                          % map is the colormap
ColMap=gray(255);         % Calculate a colormap of 255 values.
X1=floor(min(X+128,255)); % Increase the intensity and clip
X2=floor(max(X-128,0));   % Decrease the intensity and clip
X3=floor(min(X*2,255));   % Multiply the intensity by 2 and clip 
X4=256-X;                 % invert the intensity

figure; 
subplot(2,5,1); image(X); axis off;
subplot(2,5,2); image(X1); axis off;
subplot(2,5,3); image(X2); axis off;
subplot(2,5,4); image(X3); axis off;
subplot(2,5,5); image(X4); axis off;
colormap(ColMap);

Oldval=[1:255];
subplot(2,5,7)
plot(Oldval,floor(min(Oldval+128,255))); % Show the new Intensity value
axis([-5 260 -5 260]);                   % vs. the old ones 
xlabel('Old values'); ylabel('New values');
 
Oldval=[1:255];
subplot(2,5,8)
plot(Oldval,floor(max(Oldval-128,0))); % Show the new Intensity value
axis([-5 260 -5 260]);                   % vs. the old ones 
xlabel('Old values'); ylabel('New values');

Oldval=[1:255];
subplot(2,5,9)
plot(Oldval,floor(min(Oldval*2,255)));   % Show the new Intensity value
axis([-5 260 -5 260]);                   % vs. the old ones 
xlabel('Old values'); ylabel('New values');

Oldval=[1:255];
subplot(2,5,10)
plot(Oldval,256-Oldval);                 % Show the new Intensity value
axis([-5 260 -5 260]);                   % vs. the old ones 
xlabel('Old values'); ylabel('New values');