% Contrast distortion: contrastmap.m
% this program takes an image and applies a contrast distortion --
% such that the max, min and average remain unchanged

% need to be in the following directory
% cd c:\jl\4F8_imageprocessing\imageprocessing5\imageproc5mat


clear,clc,close all,home
p=input('power p in transformation y=x^p =');
% put p=2 or 3 to start with

% Generate image
%N=input('Image size = ');
load lenna256.mat
[N,M]=size(x)
figure(1)
grayimage(x)
min(min(x))
max(max(x))
pause
figure(2)
xx = reshape(x,1,N*N);
hist(xx,50)
pause


k=0.5*(max(max(x))+min(min(x)))
a=(max(max(x))-k);
T = abs((x-k)./a).^p;
y = k + a*sign(x-k).*T;
figure(3)
grayimage(y)
min(min(y))
max(max(y))
pause
figure(4)
yy = reshape(y,1,N*N);
hist(yy,50)
