Lets Learn together... Happy Reading

" Two roads diverged in a wood, and I,
I took the one less traveled by,
And that has made all the difference "-Robert Frost

Balance Contrast Enhancement Technique (BCET)

Input Image: http://www.freeimages.co.uk




This technique provides solution to biased color (RGB) composition. The contrast of the image can be stretched or compressed without changing the histogram pattern of the input image(x). The solution is based on the parabolic function obtained from the input image.



The general form of the parabolic function is defined as

The three coefficientsa’,’band ‘c’are derived from the following inputs ,
·        Minimum value of the output image(y)
·        Maximum value of the output image
·        Mean value of the output image



Where
·       ‘l’ represents the minimum value of the input image
·       ‘h’ denotes the maximum value of the input image
·       ‘e’ denotes the mean value of the input image
·       ‘L’ represents the minimum value of the output image
·       ‘H’ denotes the maximum value of the output image
·       ‘E’ denotes the mean value of the output image
·         ‘s’ denotes the mean square sum of the input image

MATLAB CODE:

I = imread('pout.tif'); %READ THE INPUT IMAGE
figure,subplot(121), imshow(I);title('INPUT IMAGE');
x    = double(I); % INPUT IMAGE
Lmin = min(x(:)); % MINIMUM OF INPUT IMAGE
Lmax = max(x(:)); % MAXIMUM OF INPUT IMAGE
Lmean = mean(x(:)); %MEAN OF INPUT IMAGE
LMssum = mean(x(:).^2); %MEAN SQUARE SUM OF INPUT IMAGE

Gmin = 0; %MINIMUM OF OUTPUT IMAGE
Gmax = 255; %MAXIMUM OF OUTPUT IMAGE
Gmean = 110; %MEAN OF OUTPUT IMAGE

bnum = Lmax.^2*(Gmean-Gmin) - LMssum*(Gmax-Gmin) + Lmin.^2*(Gmax-Gmean);
bden = 2*(Lmax*(Gmean-Gmin)-Lmean*(Gmax-Gmin)+Lmin*(Gmax-Gmean));

b = bnum/bden;

a = (Gmax-Gmin)/((Lmax-Lmin)*(Lmax+Lmin-2*b));

c = Gmin - a*(Lmin-b).^2;

y = a*(x-b).^2+c; %PARABOLIC FUNCTION
y = uint8(y);

subplot(122),imshow(y);title('OUTPUT IMAGE');



I_hist = imhist(I(:));
O_hist = imhist(y(:));

figure,stem([0:255],I_hist);hold on;stem([0:255],O_hist);legend INPUT OUTPUT




EXPLANATION:
Set the minimum value to zero and maximum value to 255. Set the mean value to 110.
From the histogram of the output image, it is evident that the minimum value is zero and maximum value 255. The histogram is stretched but the shape is retained.

EXERCISE:
·         Try with different minimum, maximum and mean values for the input image to study the result.
·         Compare the results obtained using ‘Linear contrast Enhancement technique’ and comment your answers below


Let’s try the BCET solution on the RGB image.
Save the below code as a function and name it as ‘BCET.m’

MATLAB CODE:
function y=BCET(Gmin,Gmax,Gmean,x)

    x    = double(x); % INPUT IMAGE
    Lmin = min(x(:)); % MINIMUM OF INPUT IMAGE
    Lmax = max(x(:)); % MAXIMUM OF INPUT IMAGE
    Lmean = mean(x(:)); %MEAN OF INPUT IMAGE
    LMssum = mean(x(:).^2); %MEAN SQUARE SUM OF INPUT IMAGE


    bnum = Lmax.^2*(Gmean-Gmin) - LMssum*(Gmax-Gmin) + Lmin.^2*(Gmax-Gmean);
    bden = 2*(Lmax*(Gmean-Gmin)-Lmean*(Gmax-Gmin)+Lmin*(Gmax-Gmean));

    b = bnum/bden;

    a = (Gmax-Gmin)/((Lmax-Lmin)*(Lmax+Lmin-2*b));

    c = Gmin - a*(Lmin-b).^2;

    y = a*(x-b).^2+c; %PARABOLIC FUNCTION
    y = uint8(y);
end


Now, open script in the editor and try the following code. Make sure the function BCET.m is available in the current working directory.

MATLAB CODE:
%READ THE INPUT IMAGE
A = imread(‘landsat5.png');
%https://landsatlook.usgs.gov

%PREALLOCATE THE OUTPUT IMAGE MATRIX
Output = zeros(size(A));
R = A(:,:,1); %RED CHANNEL
G = A(:,:,2); %GREEN CHANNEL
B = A(:,:,3); %BLUE CHANNEL

figure(1),subplot(211),stem([0:255],imhist(R(:)),'r');hold on;
stem([0:255],imhist(G(:)),'g');hold on;
stem([0:255],imhist(B(:)),'b');
title('HISTOGRAM OF THE INPUT IMAGE');
legend RED GREEN BLUE

Gmin = 0; %MINIMUM VALUE OF THE OUTPUT IMAGE
Gmax = 255; %MAXIMUM VALUE OF THE OUTPUT IMAGE
Gmean = 120; %MEAN VALUE OF THE OUTPUT IMAGE

%PARABOLIC FUNCTION
R=BCET(Gmin,Gmax,Gmean,R);
G=BCET(Gmin,Gmax,Gmean,G);
B=BCET(Gmin,Gmax,Gmean,B);

Output(:,:,1)=R;
Output(:,:,2)=G;
Output(:,:,3)=B;
Output = uint8(Output);

subplot(212),stem([0:255],imhist(R(:)),'r');hold on;
stem([0:255],imhist(G(:)),'g');hold on;
stem([0:255],imhist(B(:)),'b');
title('HISTOGRAM OF THE OUTPUT IMAGE');
legend RED GREEN BLUE

figure(2),subplot(121),imshow(A);title('INPUT IMAGE');
subplot(122),imshow(Output);title('OUTPUT IMAGE');






EXPLANATION:
The minimum and maximum values for all the channels are set as 0 and 255. And the mean value is set as 120.

The mean values of the Red, Green and Blue channels are different as shown in the table below.

INPUT IMAGE
MIN VALUE
MAX VALUE
MEAN VALUE
RED COMPONENT
0
255
43
GREEN COMPONENT
0
255
53.54
BLUE COMPONENT
0
255
39.6

After applying the BCET solution, the result shown below indicates that the mean values of all the channels are balanced.

OUTPUT IMAGE
MIN VALUE
MAX VALUE
MEAN VALUE
RED COMPONENT
0
255
120
GREEN COMPONENT
0
255
119.9
BLUE COMPONENT
0
255
120

To understand the mathematical derivation and the limitations of this technique refer the following paper.

Reference:
Balance contrast enhancement technique and its application in image colour composition http://dx.doi.org/10.1080/01431169108955241
like button Like "IMAGE PROCESSING" page

1 comments:

Unknown said... Reply to comment

thank you for your code

Enjoyed Reading? Share Your Views

Previous Post Next Post Home
Google ping Hypersmash.com