Image RGB pixel Normalization

Hello, I would like to know if it is function/plugin/macro to do a pixel normalization for RGB images in Imagej o

That is to adjust each pixel for on each RGB channel so that for ex. R is tranformed into R’=R/R+G+B
G’=G/R+G+B and B’=B/R+G+B

Thanks so much

Open an RGB image and execute the following macro:

run("RGB Stack");
run("Z Project...", "projection=[Sum Slices]");
imageCalculator("Divide create 32-bit stack", "ORIG","SUM");

!! Be careful !!
The resulting channels can have very different value ranges.
Use the Reset button in the Brightness/Contrast dialog to make the channel content visible.

Thanks so much phaub i got an image stack with the 3 channels normalized. Now how do I merge the gray channels back into a single RGB image normalized.I did it in photoshop, but I would like to know if we can do it imagej as well.
Thanks a lot!!

Hello Claudio -

The imageCalculator() command in Peter’s script leaves you with
a 32-bit (float) stack. For whatever reason, ImageJ does not like to
recognize this as an “RGB Stack.”


run ("8-bit");   // convert to 8-bit stack, recognized as an "RGB Stack"
run ("RGB Color");   // convert "RGB Stack" to a non-stack RGB image

Thanks, mm

I don’t know how you want to interpret this ‘normalized’ data or what you want to do with it but if you want to merge the gray channels you have to consider the display range for each channel before RGB conversion.
The display range will be/has to be/can be adjusted with the Brightness/Contrast dialog BEFORE converting the gray channel stack to RGB.

Here is a macro with some hints:

run("RGB Stack");
run("Z Project...", "projection=[Sum Slices]");
imageCalculator("Divide create 32-bit stack", "ORIG","SUM");

// IJ menu:  Image>Color>Make Composite
run("Make Composite", "display=Composite");

// Do manual min/max adjustment for each channel
// IJ menu:   Image>Adjust>Brightness/Contrast...

// Convert to 32-bit stack to RGB
// IJ menu:   Image>Type>RGB Color
//run("RGB Color");

Thanks so much Peter and Mountain

What I want to do is to calculate two indeces from UAV image of vegetation contaminated with oil spill.
Two indeces can help measuring the health of vegetation over time
excess greenness and green chromatic coordinate colour indices

GCC= G/(R+G+B)

The RGB channels should be normalized before performing index calculation.

Any suggestion on how I can calculate EG in ImageJ from the normalized channels?
Thanks a lot!!!


Check this

Thanks again, very helpfull!!

In Remote Sensing there are a bunch of indices used:

NGRD     (G-R)/(G+R)
IKaw     (R-B)/(R+B)
RGR      R/G
VAR      (G-R)/(G+R-B)
ExG      (2G-R-B)/(G+R+B)
TCV      1.4*(2R-2B)/(2R-G-2B+255*0.4)
GNDV     (NIR-G)/(NIR+G)
ENDV     (NIR+G-2B)/(NIR+G+2B)
FCV      1.5*(2NIR+B-2G)/(2G+2B-2NIR+255*0.5)

You can calculate them by converting your RGB image to an 32-bit image stack (as we have done in the first steps of the macro) and using the ImageCalculator.
You don’t have to worry about normalization. It is a part of the formulars.

What is often overlooked is the spectral bandwidth of the detection.
If an index is designed and approved for narrow banded spectral data without spectral overlap (as in the most satellite or airborne camera system) this index may not give proper results when calculated from standard/consumer RGB camera data collected with wide spectral bandwidth and a strong overlap of the bands.

1 Like

In some papers the calculate
ExG by first normalizing each channel and then compute

ExG (2G-R-B) or use directly 2 * (G/R+G+B) - (R/R+G+B) - (B/B+G+R)

Others use the formula that your quoted

ExG (2G-R-B)/(G+R+B)

but I get different results when I do it… Altough mathematically are basically the same
the computed result differs.

Until you describe HOW you do it nobody can help.

(Mathematically it is the same)

I guess I might have some parsing problem with the formulas that I use
which are

2 *(B/A+B+C) - (A/A+B+C) - (C/A+B+C)


I loaded the image, then color split, and Process-Image expression Parser
Added the chanels and used the above formulas

fullformula sampletest ![simpleversion|666x500]

2 (B/A+B+C) - (A/A+B+C) - (C/A+B+C)
is not identical with

Use either
2 *(B/(A+B+C)) - (A/(A+B+C)) - (C/(A+B+C))

Thanks so much Peter that is working perfectly!