Пример #1
0
            protected bool Equals(KLTranslation other)
            {
                var innerProduct = Math.Abs(Math.Abs(Matrix.InnerProduct(Translation, other.Translation)) - 1);

                if (innerProduct < 0.01)
                {
                    return(true);
                }
                return(false);
            }
Пример #2
0
 public bool ContainsRotation(double[] newRotation)
 {
     foreach (var rot in Rotation)
     {
         var innerProduct = Math.Abs(Math.Abs(Matrix.InnerProduct(rot.RotationAxis, newRotation)) - 1);
         if (innerProduct < 0.01)
         {
             return(true);
         }
     }
     return(false);
 }
Пример #3
0
 public bool ContainsTranslation(double[] newTranslation)
 {
     foreach (var trasl in Translation)
     {
         var innerProduct = Math.Abs(Math.Abs(Matrix.InnerProduct(trasl.Translation, newTranslation)) - 1);
         if (innerProduct < 0.01)
         {
             return(true);
         }
     }
     return(false);
 }
Пример #4
0
        public static Bezier CreateBezierRegression(List <Vector2> points)
        {
            float[] X = points.Select(x => x.X).ToArray();
            float[] Y = points.Select(x => x.Y).ToArray();

            float[][] T = ComputeTMatrix(X, Y);

            float[] resultX = Matrix.Multiply(Matrix.Multiply(Matrix.Multiply(Matrix.Inverse(M_Matrix), Matrix.Inverse(Matrix.Multiply(Matrix.Transpose(T), T))), Matrix.Transpose(T)), X);
            float[] resultY = Matrix.Multiply(Matrix.Multiply(Matrix.Multiply(Matrix.Inverse(M_Matrix), Matrix.Inverse(Matrix.Multiply(Matrix.Transpose(T), T))), Matrix.Transpose(T)), Y);

            return(new Bezier()
            {
                P1 = new Vector2(resultX[0], resultY[0]),
                C1 = new Vector2(resultX[1], resultY[1]),
                C2 = new Vector2(resultX[2], resultY[2]),
                P2 = new Vector2(resultX[3], resultY[3]),
            });
        }
Пример #5
0
            protected bool Equals(KLRotation other)
            {
                var innerProduct = Math.Abs(Math.Abs(Matrix.InnerProduct(RotationAxis, other.RotationAxis)) - 1);

                if (innerProduct < 0.01)
                {
                    if (RotationPoint != null && other.RotationPoint != null)
                    {
                        var pointDifferent = new double[]
                        {
                            RotationPoint[0] - other.RotationPoint[0], RotationPoint[1] - other.RotationPoint[1],
                            RotationPoint[2] - other.RotationPoint[2]
                        };
                        var norm = Norm.Euclidean(pointDifferent);
                        if (norm != 0.0)
                        {
                            pointDifferent = pointDifferent.Divide(norm);
                        }
                        else
                        {
                            return(true);
                        }
                        var innerProduct2 = Math.Abs(Math.Abs(Matrix.InnerProduct(RotationAxis, pointDifferent)) - 1);

                        //if (FolderUtilities.FolderUtilities.KLIsVectorNull(pointDifferent, 0.01))
                        //{
                        //    return true;
                        //}
                        //else
                        if (innerProduct2 < 0.01)
                        {
                            return(true);
                        }
                    }
                    else if (RotationPoint == null || other.RotationPoint == null)
                    {
                        return(true);
                    }
                }

                return(false);
            }
Пример #6
0
        /// <summary>
        ///   Computes the new image size.
        /// </summary>
        ///
        protected override Size CalculateNewImageSize(UnmanagedImage sourceData)
        {
            // Calculate source size
            float w = sourceData.Width;
            float h = sourceData.Height;

            // Get the four corners and the center of the image
            PointF[] corners =
            {
                new PointF(0,      0),
                new PointF(w,      0),
                new PointF(0,      h),
                new PointF(w,      h),
                new PointF(w / 2f, h / 2f)
            };

            // Project those points
            corners = homography.Inverse().TransformPoints(corners);

            // Recalculate image size
            float[] px = { corners[0].X, corners[1].X, corners[2].X, corners[3].X };
            float[] py = { corners[0].Y, corners[1].Y, corners[2].Y, corners[3].Y };

            float maxX     = Matrix.Max(px);
            float minX     = Matrix.Min(px);
            float newWidth = Math.Max(maxX, overlayImage.Width) - Math.Min(0, minX);

            float maxY      = Accord.Math.Matrix.Max(py);
            float minY      = Accord.Math.Matrix.Min(py);
            float newHeight = Math.Max(maxY, overlayImage.Height) - Math.Min(0, minY);


            // Store overlay image size
            this.imageSize = new Size((int)Math.Round(maxX - minX), (int)Math.Round(maxY - minY));

            // Store image center
            this.center = Point.Round(corners[4]);

            // Calculate and store image offset
            int offsetX = 0, offsetY = 0;

            if (minX < 0)
            {
                offsetX = (int)Math.Round(minX);
            }
            if (minY < 0)
            {
                offsetY = (int)Math.Round(minY);
            }

            this.offset = new Point(offsetX, offsetY);

            if (Double.IsNaN(newWidth) || newWidth == 0)
            {
                newWidth = 1;
            }

            if (Double.IsNaN(newHeight) || newHeight == 0)
            {
                newHeight = 1;
            }

            // Return the final image size
            return(new Size((int)Math.Ceiling(newWidth), (int)Math.Ceiling(newHeight)));
        }
Пример #7
0
 /// <summary>
 ///   Constructs a new Blend filter.
 /// </summary>
 ///
 /// <param name="overlayImage">The overlay image (also called the anchor).</param>
 ///
 public Blend(Bitmap overlayImage)
     : this(Matrix.Identity(3), overlayImage)
 {
 }
Пример #8
0
        static float[][] resampleBezierCurve(float[] c1, float[] c2, float[] c3, float[] c4, float[][] T)
        {
            float[][] C = new float[][] { c1, c2, c3, c4 };

            return(Matrix.Multiply(Matrix.Multiply(T, M_Matrix), C));
        }