Thread Subject: Normalizing RGB image

Subject: Normalizing RGB image

From: Choo

Date: 19 Jun, 2008 00:27:02

Message: 1 of 25

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?

Subject: Normalizing RGB image

From: Dave Robinson

Date: 19 Jun, 2008 09:48:02

Message: 2 of 25

"Choo " <cyching84@yahoo.com.au> wrote in message
<g3c94m$d66$1@fred.mathworks.com>...
> 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?

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

Subject: Normalizing RGB image

From: Dave Robinson

Date: 19 Jun, 2008 10:30:19

Message: 3 of 25

"Dave Robinson" <dave.robinson@somewhere.biz> wrote in
message <g3da0i$mb$1@fred.mathworks.com>...
> "Choo " <cyching84@yahoo.com.au> wrote in message
> <g3c94m$d66$1@fred.mathworks.com>...
> > 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?
>
> 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
>
>
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

Subject: Normalizing RGB image

From: Choo

Date: 20 Jun, 2008 00:14:03

Message: 4 of 25

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

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!

Subject: Normalizing RGB image

From: ImageAnalyst

Date: 20 Jun, 2008 00:27:26

Message: 5 of 25

On Jun 18, 8:27=A0pm, "Choo " <cychin...@yahoo.com.au> wrote:
> 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?
------------------------------------------------------------------
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

Subject: Normalizing RGB image

From: Choo

Date: 20 Jun, 2008 09:05:04

Message: 6 of 25

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

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

Subject: Normalizing RGB image

From: Dave Robinson

Date: 20 Jun, 2008 09:39:02

Message: 7 of 25

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

Subject: Normalizing RGB image

From: Choo

Date: 23 Jun, 2008 00:12:02

Message: 8 of 25

"Dave Robinson" <dave.robinson@somewhere.biz> wrote in
message <g3ftrm$s20$1@fred.mathworks.com>...
> "Choo " <cyching84@yahoo.com.au> wrote in message <g3frs0
> $cko$1@fred.mathworks.com>...
> > "Dave Robinson" <dave.robinson@somewhere.biz> wrote in
> > message <g3dcfr$i92$1@fred.mathworks.com>...
> > > "Dave Robinson" <dave.robinson@somewhere.biz> wrote
in
> > > message <g3da0i$mb$1@fred.mathworks.com>...
> > > > "Choo " <cyching84@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,
>

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

Subject: Normalizing RGB image

From: Choo

Date: 23 Jun, 2008 00:29:02

Message: 9 of 25

"Dave Robinson" <dave.robinson@somewhere.biz> wrote in
message <g3ftrm$s20$1@fred.mathworks.com>...
> "Choo " <cyching84@yahoo.com.au> wrote in message <g3frs0
> $cko$1@fred.mathworks.com>...
> > "Dave Robinson" <dave.robinson@somewhere.biz> wrote in
> > message <g3dcfr$i92$1@fred.mathworks.com>...
> > > "Dave Robinson" <dave.robinson@somewhere.biz> wrote
in
> > > message <g3da0i$mb$1@fred.mathworks.com>...
> > > > "Choo " <cyching84@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,
>

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

Subject: Normalizing RGB image

From: Dave Robinson

Date: 24 Jun, 2008 12:29:02

Message: 10 of 25

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

Subject: Normalizing RGB image

From: Choo

Date: 25 Jun, 2008 00:05:28

Message: 11 of 25

"Dave Robinson" <dave.robinson@somewhere.biz> wrote in
message <g3qpae$9ds$1@fred.mathworks.com>...
> "Choo " <cyching84@yahoo.com.au> wrote in message
> <g3mqoe$5tm$1@fred.mathworks.com>...
> > "Dave Robinson" <dave.robinson@somewhere.biz> wrote in
> > message <g3ftrm$s20$1@fred.mathworks.com>...
> > > "Choo " <cyching84@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

Subject: Normalizing RGB image

From: heshandh@gmail.com

Date: 24 Jul, 2008 03:16:00

Message: 12 of 25

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

heshandh@gmail.com

Subject: Normalizing RGB image

From: shaihd

Date: 19 Sep, 2008 06:41:03

Message: 13 of 25

