TransformPoints() public method

Transforms the given points using this transformation matrix.
public TransformPoints ( ) : System.Drawing.PointF[]
return System.Drawing.PointF[]
Exemplo n.º 1
0
        /// <summary>
        ///   Compute inliers using the Symmetric Transfer Error,
        /// </summary>
        ///
        private int[] distance(MatrixH H, double t)
        {
            // Compute the projections (both directions)
            PointF[] p1 = H.TransformPoints(pointSet1);
            PointF[] p2 = H.Inverse().TransformPoints(pointSet2);

            // Compute the distances
            for (int i = 0; i < pointSet1.Length; i++)
            {
                // Compute the distance as
                float ax = pointSet1[i].X - p2[i].X;
                float ay = pointSet1[i].Y - p2[i].Y;
                float bx = pointSet2[i].X - p1[i].X;
                float by = pointSet2[i].Y - p1[i].Y;
                d2[i] = (ax * ax) + (ay * ay) + (bx * bx) + (by * by);
            }

            // Find and return the inliers
            return(Matrix.Find(d2, z => z < t));
        }
Exemplo n.º 2
0
        /// <summary>
        ///   Normalizes a set of homogeneous points so that the origin is located
        ///   at the centroid and the mean distance to the origin is sqrt(2).
        /// </summary>
        public static PointH[] Normalize(this PointH[] points, out MatrixH T)
        {
            float n = points.Length;
            float xmean = 0, ymean = 0;

            for (int i = 0; i < points.Length; i++)
            {
                points[i].X = points[i].X / points[i].W;
                points[i].Y = points[i].Y / points[i].W;
                points[i].W = 1;

                xmean += points[i].X;
                ymean += points[i].Y;
            }
            xmean /= n; ymean /= n;


            float scale = 0;

            for (int i = 0; i < points.Length; i++)
            {
                float x = points[i].X - xmean;
                float y = points[i].Y - ymean;

                scale += (float)System.Math.Sqrt(x * x + y * y);
            }

            scale = (float)(SQRT2 * n / scale);


            T = new MatrixH
                (
                scale, 0, -scale * xmean,
                0, scale, -scale * ymean,
                0, 0, 1
                );

            return(T.TransformPoints(points));
        }
Exemplo n.º 3
0
        /// <summary>
        ///   Compute inliers using the Symmetric Transfer Error,
        /// </summary>
        /// 
        private int[] distance(MatrixH H, double t)
        {
            // Compute the projections (both directions)
            PointF[] p1 = H.TransformPoints(pointSet1);
            PointF[] p2 = H.Inverse().TransformPoints(pointSet2);

            // Compute the distances
            for (int i = 0; i < pointSet1.Length; i++)
            {
                // Compute the distance as
                float ax = pointSet1[i].X - p2[i].X;
                float ay = pointSet1[i].Y - p2[i].Y;
                float bx = pointSet2[i].X - p1[i].X;
                float by = pointSet2[i].Y - p1[i].Y;
                d2[i] = (ax * ax) + (ay * ay) + (bx * bx) + (by * by);
            }

            // Find and return the inliers
            return Matrix.Find(d2, z => z < t);
        }
Exemplo n.º 4
0
        public void MultiplyTest()
        {
            MatrixH matrix = new MatrixH(Matrix.Identity(3));

            PointH[] points = new PointH[] 
            {
                new PointH(1, 2),
                new PointH(5, 2),
                new PointH(12, 2),
                new PointH(1, 2),
                new PointH(10, 2),
            };


            PointH[] expected = new PointH[] 
            {
                new PointH(1, 2),
                new PointH(5, 2),
                new PointH(12, 2),
                new PointH(1, 2),
                new PointH(10, 2),
            };

            PointH[] actual = (PointH[])points.Clone();
            matrix.TransformPoints(actual);

            Assert.AreEqual(expected[0], actual[0]);
            Assert.AreEqual(expected[1], actual[1]);
            Assert.AreEqual(expected[2], actual[2]);
            Assert.AreEqual(expected[3], actual[3]);
            Assert.AreEqual(expected[4], actual[4]);

        }