Question

Within a RGB image (from a webcam) I'm looking for a way to increase the intensity/brightness of green. Glad if anyone can give a starting point.

I'm using AFORGE.NET in C# and/or OpenCV directly in C++.

Was it helpful?

Solution 3

This is what I came up with after reading through many pages of AForge.NET and OpenCV documentation. If you apply the saturation filter first, you might get a dizzy image. If you apply it later you will get a much clearer image but some "light green" pixels might have been lost before while applying the HSV filter.

                        // apply saturation filter to increase green intensity
                        var f1 = new SaturationCorrection(0.5f);
                        f1.ApplyInPlace(image);

                        var filter = new HSLFiltering();
                        filter.Hue = new IntRange(83, 189);         // all green (large range)
                        //filter.Hue = new IntRange(100, 120);      // light green (small range)

                        // this will convert all pixels outside the range into gray-scale
                        //filter.UpdateHue = false;
                        //filter.UpdateLuminance = false;

                        // this will convert all pixels outside that range blank (filter.FillColor)
                        filter.Saturation = new Range(0.4f, 1);
                        filter.Luminance = new Range(0.4f, 1);

                        // apply the HSV filter to get only green pixels
                        filter.ApplyInPlace(image);

OTHER TIPS

in general multiplication of pixel values is though of as an increase in contrast and addition is though of as an increase in brightness.

in c#

where you have an array to the first pixel in the image such as this:

byte[] pixelsIn;  
byte[] pixelsOut; //assuming RGB ordered data

and contrast and brightness values such as this:

float gC = 1.5;
float gB = 50;

you can multiply and/or add to the green channel to achieve your desired effect: (r - row, c - column, ch - nr of channels)

pixelsOut[r*w*ch + c*ch]   = pixelsIn[r*w*ch + c*ch] //red
int newGreen = (int)(pixelsIn[r*w*ch + c*ch+1] * gC + gB);  //green
pixelsOut[r*w*ch + c*ch+1] = (byte)(newGreen > 255 ? 255 : newGreen < 0 ? 0 : newGreen); //check for overflow
pixelsOut[r*w*ch + c*ch+2] = pixelsIn[r*w*ch + c*ch+2]//blue

obviously you would want to use pointers here to speed things up.

(Please note: this code has NOT BEEN TESTED)

For AFORGE.NET, I suggest use ColorRemapping class to map the values in your green channel to other value. The mapping function should be a concave function from [0,255] to [0,255] if your want to increase the brightness without losing details.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top