"Dave Robinson" <dave.robinson@somewhere.biz> wrote in message <g3da0i$mb$1@fred.mathworks.com>...
> "Choo " <cyching84@yahoo.com.au> wrote in message
> <g3c94m$d66$1@fred.mathworks.com>...
> > 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?
>
> 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
>
>
plz
i m beginner here
can u provide the mathlab code of doing it
tc bye

Subject: Normalizing RGB image

From: Walter Roberson

Date: 24 Sep, 2008 04:58:49

Message: 14 of 25

shaihd wrote:
> "Dave Robinson" <dave.robinson@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.

Subject: Normalizing RGB image

From: Tony

Date: 8 Jul, 2009 07:19:02

Message: 15 of 25

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

Subject: Normalizing RGB image

From: ddd ddddd

Date: 10 Oct, 2009 14:50:03

Message: 16 of 25

"Tony " <ewizlab@gmail.com> wrote in message <h31h96$h35$1@fred.mathworks.com>...
> 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);


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?

Subject: Normalizing RGB image

From: ddd ddddd

Date: 10 Oct, 2009 15:08:01

Message: 17 of 25

"ddd ddddd" <ddd@dd.com> wrote in message <haq6ur$bmk$1@fred.mathworks.com>...
> "Tony " <ewizlab@gmail.com> wrote in message <h31h96$h35$1@fred.mathworks.com>...
> > 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);
>
>
> 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

Subject: Normalizing RGB image

From: hira

Date: 5 Dec, 2009 11:12:04

Message: 18 of 25

"Tony " <ewizlab@gmail.com> wrote in message <h31h96$h35$1@fred.mathworks.com>...
> 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);

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

Subject: Normalizing RGB image

From: ImageAnalyst

Date: 5 Dec, 2009 12:34:45

Message: 19 of 25

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;

Subject: Normalizing RGB image

From: Dave Robinson

Date: 5 Dec, 2009 16:40:20

Message: 20 of 25

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <9c661d81-9aa2-424b-867f-c11393737a5f@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
 
Assuming you are working in UINT8, if you are working in doubles then they are scaled correspondingly

Hope that helps

Dave Robinson

Subject: Normalizing RGB image

From: Saiful lufias

Date: 9 Feb, 2010 06:19:03

Message: 21 of 25

"Dave Robinson" <dave.robinson@somewhere.biz> wrote in message <hfe2dj$fv0$1@fred.mathworks.com>...
> ImageAnalyst <imageanalyst@mailinator.com> wrote in message <9c661d81-9aa2-424b-867f-c11393737a5f@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??
> Assuming you are working in UINT8, if you are working in doubles then they are scaled correspondingly
>
> Hope that helps
>
> Dave Robinson

Subject: Normalizing RGB image

From: Dave Robinson

Date: 14 Feb, 2010 17:23:02

Message: 22 of 25

"Saiful lufias" <pedang_21@yahoo.com> wrote in message <hkquon$rjo$1@fred.mathworks.com>...
> "Dave Robinson" <dave.robinson@somewhere.biz> wrote in message <hfe2dj$fv0$1@fred.mathworks.com>...
> > ImageAnalyst <imageanalyst@mailinator.com> wrote in message <9c661d81-9aa2-424b-867f-c11393737a5f@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??
> > Assuming you are working in UINT8, if you are working in doubles then they are scaled correspondingly
> >
> > Hope that helps
> >
> > Dave Robinson

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

Subject: Normalizing RGB image

From: J.D

Date: 29 Sep, 2010 14:47:07

Message: 23 of 25

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

Subject: Normalizing RGB image

From: rAnDoM

Date: 26 Jan, 2011 02:34:04

Message: 24 of 25

"Tony" wrote in message <h31h96$h35$1@fred.mathworks.com>...
> 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);

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.

Subject: Normalizing RGB image

From: Miro

Date: 28 Mar, 2012 09:13:11

Message: 25 of 25

> 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

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
rgb normalize ddd ddddd 10 Oct, 2009 10:54:06
rgb image Choo 18 Jun, 2008 20:58:46
normalizing Choo 18 Jun, 2008 20:58:29
rssFeed for this Thread

Contact us at files@mathworks.com