and,how to do normalizing?
Indeed you are right, converting an RGB image into
normalized RGB removes the effect of any intensity
variations. An interesting experiment is to take a
photograph of something like a single colour Rose flower,
Converting this into normalized RGB converts the rose to an
amorphous blob of colour, as all of the detail of the
flower is caused by a gentle change in intensity caused by
the shadowing of the petals.
How to do it is quite simple
1) Split your RGB image into three seperate greyscale
images representing the red, green, blue colour planes
Image_red = Image_rgb(:,1);
Image_green = Image_rgb(:,2);
Image_blue = Image_rgb(:,3);
2) For each pixel in the image take the three corresponding
components from the red, green, blue matrices - calculate
the following (Remember to cast into doubles, else you will
get zero on your division)
NormalizedRed = r/sqrt(Red^2 + Green^2 + Blue^2);
NormalizedGreen = g/sqrt(Red^2 + Green^2 + Blue^2);
NormalizedBlue = b/sqrt(Red^2 + Green^2 + Blue^2);
Apply these transformations to evey pixel in the image.
3) Reform a colour image back into UINT8 (you need to
additionally scale the image by a factor of sqrt(3) to get
fully saturated colour representation). Restack the three
normalized planes to form an RGB image, and display. From
memory one of the many ways to do this is
Image_normalizedRGB = cat3(NormalizedRed,NormalizedGreen,
NormalizedBlue);
4) Things to watch for - when you get a true black pixel
Red = Green = Blue = 0, so your transformation equation
will try to compute 0/0 and fall over laughing, catch this
possibility and set the ratio to (1/sqrt(3)) which is
normalized grey. Also look out for noise in the image that
sometimes occurs in regions that were very dark in the
original image.
For speed you might get away with the approximation.
NormalizedRed` = Red/(Red + Green + Blue); etc
Normalizing can provide exactly what you need to compare
two images taken under variations of illumination PROVIDING
the colour temperature of the light source doesn't change
as the illumination output varies. e.g. a Tungsten lamp
will generate a cooler colour temperature if driven with a
lower voltage, so this might give problems - however
variation in daylight caused by clouds, or other shadowing
is easily taken out.
Hope that helps
Regards
Dave Robinson
NormalizedRed = r/sqrt(Red^2 + Green^2 + Blue^2);
NormalizedGreen = g/sqrt(Red^2 + Green^2 + Blue^2);
NormalizedBlue = b/sqrt(Red^2 + Green^2 + Blue^2);
Should read
NormalizedRed = Red/sqrt(Red^2 + Green^2 + Blue^2);
NormalizedGreen = Green/sqrt(Red^2 + Green^2 + Blue^2);
NormalizedBlue = Blue/sqrt(Red^2 + Green^2 + Blue^2);
Hope I caught it before it confused you
Regards
Dave Robinson
Thank you very much for explaining in such details! though
it's quite difficult for my understanding,as i'm just a
beginner in MATLAB, i'll try my best to understand it and
try it out!
for "NormalizedRed = Red/sqrt(Red^2 + Green^2 + Blue^2); "
where does the "Red" comes from?
Sorry about that - I have used it so often, I overlooked
the fact that I haven't defined it.
I hope you are OK with the concept that we have three
single plane images containing the Red, Green, Blue
component of the image. What I should have defined that
Red = Image_Red[x,y]; etc.
In other words Red is the red component of a single pixel.
So you apply the transformation for every pixel in your
image, so you will end up with a Normalized image which is
the same size as your original image.
ImageAnalyst's solution is excellent advice (as usual),
providing that the illumination variation across your two
comparison images are uniform - e.g. someone closed the
aperture of the camera, or the sun went down. If the
illumination variation varies across the image, e.g. a
local shadow falls across a region of the image, then
Normalization will produce a better result than colour
histogram equalization,
Yup..i'm ok with the 3 single RGB planes concept. thank you!
There's a question again..what does the parameter x & y
represent in "Red = Image_Red[x,y]; ". I'm really a
beginner here..
In pseudo-code
for y =1-->numberof rows in image
for x = 1 -->number of columns in the image
Red = Image_red[y,x]
Green = Image_green[y,x]
Blue = Image_blue[y,x]
NormalizedRed = Red/sqrt(Red^2 + Green^2 + Blue^2)
etc.
I clearly explained that in the paragraph which stated
"In other words Red is the red component of a single pixel.
So you apply the transformation for every pixel in your
image, so you will end up with a Normalized image which is
the same size as your original image."
Regards
Dave Robinson
thank you very much for replying
I want normalize RGB images. It mean I want to get images into one
color area, because of im doing undergraduate project about face
recognition. So if you know this, pls send me,
thanks
>> 1) Split your RGB image into three seperate greyscale
>> images representing the red, green, blue colour planes
>> Image_red = Image_rgb(:,1);
>> Image_green = Image_rgb(:,2);
>> Image_blue = Image_rgb(:,3);
> plz
> i m beginner here
> can u provide the mathlab code of doing it
> tc bye
Urrr -- Dave *did* provide matlab code for every step of the process.
He wasn't always consistent about the variable names between the steps,
but you should be able to figure out how the steps connect.
% Normalizing RGB image
% Tony Gladvin George
Image_rgb = imread('image.jpg');
Image_rgb = imresize(Image_rgb, [400 400]);
Image_rgb = double(Image_rgb);
%figure;imshow(uint8(Image_rgb));
Image_red = Image_rgb(:,:,1);
Image_green = Image_rgb(:,:,2);
Image_blue = Image_rgb(:,:,3);
%figure;imshow(uint8(Image_red));
[row,col] = size(Image_rgb(:,:,1));
for y = 1:row %-->numberof rows in image
for x = 1:col %-->number of columns in the image
Red = Image_red(y,x);
Green = Image_green(y,x);
Blue = Image_blue(y,x);
NormalizedRed = Red/sqrt(Red^2 + Green^2 + Blue^2);
NormalizedGreen = Green/sqrt(Red^2 + Green^2 + Blue^2);
NormalizedBlue = Blue/sqrt(Red^2 + Green^2 + Blue^2);
Image_red(y,x) = NormalizedRed;
Image_green(y,x) = NormalizedGreen;
Image_blue(y,x) = NormalizedBlue;
end
end
Image_rgb(:,:,1) = Image_red;
Image_rgb(:,:,2) = Image_green;
Image_rgb(:,:,3) = Image_blue;
Image_rgb = Image_rgb .* Image_rgb;
Image_rgb = Image_rgb .* Image_rgb;
figure; imshow(Image_rgb);
thank u for this but when i paste this code in an m file and run it gives an error
??? Error using ==> normalize at 43
A must be an ATOM.
when i click on normalize at 43 it appears normailze is some function...and matlab opens that for me
what should do to debug code without error?
sry that was my mistake....i named my m file as normalize rbg.m and therefore when i was running that it was running normalize.m which is predefined in some toolbox?
neways thank u very much for the code
please could you help me out to remove the zero division warning.
if the R, G & B = 0 than how to handle it. this is not handled in your code. i need it plz help me.
Regards
---------------------------------------------------------------------------
What's wrong with just setting the values to zero, if all 3 are zero?
NormalizedRed = 0;
NormalizedGreen = 0;
NormalizedBlue = 0;
Well actually thats the wrong answer. Black is a 'colour' that lies along the black/grey/white axis. That is to say that black is the limiting case of very dark grey. thus as the effect of normalizing colour in this fashion removes the effect of intensity variation you would expect black to generate exactly the same result as white, which when scaled to uint8 will give you 147 (255/sqrt(3)). For any colour having equal quantities of r,g & b, even when it is black.
Thus
if(Intensity ==0)
Redness = 147;
Greeness = 147;
Blueness = 147;
else
Redness = ...
end
Assuming you are working in UINT8, if you are working in doubles then they are scaled correspondingly
Hope that helps
Dave Robinson
dave..
>i already got the normalized rgb,so that means i should make skin segmentation from that pic or what??
Hi Saiful lufias
Is there a question or comment buried in your response to this thread - I cannot make any sense of what you are trying to say.
Regards
Dave Robinson
and lastly to calculate the average of the value of r ,g , and b
Hi all,
I tried this code on an image, the problem that I got is the image is very "red and green", I don't obtain an image like on this link : http://www.aishack.in/2010/01/normalized-rgb/
Can someone explain what I did wrong ? Or it normal ?? :-/
Thanks everyone.