% BRIGHTENIING:

% brighten images

image = testImage;

method = 3;

filePath = 'C:\Documents and Settings\Kim Shultz\My Documents\ee362\brightened pictures\';

fileName = cat(2,filePath,'test_image.jpg');

 

% methods are as follows:

% 1 = make mean 0.5 by addition

% 2 = make mean 0.5 by multiplication

% 3 = multiply by exponential decay

% 4 = multiply by gaussian

 

if method == 1;

    Rav = mean(image(:,:,1));

    Rav = mean(Rav);

    Gav = mean(image(:,:,2));

    Gav = mean(Gav);

    Bav = mean(image(:,:,3));

    Bav = mean(Bav);

    av = mean([Gav,Bav,Rav]);

    image = image +0.5 - av;

    %if any values are over 1, cutoff at 1

    image = min(image,1);

    %if any values are under 0, cutoff at 0

    image = max(image,0);

end

 

if method == 2;

    Rav = mean(image(:,:,1));

    Rav = mean(Rav);

    Gav = mean(image(:,:,2));

    Gav = mean(Gav);

    Bav = mean(image(:,:,3));

    Bav = mean(Bav);

    av = mean([Gav,Bav,Rav]);

    image = image*0.5/av;

    %if any values are over 1, cutoff at 1

    image = min(image,1);

    %if any values are under 0, cutoff at 0

    image = max(image,0);

end

 

if method == 3

    x = .1;

    y = 3;

    image(:,:,1) = image(:,:,1).*y.*(exp(-mean(image,3)/x)+1/y-exp(-1/x));

    image(:,:,2) = image(:,:,2).*y.*(exp(-mean(image,3)/x)+1/y-exp(-1/x));

    image(:,:,3) = image(:,:,3).*y.*(exp(-mean(image,3)/x)+1/y-exp(-1/x));

    %if any values are over 1, cutoff at 1

    image = min(image,1);

    %if any values are under 0, cutoff at 0

    image = max(image,0);

end   

 

if method == 4

    x = .2;

    y = 2;

    xx = [0:.01:1];

    yy = y.*(exp(-(xx./x).^2)+1/y-exp(-1/x^2));

    image(:,:,1) = image(:,:,1).*y.*(exp(-(mean(image,3)./x).^2)+1/y-exp(-1/x^2));

    image(:,:,2) = image(:,:,2).*y.*(exp(-(mean(image,3)./x).^2)+1/y-exp(-1/x^2));

    image(:,:,3) = image(:,:,3).*y.*(exp(-(mean(image,3)./x).^2)+1/y-exp(-1/x^2));

    %if any values are over 1, cutoff at 1

    image = min(image,1);

    %if any values are under 0, cutoff at 0

    image = max(image,0);

end   

 

imwrite(image,fileName,'jpeg');