//---------------------------------------------------------------------------------------------- //Получить подматрицы public static RealMatrix[] GetSubMatrices( int rowTopLeft, int columnTopLeft, int rowBottomRight, int columnBottomRight, params RealMatrix[] matrices ) { RealMatrix[] subMatrices = new RealMatrix[matrices.Length]; for (int index = 0; index < matrices.Length; index++) { RealMatrix matrix = matrices[index]; RealMatrix subMatrix = matrix.GetSubMatrix (rowTopLeft, columnTopLeft, rowBottomRight, columnBottomRight); subMatrices[index] = subMatrix; } return(subMatrices); }
//------------------------------------------------------------------------------------------------ //Фильтрация матрицы по маске public static RealMatrix FilterMatrixByMask(RealMatrix matrix, RealMatrix mask) { bool isMaskCorrect = (mask.RowCount == mask.ColumnCount) && ((mask.RowCount % 2) != 0) && ((mask.ColumnCount % 2) != 0); if (!isMaskCorrect) { throw new MatrixException(); } int windowSize = mask.RowCount; int newWidth = matrix.ColumnCount - windowSize + 1; int newHeight = matrix.RowCount - windowSize + 1; RealMatrix newMatrix = new RealMatrix(newHeight, newWidth); int halfSize = windowSize / 2; int startX = halfSize; int startY = halfSize; int finishX = matrix.ColumnCount - halfSize - 1; int finishY = matrix.RowCount - halfSize - 1; for (int x = startX, newX = 0; x <= finishX; x++, newX++) { for (int y = startY, newY = 0; y <= finishY; y++, newY++) { RealMatrix matrixArea = matrix.GetSubMatrix(y - halfSize, x - halfSize, y + halfSize, x + halfSize); double newValue = MatrixHandler.GetFilteredValue(matrixArea, mask); newMatrix[newY, newX] = newValue; } } return(newMatrix); }