Action_Recognition_2._0.FeatureExtractor2D.rgb2gray C# (CSharp) Method

rgb2gray() public method

Row-wise iteration through the Bitmap, get the color from each pixel and change to grayscale. Refer to this link for explanation of conversion http://stackoverflow.com/questions/687261/converting-rgb-to-grayscale-intensity NOTE: In the future, consider converting Bitmap to Matrix here to set pixel value to integer instead of Color, essentially skipping the Color.FromArgb step
public rgb2gray ( Bitmap bm ) : Bitmap
bm System.Drawing.Bitmap
return System.Drawing.Bitmap
        public Bitmap rgb2gray(Bitmap bm)
        {
            //Row-wise iteration through the Bitmap
            for (int y = 0; y < bm.Height; y++)
            {
                for (int x = 0; x < bm.Width; x++)
                {
                    Color pixelColor = bm.GetPixel(x, y);

                    int pixelLuminance = (int)(pixelColor.R * 0.2126 + pixelColor.G * 0.7152 + pixelColor.B * 0.0722);

                    bm.SetPixel(x, y, Color.FromArgb(pixelLuminance, pixelLuminance, pixelLuminance));
                }//for
            }//for

            return bm;
        }