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

ToMatrix() public method

Copies the data from a Bitmap object into a Weka Matrix for purposes of matrix manipulation. Future consideration: Bitmap class's LockBits() function offers better performance for large-scale changes that SetPixel()
public ToMatrix ( Bitmap bm ) : Matrix
bm System.Drawing.Bitmap
return Matrix
        public Matrix ToMatrix(Bitmap bm)
        {
            int height = bm.Height;
            int width = bm.Width;
            Matrix M = new Matrix(height, width);
            Color pixelColor;

            //iterate through the Bitmap, getting the colors from each pixel, convert the colors to RGB alpha value and store in a Matrix
            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    pixelColor = bm.GetPixel(i, j);     //get pixel color from Bitmap
                    M.set(i, j, pixelColor.ToArgb());   //convert to alpha RGB and store in the Matrix, M
                }
            }

            return M;
        }