Ejemplo n.º 1
0
        public PolynomialImageTransformer(RegistrationDefinition registration, InterpolationMode interpolationMode, int polynomialDegree) : base(registration, interpolationMode)
        {
            List <PositionAssociation> associationList = registration.GetAssociationList();
            TransformationStyle        arg_15_0        = registration.warpStyle;
            int num = associationList.Count;

            if (num == 2)
            {
                num++;
            }
            JamaMatrix jamaMatrix  = new JamaMatrix(num, 2);
            JamaMatrix jamaMatrix2 = new JamaMatrix(num, 2);

            for (int i = 0; i < num; i++)
            {
                LatLon latLon = (i == associationList.Count) ? PolynomialImageTransformer.getThirdPosition(associationList[0].sourcePosition.pinPosition.latlon, associationList[1].sourcePosition.pinPosition.latlon, true) : associationList[i].sourcePosition.pinPosition.latlon;
                jamaMatrix.SetElement(i, 0, latLon.lon);
                jamaMatrix.SetElement(i, 1, latLon.lat);
                LatLon latLon2 = (i == associationList.Count) ? PolynomialImageTransformer.getThirdPosition(MercatorCoordinateSystem.LatLonToMercator(associationList[0].globalPosition.pinPosition.latlon), MercatorCoordinateSystem.LatLonToMercator(associationList[1].globalPosition.pinPosition.latlon), false) : MercatorCoordinateSystem.LatLonToMercator(associationList[i].globalPosition.pinPosition.latlon);
                jamaMatrix2.SetElement(i, 0, latLon2.lon);
                jamaMatrix2.SetElement(i, 1, latLon2.lat);
            }
            this.destMercatorToSourceTransformer             = PolynomialImageTransformer.getPolyPointTransformer(jamaMatrix, jamaMatrix2, polynomialDegree);
            this.sourceToDestMercatorTransformer_approximate = PolynomialImageTransformer.getApproximateInverterPolyPointTransformer(jamaMatrix, jamaMatrix2, polynomialDegree);
            DownhillInverterPointTransformer flakyPointTransformer = new DownhillInverterPointTransformer(this.destMercatorToSourceTransformer, this.sourceToDestMercatorTransformer_approximate);
            IPointTransformer sourceToMercator = new RobustPointTransformer(flakyPointTransformer, this.sourceToDestMercatorTransformer_approximate);

            this.destLatLonToSourceTransformer = new LatLonToSourceTransform(this.destMercatorToSourceTransformer);
            this.sourceToDestLatLonTransformer = new SourceToLatLonTransform(sourceToMercator);
        }
        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);
        }
Ejemplo n.º 3
0
        private static JamaMatrix RegularUnitGrid(int size)
        {
            JamaMatrix jamaMatrix = new JamaMatrix(size * size, 2);

            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < size; j++)
                {
                    jamaMatrix.SetElement(i * size + j, 0, (double)j / (double)(size - 1));
                    jamaMatrix.SetElement(i * size + j, 1, (double)i / (double)(size - 1));
                }
            }
            return(jamaMatrix);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
        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()));
        }
Ejemplo n.º 6
0
		public HomographicImageTransformer(RegistrationDefinition registration, InterpolationMode interpolationMode) : base(registration, interpolationMode)
		{
			List<PositionAssociation> associationList = registration.GetAssociationList();
			TransformationStyle arg_15_0 = registration.warpStyle;
			int count = associationList.Count;
			JamaMatrix jamaMatrix = new JamaMatrix(count, 2);
			JamaMatrix jamaMatrix2 = new JamaMatrix(count, 2);
			for (int i = 0; i < count; i++)
			{
				LatLon latlon = associationList[i].sourcePosition.pinPosition.latlon;
				jamaMatrix.SetElement(i, 0, latlon.lon);
				jamaMatrix.SetElement(i, 1, latlon.lat);
				LatLon latLon = MercatorCoordinateSystem.LatLonToMercator(associationList[i].globalPosition.pinPosition.latlon);
				jamaMatrix2.SetElement(i, 0, latLon.lon);
				jamaMatrix2.SetElement(i, 1, latLon.lat);
			}
		}
