public Dictionary <int, int> Compare(ImageDescriptors referenceImage, ImageDescriptors targetImage, double threshold)
        {
            Dictionary <int, int> result = new Dictionary <int, int>();

            for (int i = 0; i < targetImage.Count; i++)
            {
                IndexValue <double>[] temp = new IndexValue <double> [referenceImage.Count];

                for (int j = 0; j < referenceImage.Count; j++)
                {
                    temp[j] = new IndexValue <double>(j, Descriptor.CalculateAngle(referenceImage[j], targetImage[i]));
                }

                SortAlgorithm.Heapsort <IndexValue <double> >(ref temp, SortDirection.Descending);

                if (temp[0].Value.Equals(double.NaN))
                {
                    throw new NotImplementedException();
                }

                if (temp[0].Value / temp[1].Value < threshold)
                {
                    result.Add(i, temp[0].Index);
                }
            }

            return(result);
        }
Beispiel #2
0
        private void Test()
        {
            System.Diagnostics.Stopwatch watch = System.Diagnostics.Stopwatch.StartNew();

            Random r = new Random();

            int[] array10k = Enumerable.Repeat(0, 10000).Select(i => r.Next()).ToArray();

            SortAlgorithm.Heapsort <int>(array10k, (p1, p2) => p1.CompareTo(p2));

            watch.Stop();
            Debug.WriteLine($"Heapsort, {array10k.Length}, {watch.ElapsedMilliseconds / 1000.0}");
            watch.Restart();

            SortAlgorithm.MergeSort <int>(array10k, (p1, p2) => p1.CompareTo(p2));

            watch.Stop();
            Debug.WriteLine($"MergeSort, {array10k.Length}, {watch.ElapsedMilliseconds / 1000.0}");
            watch.Restart();

            SortAlgorithm.QuickSort <int>(array10k, (p1, p2) => p1.CompareTo(p2));

            watch.Stop();
            Debug.WriteLine($"QuickSort, {array10k.Length}, {watch.ElapsedMilliseconds / 1000.0}");
            watch.Restart();

            SortAlgorithm.BubbleSort <int>(array10k, (p1, p2) => p1.CompareTo(p2));

            watch.Stop();
            Debug.WriteLine($"BubbleSort, {array10k.Length}, {watch.ElapsedMilliseconds / 1000.0}");
            watch.Restart();
        }
        public int FindMatch(ImageDescriptors image, double threshold)
        {
            List <IndexValue <double> > values = CalculateSimilariry(image, threshold);

            SortAlgorithm.Heapsort <IndexValue <double> >(ref values, SortDirection.Ascending);

            return(values[0].Index);
        }
