% dip05_1.m          gr05mar15
% Intensity transformations
clear all;

f = imread('.\img\cameraman.tif');
disp([min(f(:)), max(f(:))]);
imshow(f);
impixelinfo;  % pixval;
pause;

f = double(f);      % range remains [0,255]

f1 = 255 - f;           %  negative

f2 = f;                           %  stretch a portion of the gray levels
fmn = 90;    fmx = 160;
f2(f2<fmn)=fmn;
f2(f2>fmx)=fmx;
f2 = (f2-fmn) / (fmx-fmn) * 255;

f3 = f;                           %  display a portion of the gray levels
fmn = 110;    fmx = 140;
f3(f3<fmn)=0;
f3(f3>fmx)=0;

imshow([f f1; f2 f3],[]);   pause;

in = 0:255;                       %  gamma mapping plots
for i=-2:.4:2;
    gamma = 5 .^i;
    disp(gamma);
    c = 255 .^ (1-gamma);              % set output range = input range
    out = c * in .^ gamma;
    plot(in,out); axis('tight'); axis('square'); hold on;
    end;
hold off;
pause;

f = double(imread('.\img\alpibn.tif'));
for i=-1.5:.3:1;                            % different gamma corrections
    gamma = 5 .^i;
    f1 = (255 .^(1-gamma)) * f .^ gamma;
    imshow([f f1],[]);   text(400,20,num2str(gamma,3));   pause;
    end;

return;
