예제 #1
0
        //----------------------------------------------------------------------------------------------
        //----------------------------------------------------------------------------------------------
        //----------------------------------------------------------------------------------------------
        public PlaneDescriptor Approximate(params Point3D[] points)
        {
            int        n       = 3;
            RealMatrix matrixA = new RealMatrix(points.Length, n);

            for (int index = 0; index < points.Length; index++)
            {
                Point3D point = points[index];

                matrixA[index, 0] = 1;
                matrixA[index, 1] = point.X;
                matrixA[index, 2] = point.Y;
            }

            RealVector vectorZ = new RealVector(SpaceManager.GetCoordinatesZ(points));

            RealMatrix transposedMatrixA  = matrixA.GetTransposedMatrix();
            RealVector coefficientsVector =
                (transposedMatrixA * matrixA).GetInverseMatrix() * transposedMatrixA * vectorZ;

            double d = coefficientsVector[0];
            double a = coefficientsVector[1];
            double b = coefficientsVector[2];

            double coefficientOfX = a / d;
            double coefficientOfY = b / d;
            double coefficientOfZ = -1 / d;
            double absoluteTerm   = 1;

            PlaneDescriptor planeDescriptor =
                new PlaneDescriptor(coefficientOfX, coefficientOfY, coefficientOfZ, absoluteTerm);

            return(planeDescriptor);
        }
예제 #2
0
        //------------------------------------------------------------------------------------------------
        //Фильтрация изображения
        public RealMatrix ExecuteFiltration(
            RealMatrix grayScaleIntensityMatrix, int stepX, int stepY
            )
        {
            RealMatrix filteredRowsMatrix = this.FiltrateGrayScaleImageRows
                                                (grayScaleIntensityMatrix, stepX);
            RealMatrix transposedFilteredRowsMatrix = filteredRowsMatrix.GetTransposedMatrix();
            RealMatrix filteredColumnsMatrix        =
                this.FiltrateGrayScaleImageRows(transposedFilteredRowsMatrix, stepY);
            RealMatrix resultMatrix = filteredColumnsMatrix.GetTransposedMatrix();

            return(resultMatrix);
        }
예제 #3
0
        //---------------------------------------------------------------------------------------
        //Аппроксимировать
        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);
        }
예제 #4
0
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //Interface Methods
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public static Pi_Class1.Plane getPlaneParams(List<Point3D> pointsOfPlane)
        {
            /*int a = 1;
            int b = 2;
            int c = -3;
            int d = 1;
            pointsOfPlane = new List<Point3D>();

            for (int x = 0; x < 4; x++)
            {
                for (int y = 0; y < 4; y++)
                {
                    var newPoint = new Point3D(x, y, -(x*a + y*b + d)/c);
                    pointsOfPlane.Add(newPoint);
                }
            }*/

            var result = new Pi_Class1.Plane();

            var initMatrix = new double[pointsOfPlane.Count(),4];

            for (int j = 0; j < pointsOfPlane.Count(); j++)
            {
                for (int i = 0; i < 4; i++)
                {
                    if (i == 0)
                    {
                        initMatrix[j, i] = pointsOfPlane[j].x;
                    }
                    else if (i == 1)
                    {
                        initMatrix[j, i] = pointsOfPlane[j].y;
                    }
                    else if (i == 2)
                    {
                        initMatrix[j, i] = pointsOfPlane[j].z;
                    }
                    else if (i == 3)
                    {
                        initMatrix[j, i] = 1;
                    }
                }
            }

            var initialMatrix = new RealMatrix(initMatrix);
            var transposedMatrix = initialMatrix.GetTransposedMatrix();
            var multMatrix = transposedMatrix*initialMatrix;

            double deter = multMatrix.GetDeterminant();
            //RealMatrix conjMatrix = multMatrix.GetAlgebraicalComplement()

            var complementData = new double[4,4];
            for (int j = 0; j < 4; j++)
            {
                for (int i = 0; i < 4; i++)
                {
                    complementData[j, i] = multMatrix.GetAlgebraicalComplement(j, i);
                }
            }

            var complementMatrix = new RealMatrix(complementData);

            RealMatrix transposedMatrix2 = complementMatrix.GetTransposedMatrix();
            RealMatrix obrMatrix = transposedMatrix2*(1.0/deter);

            var onesVector = new double[4,1];
            onesVector[0, 0] = 1;
            onesVector[1, 0] = 1;
            onesVector[2, 0] = 1;
            onesVector[3, 0] = 1;

            var onesMatrix = new RealMatrix(onesVector);
            RealMatrix resultMatrix = obrMatrix*onesMatrix;

            double[,] resultData = resultMatrix.GetDataArray();
            result.a = resultData[0, 0];
            result.b = resultData[1, 0];
            result.c = resultData[2, 0];
            result.d = resultData[3, 0];

            result.a = result.a/result.d;
            result.b = result.b / result.d;
            result.c = result.c / result.d;
            result.d = result.d / result.d;

            /*List<Point3D> pointsOfPlane2 = new List<Point3D>();

            for (double x = 0; x < 4; x++)
            {
                for (double y = 0; y < 4; y++)
                {
                    var newPoint = new Point3D((int) x, (int) y, (int) ((x * result.a + y * result.b + result.d) / result.c));
                    pointsOfPlane2.Add(newPoint);
                }
            }*/

            return result;
        }