Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Normalizing RGB image

2,143 views
Skip to first unread message

Choo

unread,
Jun 18, 2008, 8:27:02 PM6/18/08
to
Can someone please tell me what is the use of normalizing
an image? i've read that, this is to remove the effect of
any change in intensity.
can i make the intensity of 2 images similar or same?

and,how to do normalizing?

Dave Robinson

unread,
Jun 19, 2008, 5:48:02 AM6/19/08
to
"Choo " <cych...@yahoo.com.au> wrote in message
<g3c94m$d66$1...@fred.mathworks.com>...

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


Dave Robinson

unread,
Jun 19, 2008, 6:30:19 AM6/19/08
to
"Dave Robinson" <dave.r...@somewhere.biz> wrote in
message <g3da0i$mb$1...@fred.mathworks.com>...
Whoops Sorry

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

Choo

unread,
Jun 19, 2008, 8:14:03 PM6/19/08
to
"Dave Robinson" <dave.r...@somewhere.biz> wrote in
message <g3dcfr$i92$1...@fred.mathworks.com>...

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!

ImageAnalyst

unread,
Jun 19, 2008, 8:27:26 PM6/19/08
to
------------------------------------------------------------------
Choo:
I think what you're wanting to do is called "histogram matching" or
"histogram warping." You can Google them. It's been talked a lot on
newsgroups, some here and a lot on sci.image.processing. The best
paper I've seen on the topic is by Mark Grundland and Neil Dodgson:
http://www.cl.cam.ac.uk/~mg290/Portfolio/ColorHistogramWarp.html
It's very nice work. I wouldn't be surprised if it ended up being one
of the classic papers in that area. What's really nice is that it
does a wonderful job on color images, which is a lot tougher to do
than with monochrome images.
Look at that page - I think you'll find it does what you want.
Good luck,
ImageAnalyst

Choo

unread,
Jun 20, 2008, 5:05:04 AM6/20/08
to
"Dave Robinson" <dave.r...@somewhere.biz> wrote in
message <g3dcfr$i92$1...@fred.mathworks.com>...

for "NormalizedRed = Red/sqrt(Red^2 + Green^2 + Blue^2); "
where does the "Red" comes from?

Dave Robinson

unread,
Jun 20, 2008, 5:39:02 AM6/20/08
to
"Choo " <cych...@yahoo.com.au> wrote in message <g3frs0
$cko$1...@fred.mathworks.com>...

> "Dave Robinson" <dave.r...@somewhere.biz> wrote in
> message <g3dcfr$i92$1...@fred.mathworks.com>...
> > "Dave Robinson" <dave.r...@somewhere.biz> wrote in
> > message <g3da0i$mb$1...@fred.mathworks.com>...
> > > "Choo " <cych...@yahoo.com.au> wrote in message
> > > <g3c94m$d66$1...@fred.mathworks.com>...
>
> 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,

Choo

unread,
Jun 22, 2008, 8:12:02 PM6/22/08
to
"Dave Robinson" <dave.r...@somewhere.biz> wrote in
message <g3ftrm$s20$1...@fred.mathworks.com>...

Yup..i'm ok with the 3 single RGB planes concept. thank you!

Choo

unread,
Jun 22, 2008, 8:29:02 PM6/22/08
to
"Dave Robinson" <dave.r...@somewhere.biz> wrote in
message <g3ftrm$s20$1...@fred.mathworks.com>...

There's a question again..what does the parameter x & y
represent in "Red = Image_Red[x,y]; ". I'm really a
beginner here..

Dave Robinson

unread,
Jun 24, 2008, 8:29:02 AM6/24/08
to
"Choo " <cych...@yahoo.com.au> wrote in message
<g3mqoe$5tm$1...@fred.mathworks.com>...

> "Dave Robinson" <dave.r...@somewhere.biz> wrote in
> message <g3ftrm$s20$1...@fred.mathworks.com>...
> > "Choo " <cych...@yahoo.com.au> wrote in message
<g3frs0
> > $cko$1...@fred.mathworks.com>...

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


Choo

unread,
Jun 24, 2008, 8:05:28 PM6/24/08
to
"Dave Robinson" <dave.r...@somewhere.biz> wrote in
message <g3qpae$9ds$1...@fred.mathworks.com>...

