//------------------------------------------------------------------------------------------- //------------------------------------------------------------------------------------------- public double[] Compute( Point pointOne, Point pointTwo, int interferogramIndexOne, int interferogramIndexTwo ) { TrajectoryCreator trajectoryCreator = new TrajectoryCreator(this.interferograms); Curve2D trajectory = trajectoryCreator.GetTrajectory(pointOne, pointTwo); Point2D[] points = trajectory.GetPoints(); this.TrajectoryPoints = points; EllipseApproximator ellipseApproximator = new EllipseApproximator(); EllipseDescriptor ellipseDescriptor = ellipseApproximator.Approximate(points); Point2D ellipseCentre = ellipseDescriptor.GetCentre(); points = PlaneManager.DisplacePoints(points, -ellipseCentre.X, -ellipseCentre.Y); double x0 = points[0].X; double y0 = points[0].Y; double x1 = points[interferogramIndexOne].X; double y1 = points[interferogramIndexOne].Y; double x2 = points[interferogramIndexTwo].X; double y2 = points[interferogramIndexTwo].Y; double[] phaseShifts = this.GetPhaseShifts(x0, y0, x1, y1, x2, y2); return(phaseShifts); }
//--------------------------------------------------------------------------------------------- //Аппроксимация эллипсом private EllipseDescriptor GetEllipseDescriptor(Point2D[] points) { EllipseApproximator ellipseApproximator = new EllipseApproximator(); EllipseDescriptor ellipseDescriptor = ellipseApproximator.Approximate(points); return(ellipseDescriptor); }
//------------------------------------------------------------------------------------------- //Вычислить фазовые сдвиги public double[] Compute( Point pointOne, Point pointTwo ) { TrajectoryCreator trajectoryCreator = new TrajectoryCreator(this.interferograms); Curve2D trajectory = trajectoryCreator.GetTrajectory(pointOne, pointTwo); IntensitiesForPointOne = trajectory.GetArrayX(); EllipseApproximator approximator = new EllipseApproximator(); Point2D[] trajectoryPoints = trajectory.GetPoints(); this.TrajectoryPoints = trajectoryPoints; QuadricCurveDescriptor approximatingQuadricCurve = approximator.Approximate(trajectoryPoints); EllipseDescriptor approximatingEllipse = approximatingQuadricCurve as EllipseDescriptor; double startX = 0; double finishX = 255; double step = 1; this.EllipsePoints = approximatingEllipse.GetPoints(startX, finishX, step); Curve2D transformedTrajectory = this.TransformateTrajectory(trajectory, approximatingEllipse); double[] phaseShifts = this.CalculatePhaseShifts(transformedTrajectory); double[] correctedPhaseShifts = this.CorrectPhaseShifts(phaseShifts); return(correctedPhaseShifts); }
//--------------------------------------------------------------------------------------------- //Трансформация траектоории (центрирование, поворот, растяжение) private Curve2D TransformateTrajectory( Curve2D trajectory, EllipseDescriptor approximateEllipse ) { //Центрирование Curve2D transformedTrajectory = this.CentreTrajectory(trajectory, approximateEllipse); //Поворот параллельно координатной оси double rotationAngleToAxis = approximateEllipse.GetAngleBetweenOxAndPrincipalAxis(); transformedTrajectory = this.RotateTrajectory(transformedTrajectory, rotationAngleToAxis); //Растяжение EllipseOrientaion primaryOrientation = approximateEllipse.GetOrientaion(); TrajectoryOrientation trajectoryOrientation = this.DetectTrajectoryOrientation(primaryOrientation, rotationAngleToAxis); double koefficientOfStretch = 1 / approximateEllipse.GetCompressionRatio(); transformedTrajectory = this.StretchingTrajectory (transformedTrajectory, trajectoryOrientation, koefficientOfStretch); //Поворот траектории до пересечения первой точки с осью OX Point2D firstPointTrajectory = transformedTrajectory[0]; double rotationAngle = Mathem.Arctg(firstPointTrajectory.Y, firstPointTrajectory.X); transformedTrajectory = this.RotateTrajectory(transformedTrajectory, rotationAngle); return(transformedTrajectory); }
//--------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------- //Преобразовать точки к окружности private Point2D[] GetTransformedPoints(params Point2D[] points2D) { //this.EllipsePoints = points2D; EllipseApproximator ellipseApproximator = new EllipseApproximator(); EllipseDescriptor ellipseDescriptor = ellipseApproximator.Approximate(points2D); Point2D ellipseCentre = ellipseDescriptor.GetCentre(); points2D = PlaneManager.DisplacePoints(points2D, -ellipseCentre.X, -ellipseCentre.Y); double rotationAngle = ellipseDescriptor.GetAngleBetweenOxAndPrincipalAxis(); points2D = this.RotatePoints(-rotationAngle, points2D); EllipseOrientaion pointsOrientation = this.GetPointsOrientation(points2D); if (pointsOrientation == EllipseOrientaion.AxisY) { points2D = this.RotatePoints(Math.PI / 2, points2D); } double radiusX = ellipseDescriptor.GetSemiMajorAxis(); double radiusY = ellipseDescriptor.GetSemiMinorAxis(); double stretchCoefficient = radiusX / radiusY; Point2D[] stretchPoints = this.StretchPointsAlongAxisY(stretchCoefficient, points2D); this.EllipsePoints = stretchPoints; return(stretchPoints); }
//--------------------------------------------------------------------------------------------- public InterferogramDecodingResult DecodeInterferogram(RealMatrix[] interferograms, BitMask2D bitMask) { //double gamma = 2; //interferograms = MatricesManager.GetGammaCorrectedMatrices( gamma, interferograms ); //interferograms = GetNormalizedMatrices( interferograms ); //Выбранные точки изображения Point[] selectedImagePoints = bitMask.GetTruePoints(); Point3D[] points3D = this.GetParallelToCoordinatePlanePoints3D(interferograms, selectedImagePoints); this.TrajectoryPoints = points3D; Point2D[] points2D = SpaceManager.GetProjectionXY(points3D); this.ProjectionPoints = points2D; EllipseDescriptor ellipseDescriptor = this.GetEllipseDescriptor(points2D); Point2D ellipseCentre = ellipseDescriptor.GetCentre(); Point3D pointsCentre = new Point3D(ellipseCentre.X, ellipseCentre.Y, points3D[0].Z); RealVector cylinderGuidLine = this.GetCylinderGuidLine(ellipseDescriptor); RealVector normalizedCylinderGuidLine = cylinderGuidLine.GetNormalizedVector(); /* * this.CalculateCirclePointsDispersion( cylinderGuidLine, points3D, pointsCentre ); * double cylinderGuidLineOptimalAngle = this.GetCylinderGuidLineOptimalAngle(); * cylinderGuidLine = this.GetRotatedInPlaneCylinderGuidLine * ( cylinderGuidLine, cylinderGuidLineOptimalAngle ); */ Point3D[] circlePoints = this.GetCirclePoints(points3D, normalizedCylinderGuidLine); this.CirclePoints = circlePoints; Point3D circlePointsCentre = this.GetCorrectedCirclePoint(pointsCentre, normalizedCylinderGuidLine); //Поворот точек RealMatrix rotationMatrix = this.GetRotationMatrix(circlePoints); //rotationMatrix.WriteToTextFile( @"d:\!!\RotationMatrix.txt" ); // debug Point3D[] rotatedCirclePoints = this.RotatePoints(circlePoints, rotationMatrix); this.RotatedCirclePoints = rotatedCirclePoints; Point3D rotatedCirclePointsCentre = PlaneManager.RotateVector (new RealVector(circlePointsCentre), rotationMatrix).ToPoint3D(); Point3D[] correctedPoints = this.DisplacePoints(rotatedCirclePoints, rotatedCirclePointsCentre); int sizeX = interferograms[0].ColumnCount; int sizeY = interferograms[0].RowCount; RealMatrix phaseMatrix = this.CalculatePhaseMatrixByCirclePoints (correctedPoints, selectedImagePoints, sizeX, sizeY); InterferogramDecodingResult decodingResult = new InterferogramDecodingResult(phaseMatrix); return(decodingResult); }
//--------------------------------------------------------------------------------------------- //Направляющая цилиндра private RealVector GetCylinderGuidLine(EllipseDescriptor ellipseDescriptor) { double semiMinorAxis = ellipseDescriptor.GetSemiMinorAxis(); double semiMajorAxis = ellipseDescriptor.GetSemiMajorAxis(); double angle = ellipseDescriptor.GetAngleBetweenOxAndPrincipalAxis(); RealVector cylinderGuidLine = this.CreateCylinderGuidLine(semiMinorAxis, semiMajorAxis, angle); return(cylinderGuidLine); }
//--------------------------------------------------------------------------------------------- //Центрирование траектории private Curve2D CentreTrajectory( Curve2D trajectory, //Траектория EllipseDescriptor approximatingEllipse //Аппроксимирующий эллипс ) { Point2D centreEllipse = approximatingEllipse.GetCentre(); Curve2D transformedTrajectory = trajectory.GetDisplacementCurve(-centreEllipse.X, -centreEllipse.Y); return(transformedTrajectory); }
//--------------------------------------------------------------------------------------- //Создание эллипса private EllipseDescriptor CreateEllipseDescriptor(double[] array) { double a11 = array[0]; double a22 = array[1]; double a12 = array[2] / 2; double a13 = array[3] / 2; double a23 = array[4] / 2; double a33 = array[5]; EllipseDescriptor ellipse = new EllipseDescriptor(a11, a22, a12, a13, a23, a33); return(ellipse); }
//--------------------------------------------------------------------------------------- //Аппроксимировать public EllipseDescriptor Approximate(Point2D[] points) { RealMatrix matrixD = this.CreateMatrixD(points); RealMatrix transposedMatrixD = matrixD.GetTransposedMatrix(); RealMatrix matrixS = transposedMatrixD * matrixD; double[] eigenValues = this.CalculateEigenValues(matrixS); double[] absoluteEigenValues = ArrayOperator.GetAbsoluteValues(eigenValues); int minAbsoluteEigenValueIndex = ArrayOperator.GetMinValueIndex(absoluteEigenValues); double lambda = eigenValues[minAbsoluteEigenValueIndex]; RealMatrix matrixA = this.CreateMatrixA(matrixS, lambda); double[ , ] dataArrayMatrixA = matrixA.GetDataArray(); double[] dataArrayVectorB = new double[] { 1, 0, 0, 0, 0, 0 }; double[] values = this.SolveLinearSystem(dataArrayMatrixA, dataArrayVectorB); EllipseDescriptor ellipse = this.CreateEllipseDescriptor(values); return(ellipse); }
//--------------------------------------------------------------------------------------------- //Преобразовать точки к окружности private Point2D[] GetTransformedPoints(Point2D[] points2D) { EllipseApproximator ellipseApproximator = new EllipseApproximator(); EllipseDescriptor ellipseDescriptor = ellipseApproximator.Approximate(points2D); Point2D ellipseCentre = ellipseDescriptor.GetCentre(); points2D = PlaneManager.DisplacePoints(points2D, -ellipseCentre.X, -ellipseCentre.Y); double rotationAngle = ellipseDescriptor.GetAngleBetweenOxAndPrincipalAxis(); points2D = this.RotatePoints(points2D, -rotationAngle); EllipseOrientaion pointsOrientation = this.GetPointsOrientation(points2D); if (pointsOrientation == EllipseOrientaion.AxisY) { points2D = this.RotatePoints(points2D, Math.PI / 2); } double radiusX = ellipseDescriptor.GetSemiMajorAxis(); double radiusY = ellipseDescriptor.GetSemiMinorAxis(); CanonicalEllipseDescriptor canonicalEllipseDescriptor = new CanonicalEllipseDescriptor(radiusX, radiusY); Point2D[] correctedToEllipsePoints = this.CorrectPointsToCanonicalEllipse(points2D, canonicalEllipseDescriptor); this.EllipsePoints = correctedToEllipsePoints; CircleDescriptor circleDescriptor = new CircleDescriptor(new Point2D(0, 0), radiusX); Point2D[] correctedToCirclePoints = this.StretchToCircleAlongAxisY(correctedToEllipsePoints, circleDescriptor, 0); return(correctedToCirclePoints); }