Beispiel #4
0
        /// <summary>
        /// Chen and Guevara 77
        /// </summary>
        /// <param name="numberOfPoints"></param>
        /// <returns></returns>
        public AttributedPointCollection SelectPointsBaesdOnCAG(int numberOfPoints)
        {
            int numberOfRow = this.NumberOfRows;

            int numberOfColumns = this.NumberOfColumns;

            IndexValue <double>[] significanceValues = new IndexValue <double> [numberOfRow * numberOfColumns];

            for (int i = 1; i < numberOfRow - 1; i++)
            {
                for (int j = 1; j < numberOfColumns - 1; j++)
                {
                    double first = CalculateSecondDifference(i, j, RasterDirection.EastWest);

                    double second = CalculateSecondDifference(i, j, RasterDirection.SouthNorth);

                    double third = CalculateSecondDifference(i, j, RasterDirection.NorthernWestSouthernEast);

                    double fourth = CalculateSecondDifference(i, j, RasterDirection.SouthernWestNorthernEast);

                    significanceValues[i * numberOfColumns + j] =
                        new IndexValue <double>(i * numberOfColumns + j, first + second + third + fourth);
                }
            }

            IndexValue <double>[] sortedSignificanceValues = SortAlgorithm.Heapsort <IndexValue <double> >(significanceValues, SortDirection.Ascending);

            AttributedPointCollection irregularPoints = new AttributedPointCollection();

            for (int i = 0; i < numberOfPoints; i++)
            {
                int row = (int)Math.Floor((double)sortedSignificanceValues[i].Index / numberOfColumns);

                int column = sortedSignificanceValues[i].Index % numberOfColumns;

                irregularPoints.Add(this.GetPoint(row, column));
            }

            //AddBorder
            irregularPoints.Add(this.LowerLeft);

            irregularPoints.Add(this.LoweRight);

            irregularPoints.Add(this.UpperLeft);

            irregularPoints.Add(this.UppeRight);

            return(irregularPoints);
        }
        public static List <int> GetConvexHullVertexes(PointCollection points)
        {
            int leftBoundIndex = points.LowerBoundIndex;

            IRI.Ket.Geometry.Point initialPoint = points[leftBoundIndex];

            int length = points.Count;

            IndexValue <double>[] list = new IndexValue <double> [length - 1];

            int counter = 0;

            for (int i = 0; i < length; i++)
            {
                if (i == leftBoundIndex)
                {
                    continue;
                }

                list[counter] = new IndexValue <double>(i,
                                                        Math.Atan2(points[i].Y - initialPoint.Y,
                                                                   points[i].X - initialPoint.X));
                counter++;
            }

            list = SortAlgorithm.Heapsort <IndexValue <double> >(list, SortDirection.Descending);

            List <int> result = new List <int>();

            result.Add(leftBoundIndex);

            counter = 0;

            while (counter < list.Length)
            {
                IRI.Ket.Geometry.Point tempPoint = points[list[counter].Index];

                if (result.Count < 2)
                {
                    result.Add(list[counter].Index);

                    counter++;

                    continue;
                }

                PointVectorRelation pointSituation = GetPointVectorRelation(tempPoint,
                                                                            points[result[result.Count - 2]],
                                                                            points[result[result.Count - 1]]);

                if (pointSituation == PointVectorRelation.LiesLeft)
                {
                    result.Add(list[counter].Index);

                    counter++;
                }
                else if (pointSituation == PointVectorRelation.LiesRight)
                {
                    result.RemoveAt(result.Count - 1);
                }
                else
                {
                    if (list[counter].Value == list[0].Value &&
                        CalculateDistance(initialPoint, tempPoint) > CalculateDistance(initialPoint, points[result[result.Count - 1]]))
                    {
                        result.Add(list[counter].Index);

                        counter++;
                    }
                    else if (list[counter].Value == list[length - 2].Value &&
                             CalculateDistance(initialPoint, tempPoint) < CalculateDistance(initialPoint, points[result[result.Count - 1]]))
                    {
                        result.Add(list[counter].Index);

                        counter++;
                    }
                    else
                    {
                        result.RemoveAt(result.Count - 1);
                    }
                }
            }

            return(result);
        }
        public static PointCollection CreateConvexHull(PointCollection points)
        {
            int leftBoundIndex = points.LowerBoundIndex;

            IRI.Ket.Geometry.Point initialPoint = points[leftBoundIndex];

            int length = points.Count;

            IndexValue <double>[] unsortedPoints = new IndexValue <double> [length - 1];

            int counter = 0;

            for (int i = 0; i < length; i++)
            {
                if (i == leftBoundIndex)
                {
                    continue;
                }

                unsortedPoints[counter] = new IndexValue <double>(i,
                                                                  Math.Atan2(points[i].Y - initialPoint.Y,
                                                                             points[i].X - initialPoint.X));
                counter++;
            }

            IndexValue <double>[] sortedPoints = SortAlgorithm.Heapsort <IndexValue <double> >(unsortedPoints, SortDirection.Descending);

            IRI.Ket.Geometry.PointCollection result = new IRI.Ket.Geometry.PointCollection();

            result.Add(points[leftBoundIndex]);

            counter = 0;

            while (counter < sortedPoints.Length)
            {
                IRI.Ket.Geometry.Point tempPoint = points[sortedPoints[counter].Index];

                if (result.Count < 2)
                {
                    result.Add(tempPoint);

                    counter++;

                    continue;
                }

                PointVectorRelation pointSituation = GetPointVectorRelation(tempPoint, result[result.Count - 2], result[result.Count - 1]);

                if (pointSituation == PointVectorRelation.LiesLeft)
                {
                    result.Add(tempPoint);

                    counter++;
                }
                else if (pointSituation == PointVectorRelation.LiesRight)
                {
                    result.RemoveAt(result.Count - 1);
                }
                else
                {
                    if (sortedPoints[counter].Value == sortedPoints[0].Value)
                    {
                        if (CalculateDistance(initialPoint, tempPoint) > CalculateDistance(initialPoint, result[result.Count - 1]))
                        {
                            result.Add(tempPoint);
                        }

                        counter++;
                    }
                    else if (sortedPoints[counter].Value == sortedPoints[length - 2].Value)
                    {
                        if (CalculateDistance(initialPoint, tempPoint) < CalculateDistance(initialPoint, result[result.Count - 1]))
                        {
                            result.Add(tempPoint);
                        }

                        counter++;
                    }
                    else
                    {
                        result.RemoveAt(result.Count - 1);
                    }
                }
            }

            return(result);
        }
Beispiel #7
0
        public static Point[] MooreSorter(Point[] array)
        {
            Boundary boundary = GetBoundary(array, 5);

            return(SortAlgorithm.Heapsort <Point>(array, (p1, p2) => MooreComparer(p1, p2, boundary)));
        }
Beispiel #8
0
        public static Point[] UOrderOrLebesgueSquareSorter(Point[] array)
        {
            Boundary boundary = GetBoundary(array, 5);

            return(SortAlgorithm.Heapsort <Point>(array, (p1, p2) => UOrderOrLebesgueSquareComparer(p1, p2, boundary)));
        }
Beispiel #9
0
        public static Point[] DiagonalLebesgueSorter(Point[] array)
        {
            Boundary boundary = GetBoundary(array, 5);

            return(SortAlgorithm.Heapsort <Point>(array, (p1, p2) => DiagonalLebesgueComparer(p1, p2, boundary)));
        }