You are on page 1of 9

Color and Multi-Spectral Imaging

Lab. n° 2 Report

FASOGBON Peter Oluwanisola


Master Computer Vision and Robotics
Image Processing I
Alamin Mansouri
30th November, 2010

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)

Global and Local Implementation, ROI, MSE ,Eucledian

Matlab Implementations and Results

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

Combination of Greyworld and Modified White Patch


This is the progressive combination of Grey World and Modified White Patch while the Greyworld
is applied on the middle dark to the dark part of the image and vice versa in case of Modified White
Patch algorithm.
rgbresult = GWMWP(rgbin)

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);

IR = filter2(F,R,'same'); %filtering of each channel


IG = filter2(F,G,'same');
IB = filter2(F,B,'same');

Multi Scale Retinex


This algorithm is partly based on the principle of Single Scale retinex but we will need to get the
images at different values of C where C is the gain.
it can be run on the terminal using
msretinex = MSRetinex(rgbin,c1,c2,c3) ;

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

Multi Scale Retinex with Color Correction

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)

Automatic Color Equalization(ACE)


I made use of three ‘For’ loops in my algorithm since this is the easiest way for me to do it. My
function file looks like below,
function rgbout = ACE(rgbin)

And the file can be read out in the command window using this format
rgbin = imread(rgbin);

An example of my ‘FOR’ loop


for i=1:size(R,1)
for j=1:size(R,2)
for k=1:size(R,1)
for l=1:size(R,2)
if([k l]~=[i j])
dist = sqrt((k-i).^2+(l-j).^2);
difference = R(i,j)-R(k,l);
rgbout(i,j,1) = difference/dist;
end
end
end
end
end

MSE and Error (Local and Global)


As I have understand,This part is based on the fact that In order to measure algorithm’s ability to
perform color constancy, we need to compute the mean distance across all the corresponding pixels
between two images of the same size or part of what we need in the two image which leads to
Global and Local Calculations

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

Extract of my conversion to Lab Space


C = makecform('srgb2lab');
lab1 = applycform(rgbout,C);

Comparism using Metric Results

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.

s/N GWorld WPatch MWPatch SSRetinex MSRetinex MSRCR ACE

Visual Less effective Less More Less More Most Better


effective effective details details details
Time 0.106841S on 0.120137S 0.109469S 3.001544S 4.677876S 5.029692S ~15min
30.1kb Image on 141kb on 141kb on 31.3kb on 31.3kb on 31.3kb on 38kb -
feille_cerise.jp Film.tif Film.tif Image Image Image >infinity
g Lena.jpg Lena.jpg Lena.jpg
rating 2/5 1/5 4/5 3/5 5/5 4/5 5/5

I tested this on just few pictures because of Matlab running time,


MSE = metric(xxx_orig, rgbout)
error = mean(xxx_orig, rgbout)
Building Image Film Image Fish Image

MSE 6.6670e+006 1.2325e+009 2.8321e+009

Mean 8.0693e+005 1.0656e+006 1.8250e+006

Efficiency and Hypothesis


As I said earlier, All these algorithms depend on the kind of scene under consideration. This can be
the intensity of the pixels in pictures.
For example,
White Patch Algorithm is better for image with much brighter parts and vice versa in the case of
Grey World.
In the case of Retinex,
 Multi Scale Retinex is Better than SSR in balance of dynamic compression and color
rendition
 MSR is good enough for gray pictures but not desirable for color pictures which leads to the
introduction of Multi Scale Retinex with Color Correction

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.

You might also like