Ejemplo n.º 7
0
        public static JamaMatrix PolyExps(int degree)
        {
            JamaMatrix jamaMatrix = new JamaMatrix((degree + 1) * (degree + 2) / 2, 2);
            int        num        = 0;

            for (int i = 0; i <= degree; i++)
            {
                for (int j = 0; j <= degree - i; j++)
                {
                    jamaMatrix.SetElement(num, 0, (double)i);
                    jamaMatrix.SetElement(num, 1, (double)j);
                    num++;
                }
            }
            D.Assert(num == jamaMatrix.RowDimension);
            return(jamaMatrix);
        }
Ejemplo n.º 8
0
        public static void TestFunc()
        {
            double[][] array    = new double[4][];
            double[][] arg_15_0 = array;
            int        arg_15_1 = 0;

            double[] array2 = new double[2];
            arg_15_0[arg_15_1] = array2;
            array[1]           = new double[]
            {
                1.02,
                0.93
            };
            array[2] = new double[]
            {
                0.0,
                1.0
            };
            double[][] arg_73_0 = array;
            int        arg_73_1 = 3;

            double[] array3 = new double[2];
            array3[0]          = 1.0;
            arg_73_0[arg_73_1] = array3;
            double[][] a          = array;
            JamaMatrix jamaMatrix = new JamaMatrix(a);

            PolynomialImageTransformer.RegularUnitGrid(4);
            JamaMatrix jamaMatrix2 = (JamaMatrix)jamaMatrix.Clone();

            jamaMatrix2.SetElement(1, 0, 1.0);
            jamaMatrix2.SetElement(1, 1, 1.0);
            JamaMatrix jamaMatrix3 = IPolyPointTransformer.Polynomialize(jamaMatrix, 2);
            JamaMatrix jamaMatrix4 = PolynomialImageTransformer.SVDSolveApply(jamaMatrix3, PolynomialImageTransformer.PointUnroll(jamaMatrix2));

            D.Say(0, "polyTransform:\n" + jamaMatrix4.ToString());
            JamaMatrix unrolledVector = jamaMatrix3.times(jamaMatrix4);

            D.Say(0, "testSolution:\n" + PolynomialImageTransformer.PointRoll(unrolledVector, 2).ToString());
            PolynomialImageTransformer.getPolyPointTransformer(jamaMatrix, jamaMatrix2, 2);
            LatLon p = new LatLon(0.93, 1.02);

            D.Say(0, "Invert test:\n" + PolynomialImageTransformer.getApproximateInverterPolyPointTransformer(jamaMatrix, jamaMatrix2, 2).getTransformedPoint(p).ToString());
        }
Ejemplo n.º 9
0
        private static JamaMatrix CornersToVectorMatrix(MapRectangle rect)
        {
            JamaMatrix jamaMatrix = new JamaMatrix(3, 4);

            jamaMatrix.SetElement(0, 0, rect.lon0);
            jamaMatrix.SetElement(0, 1, rect.lon0);
            jamaMatrix.SetElement(0, 2, rect.lon1);
            jamaMatrix.SetElement(0, 3, rect.lon1);
            jamaMatrix.SetElement(1, 0, rect.lat0);
            jamaMatrix.SetElement(1, 1, rect.lat1);
            jamaMatrix.SetElement(1, 2, rect.lat0);
            jamaMatrix.SetElement(1, 3, rect.lat1);
            jamaMatrix.SetElement(2, 0, 1.0);
            jamaMatrix.SetElement(2, 1, 1.0);
            jamaMatrix.SetElement(2, 2, 1.0);
            jamaMatrix.SetElement(2, 3, 1.0);
            return(jamaMatrix);
        }