numl.Math.LinearAlgebra.Matrix.Extract C# (CSharp) Method

Extract() public static method

Extracts this object.
public static Extract ( Matrix m, int x, int y, int width, int height, bool safe = true ) : Matrix
m Matrix Input Matrix.
x int Matrix x.
y int The y coordinate.
width int The width.
height int The height.
safe bool (Optional) true to safe.
return Matrix
        public static Matrix Extract(Matrix m, int x, int y, int width, int height, bool safe = true)
        {
            Matrix m2 = Zeros(height, width);
            for (int i = y; i < y + height; i++)
                for (int j = x; j < x + width; j++)
                    if (safe && i < m.Rows && j < m.Cols)
                        m2[i - y, j - x] = m[i, j];

            return m2;
        }

Usage Example

示例#1
0
 /// <summary>A Matrix extension method that extracts this object.</summary>
 /// <param name="m">Matrix.</param>
 /// <param name="x">The x coordinate.</param>
 /// <param name="y">The y coordinate.</param>
 /// <param name="width">The width.</param>
 /// <param name="height">The height.</param>
 /// <param name="safe">(Optional) true to safe.</param>
 /// <returns>A Matrix.</returns>
 public static Matrix Extract(this Matrix m, int x, int y, int width, int height, bool safe = true)
 {
     return(Matrix.Extract(m, x, y, width, height, safe));
 }