示例#1
0
        public static JamaMatrix Polynomialize(JamaMatrix values, int degree)
        {
            JamaMatrix jamaMatrix  = PolyExps(degree);
            JamaMatrix jamaMatrix2 = new JamaMatrix(values.RowDimension, jamaMatrix.RowDimension);

            for (int i = 0; i < jamaMatrix.RowDimension; i++)
            {
                for (int j = 0; j < values.RowDimension; j++)
                {
                    jamaMatrix2.SetElement(j,
                                           i,
                                           Math.Pow(values.GetElement(j, 0), jamaMatrix.GetElement(i, 0)) *
                                           Math.Pow(values.GetElement(j, 1), jamaMatrix.GetElement(i, 1)));
                }
            }

            JamaMatrix jamaMatrix3 = new JamaMatrix(jamaMatrix2.RowDimension * 2, jamaMatrix2.ColumnDimension * 2);

            jamaMatrix3.setMatrix(0, jamaMatrix2.RowDimension - 1, 0, jamaMatrix2.ColumnDimension - 1, jamaMatrix2);
            jamaMatrix3.setMatrix(jamaMatrix2.RowDimension,
                                  2 * jamaMatrix2.RowDimension - 1,
                                  jamaMatrix2.ColumnDimension,
                                  2 * jamaMatrix2.ColumnDimension - 1,
                                  jamaMatrix2);
            return(jamaMatrix3);
        }
        public override void doTransform(PointD p0, PointD p1)
        {
            JamaMatrix jamaMatrix = new JamaMatrix(1, 2);

            jamaMatrix.SetElement(0, 0, p0.x);
            jamaMatrix.SetElement(0, 1, p0.y);
            JamaMatrix jamaMatrix2 = Polynomialize(jamaMatrix, polynomialDegree).times(matrix);

            p1.x = jamaMatrix2.GetElement(0, 0);
            p1.y = jamaMatrix2.GetElement(1, 0);
        }
示例#3
0
        public override void writeToXml(XmlTextWriter writer)
        {
            JamaMatrix jamaMatrix = PolyExps(polynomialDegree);

            string[] array = new[] { "x", "y" };
            for (int i = 0; i < 2; i++)
            {
                writer.WriteStartElement("Sum");
                writer.WriteAttributeString("Name", array[i]);
                for (int j = 0; j < jamaMatrix.RowDimension; j++)
                {
                    writer.WriteStartElement("Term");
                    writer.WriteAttributeString("Coefficient",
                                                transformCoefficients.GetElement(i * jamaMatrix.RowDimension + j, 0)
                                                .ToString(CultureInfo.InvariantCulture));
                    for (int k = 0; k < 2; k++)
                    {
                        writer.WriteAttributeString(array[k] + "_power",
                                                    jamaMatrix.GetElement(j, k).ToString(CultureInfo.InvariantCulture));
                    }

                    writer.WriteEndElement();
                }

                writer.WriteEndElement();
            }
        }
        private static JamaMatrix PseudoInverseBySVD(JamaMatrix gm)
        {
            if (gm.RowDimension < gm.ColumnDimension)
            {
                JamaMatrix gm2        = gm.transpose();
                JamaMatrix jamaMatrix = PolynomialImageTransformer.PseudoInverseBySVD(gm2);
                return(jamaMatrix.transpose());
            }
            if (gm.RowDimension == gm.ColumnDimension)
            {
                return(gm.inverse());
            }
            SingularValueDecomposition singularValueDecomposition = new SingularValueDecomposition(gm);
            JamaMatrix jamaMatrix2 = singularValueDecomposition.S.transpose();

            for (int i = 0; i < jamaMatrix2.RowDimension; i++)
            {
                double element = jamaMatrix2.GetElement(i, i);
                if (element != 0.0)
                {
                    jamaMatrix2.SetElement(i, i, 1.0 / element);
                }
            }
            return(singularValueDecomposition.getV().times(jamaMatrix2).times(singularValueDecomposition.getU().transpose()));
        }
示例#5
0
        public static double Min(JamaMatrix gm)
        {
            bool   flag = true;
            double num  = 0.0;

            if (gm.RowDimension * gm.ColumnDimension <= 0)
            {
                throw new Exception("No elements.");
            }

            for (int i = 0; i < gm.RowDimension; i++)
            {
                for (int j = 0; j < gm.ColumnDimension; j++)
                {
                    double element = gm.GetElement(i, j);
                    if (flag || element < num)
                    {
                        num  = element;
                        flag = false;
                    }
                }
            }

            return(num);
        }
 public FastPoly2PointTransformer(JamaMatrix matrix) : base(matrix)
 {
     polynomialDegree = 2;
     for (int i = 0; i < 12; i++)
     {
         c[i] = matrix.GetElement(i, 0);
     }
 }
 public FastPoly1PointTransformer(JamaMatrix matrix) : base(matrix)
 {
     this.polynomialDegree = 1;
     for (int i = 0; i < 6; i++)
     {
         this.c[i] = matrix.GetElement(i, 0);
     }
 }
 public Affine2DPointTransformer(JamaMatrix matrix)
 {
     c0 = matrix.GetElement(0, 0);
     c1 = matrix.GetElement(0, 1);
     c2 = matrix.GetElement(0, 2);
     c3 = matrix.GetElement(1, 0);
     c4 = matrix.GetElement(1, 1);
     c5 = matrix.GetElement(1, 2);
 }
示例#9
0
 public Affine2DPointTransformer(JamaMatrix matrix)
 {
     this.c0 = matrix.GetElement(0, 0);
     this.c1 = matrix.GetElement(0, 1);
     this.c2 = matrix.GetElement(0, 2);
     this.c3 = matrix.GetElement(1, 0);
     this.c4 = matrix.GetElement(1, 1);
     this.c5 = matrix.GetElement(1, 2);
 }