> "Choo " <cych...@yahoo.com.au> wrote in message
> <g3mqoe$5tm$1...@fred.mathworks.com>...
> > "Dave Robinson" <dave.r...@somewhere.biz> wrote in
> > message <g3ftrm$s20$1...@fred.mathworks.com>...
> > > "Choo " <cych...@yahoo.com.au> wrote in message
> <g3frs0
> > > $cko$1...@fred.mathworks.com>...
>
> 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

hesh...@gmail.com

unread,
Jul 23, 2008, 11:16:00 PM7/23/08
to
Hello guys,

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

hesh...@gmail.com

shaihd

unread,
Sep 19, 2008, 2:41:03 AM9/19/08
to
"Dave Robinson" <dave.r...@somewhere.biz> wrote in message <g3da0i$mb$1...@fred.mathworks.com>...
plz
i m beginner here
can u provide the mathlab code of doing it
tc bye

Walter Roberson

unread,
Sep 24, 2008, 12:58:49 AM9/24/08
to
shaihd wrote:
> "Dave Robinson" <dave.r...@somewhere.biz> wrote in message <g3da0i$mb$1...@fred.mathworks.com>...

>> 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.

Tony

unread,
Jul 8, 2009, 3:19:02 AM7/8/09
to
The above discussed algorithm in code

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

ddd ddddd

unread,
Oct 10, 2009, 10:50:03 AM10/10/09
to
"Tony " <ewi...@gmail.com> wrote in message <h31h96$h35$1...@fred.mathworks.com>...


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?

ddd ddddd

unread,
Oct 10, 2009, 11:08:01 AM10/10/09
to
"ddd ddddd" <d...@dd.com> wrote in message <haq6ur$bmk$1...@fred.mathworks.com>...


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

hira

unread,
Dec 5, 2009, 6:12:04 AM12/5/09
to
"Tony " <ewi...@gmail.com> wrote in message <h31h96$h35$1...@fred.mathworks.com>...

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

ImageAnalyst

unread,
Dec 5, 2009, 7:34:45 AM12/5/09
to
On Dec 5, 6:12 am, "hira " <h_far...@yahoo.com> wrote

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


Dave Robinson

unread,
Dec 5, 2009, 11:40:20 AM12/5/09
to
ImageAnalyst <imagea...@mailinator.com> wrote in message <9c661d81-9aa2-424b...@31g2000vbf.googlegroups.com>...
> On Dec 5, 6:12?am, "hira " <h_far...@yahoo.com> wrote

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

Saiful lufias

unread,
Feb 9, 2010, 1:19:03 AM2/9/10
to
"Dave Robinson" <dave.r...@somewhere.biz> wrote in message <hfe2dj$fv0$1...@fred.mathworks.com>...

> ImageAnalyst <imagea...@mailinator.com> wrote in message <9c661d81-9aa2-424b...@31g2000vbf.googlegroups.com>...
> > On Dec 5, 6:12?am, "hira " <h_far...@yahoo.com> wrote
> > > 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
>

dave..

>i already got the normalized rgb,so that means i should make skin segmentation from that pic or what??

Dave Robinson

unread,
Feb 14, 2010, 12:23:02 PM2/14/10
to
"Saiful lufias" <peda...@yahoo.com> wrote in message <hkquon$rjo$1...@fred.mathworks.com>...

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

J.D

unread,
Sep 29, 2010, 10:47:07 AM9/29/10
to
can i know how to show the value of normalized RGB for every pixel~
like when we take the cursor to the pixel then it will show the value~

and lastly to calculate the average of the value of r ,g , and b

rAnDoM

unread,
Jan 25, 2011, 9:34:04 PM1/25/11
to
"Tony" wrote in message <h31h96$h35$1...@fred.mathworks.com>...

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.

Miro

unread,
Mar 28, 2012, 5:13:11 AM3/28/12
to
> 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);

Hello Dave Robinson,

I am very interessted in this formula, what is its background? Can you provide me more information about it? (Paper, book, link). All tries by google failed so far.

Regards Miro
0 new messages