Professional Documents
Culture Documents
Lab. n° 2 Report
Definition
What our visual system perceives is not the color of an object, but the combination of its spectral
reflectance with the illuminant’s spectral characteristics. Consequently, from a photometric view-
point, a yellow patch illuminated with a white light or a white patch illuminated with a yellow light
can reflect the same spectral distribution. Changes in the illuminant should produce changes in the
perceived image. However, the human visual system ~HVS! steadily perceives a scene regardless
of changes in the lighting conditions.This is a perceptual mechanism called color constancy.
This mechanism is able to separate, with a certain tolerance, the reflectance from the illuminant in a
perceived
My work on Color Constancy is based on the use of below defined algorithm to enhance or change
the illumination of an image. Some cases can be as a result of bad illumination when the image was
taken.
Objective
To study efficiency of Color Constancy Algorithms and their Combinations for better results.
Expectations
Report, results of the images, matlab source codes
Algorithms
Algorithms implemented were,
1. Grey World
2. White Patch
3. Modified White Patch
4. Grey World and Modified White Patch
5. Retinex Method
6. Automatic Color Equalization(ACE)
Grey World
My Grey World algorithm in matlab was named “grayworld” and it can be run on the terminal
using
rgbout = grayworld(rgbin);
where rgbout is the result and rgbin is the input image respectively.
For example,
Image = grayworld('feille_cerise.jpg ');
I use main file in my programme to display one test image for each algorithm while others are
commented. I have also already define “imshow” to display respective images when the function is
called.
The images below contain the result of the implemented code above with the result of the input and
output image shown in a single figure
White Patch
The next algorithm, White Patch algorithm, I named it “whitepatch” and it can be run on the ter-
minal using
rgbout = whitepatch(rgbin);
where rgbout is the result and rgbin is the input image respectively.
For example,
Image = whitepatch('Film.tif');
This kind of algorithm depends on the image it is used on since it is white patch algorithm and its
not a good idea to use on the images with the same characteristics. In some images, there may be no
effect in some images with noise and images having max pixel value of 255.
I use main file in my programme to display one test image for each algorithm while others are
commented. I have also already define “imshow” in the algorithm to save time so that it
display respective images when the function is called.
The images below contain the result of the implemented code above with the result of the input and
output image shown in a single figure
Modified White Patch
Modified White Patch algorithm as the name says is like modification made on the initial white
patch algorithm so that it takes into account in situation when there is noise or pixel with maximum
values of 255 (as this is one of the disadvantages of white patch algorithm)
In this case, we only define thresholds and take into account pixels having values greater than a
certain threshold . I named it “modifiedwhitepatch” using matlab and it can be run on the ter-
minal using
rgbout = modifiedwhitepatch(rgbin);
where rgbout is the result and rgbin is the input image respectively.
For example,
Image = modifiedwhitepatch('Film.tif');
I use main file in my programme to display one test image for each algorithm while others are
commented. I have also already define “imshow” in the algorithm to save time so that it
display respective images when the function is called.
The images below contain the result of the implemented code above with the result of the input and
output image shown in a single figure
For example,
Image = GWMWP('building.jpg');
Below contrains an extract from my matlab algorithm( the for loop algorithm implemented )
for i=1:size(rgbin,1)
for j=1:size(rgbin,2)
if I>=h1
rgbout(i,j,1)=rgbin(i,j,1).*KrGW;
rgbout(i,j,2)=rgbin(i,j,2).*KgGW;
rgbout(i,j,3)=rgbin(i,j,3).*KbGW;
elseif I<=h2
rgbout(i,j,1)=rgbin(i,j,1).*KrMWP;
rgbout(i,j,2)=rgbin(i,j,2).*KgMWP;
rgbout(i,j,3)=rgbin(i,j,3).*KbMWP;
else
Kr = (1-delta)*KrGW+delta*KrMWP;
Kg = (1-delta)*KgGW+delta*KrMWP;
Kb = (1-delta)*KbGW+delta*KrMWP;
rgbout(i,j,1)=Kr*rgbin(i,j,1);
rgbout(i,j,2)=Kg*rgbin(i,j,2);
rgbout(i,j,3)=Kb*rgbin(i,j,3);
end
end
end
The images below contain the result of the implemented code above with the result of the input and
output image shown in a single figure
There is really not much difference as perceived by the eyes because of the image used.
Retinex
Single Scale Retinex
This algorithm is based on weighing the values of a neighbouring pixel in an image. This weighing
is done with the Gaussian function called surrounding function.
it can be run on the terminal using
rgbout = SSRetinex(rgbin,c);
where rgbout is the result, rgbin and ‘C’ is the input value for variance which is used in the tunning
of how the images will look i.e the Gain from Gaussian function.
For example,
Image = SSRetinex('lena.jpg',240);
I use main file in my programme to display one test image for each algorithm while others are
commented. I have also already define “imshow” in the algorithm to save time so that it display
respective images when the function is called.
The images below contain the result of the implemented code above with the result of the input and
output image shown in a single figure
rgbout=SSRetinex(rgbin,c)
I carried out this by using fspecial to call the Gaussian function in the matlab to ease my
calculations. See below for details
F = fspecial('gaussian',size(R),c);
where rgbout is the result, rgbin and c1,c2,c.3. The values of c used here are
c1 = 5;
c2 = 20;
c3 = 240; respectively
At the end, the images are merged together to give the desired illuminations.
The output image depends on the values of c respectively.
For example,
Image = MSRetinex('lena.jpg',5,20,240);
I use main file in my programme to display one test image for each algorithm while others are
commented. I have also already define “imshow” in the algorithm to save time so that it display
respective images when the function is called.
The images below contain the result of the implemented code above with the result of the input and
output image shown in a single figure
This algorithm is partly an improvement of Multi Scale Retinex Algorithm. Different values are
introduce here to improve the gains and adjustment.
it can be run on the terminal using
rgbout = MSRCR (rgbin, a);
‘a’=gain from Gaussian
At the end, the images are merged together to give the desired illuminations.
The output image depends on the values of c respectively.
For example,
Image = MSRCR('Film.tif');
I use main file in my programme to display one test image for each algorithm while others are
commented. I have also already define “imshow” in the algorithm to save time so that it display
respective images when the function is called.
The images below contain the result of the implemented code above with the result of the input and
output image shown in a single figure
The first image is the result from ‘a = 0.5’ while the second image is calculated with the value of
‘a=200’.
Figure I (a=0.5)
Figure II (a=200)
And the file can be read out in the command window using this format
rgbin = imread(rgbin);
I computed MSE and Change in mean differently using the formula given in the notebook.
This is an extract of my function file
function MSE = metric(xxx_orig, rgbout)
function error = mean(xxx_orig, rgbout)
This file can be run to give the results of the eucledian distance in the lab colour space as well as the
Minimum Square Error.
where xxx_orig is the original image and rgbout is the image I used for comparism in calculating
the errors and change in mean respectively
Note
All is useful depending on the images and the values of the pixels.
The ratings below are based on my personal observation and its not saying one is better than the
other. One can be very useful in one way and not important in else.
Conclusion
After the end of this project, I was able to understand the Color Constancy better and able to try
different matlab codes which are not used here, It also helps me in consulting different means for
the outcome of this project.
I realized in my own view that ACE and Retinex are very powerful, useful and very important in
Color Constancy . I also gain the use of tic and toc for timer, Eucledian distance and Error
determinations.