//----------------------------------------------------------------------------------------------------- //Фильтрация матриц по маске public static RealMatrix[] FilterMatricesByMask(RealMatrix[] matrices, RealMatrix mask) { RealMatrix[] newMatrices = new RealMatrix[matrices.Length]; for (int index = 0; index < matrices.Length; index++) { RealMatrix matrix = matrices[index]; RealMatrix newMatrix = MatrixHandler.FilterMatrixByMask(matrix, mask); newMatrices[index] = newMatrix; } return(newMatrices); }
//------------------------------------------------------------------------------------------------ //Фильтрация матрицы по маске 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); }