//---------------------------------------------------------------------------------------------- //Привести матрицы от диапазона к диапазону public static RealMatrix[] TransformMatrices( Interval <double> startInterval, Interval <double> finishInterval, params RealMatrix[] matrices ) { RealIntervalTransform intervalTransformer = new RealIntervalTransform(startInterval, finishInterval); RealMatrix[] newMatrices = new RealMatrix[matrices.Length]; for (int index = 0; index < matrices.Length; index++) { RealMatrix matrix = matrices[index]; RealMatrix newMatrix = RealMatrixValuesTransform.TransformMatrixValues(matrix, intervalTransformer); newMatrices[index] = newMatrix; } return(newMatrices); }
//----------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------- //Создание битововой маски из матрицы (пороговое значение) public BitMask2D(RealMatrix matrix, double thresholdValue) { this.rowCount = matrix.RowCount; this.columnCount = matrix.ColumnCount; this.dataArray = new bool[this.rowCount, this.columnCount]; for (int row = 0; row < rowCount; row++) { for (int column = 0; column < columnCount; column++) { double value = matrix[row, column]; if (value < thresholdValue) { this.dataArray[row, column] = false; } else { this.dataArray[row, column] = true; } } } }
//------------------------------------------------------------------------------------------------ //Фильтрация матрицы по маске 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); }
//----------------------------------------------------------------------------------------------------- public static RealMatrix[] GetGammaCorrectedMatrices( double gamma, params RealMatrix[] matrices ) { RealMatrix[] newMatrices = new RealMatrix[matrices.Length]; for (int index = 0; index < matrices.Length; index++) { RealMatrix matrix = matrices[index]; RealMatrix newMatrix = new RealMatrix(matrix.RowCount, matrix.ColumnCount); for (int row = 0; row < matrix.RowCount; row++) { for (int column = 0; column < matrix.ColumnCount; column++) { newMatrix[row, column] = Math.Pow(matrix[row, column], gamma); } } newMatrices[index] = newMatrix; } return(newMatrices); }
//------------------------------------------------------------------------------------------ //Установка подматрицы public void SetSubMatrix(RealMatrix matrix, int rowTopLeft, int columnTopLeft) { if ( this.RowCount < rowTopLeft + matrix.RowCount || this.ColumnCount < columnTopLeft + matrix.ColumnCount ) { throw new MatrixException(); } for ( int row = rowTopLeft, subMatrixRow = 0; subMatrixRow < matrix.RowCount; row++, subMatrixRow++ ) { for ( int column = columnTopLeft, subMatrixColumn = 0; subMatrixColumn < matrix.ColumnCount; column++, subMatrixColumn++ ) { this[row, column] = matrix[subMatrixRow, subMatrixColumn]; } } }
//------------------------------------------------------------------------------------------ //Транспонирование матрицы public RealMatrix GetTransposedMatrix() { int columnCountNewMatrix = this.rowCount; int rowCountNewMatrix = this.columnCount; RealMatrix newMatrix = new RealMatrix(rowCountNewMatrix, columnCountNewMatrix); for (int rowThisMatrix = 0; rowThisMatrix < this.rowCount; rowThisMatrix++) { for ( int columnThisMatrix = 0; columnThisMatrix < this.columnCount; columnThisMatrix++ ) { int rowNewMatrix = columnThisMatrix; int columnNewMatrix = rowThisMatrix; newMatrix[rowNewMatrix, columnNewMatrix] = this.dataArray[rowThisMatrix, columnThisMatrix]; } } return(newMatrix); }
//----------------------------------------------------------------------------------------- public RealMatrix(RealMatrix matrix) : this(matrix.dataArray) { }