Example #1
0
        public static Matrix <double> GetBestModel(AffineRegionsPairs pairs, Transformation transformation)
        {
            Matrix <double> bestModel = null;
            double          bestScore = 0;

            for (int i = 0; i < ITERATION_NUM; i++)
            {
                List <AffineRegionsPair> samples = transformation.GetRandomSample(pairs);
                Matrix <double>          model   = transformation.CalculateModel(samples);
                double score = 0;

                foreach (AffineRegionsPair pair in pairs.Pairs)
                {
                    double error = transformation.ModelError(model, pair);
                    if (error < MAX_ERROR)
                    {
                        score++;
                    }
                }

                if (score > bestScore)
                {
                    bestScore = score;
                    bestModel = model;
                }
            }

            return(bestModel);
        }
Example #2
0
        static void Main(string[] args)
        {
            string firstImageName  = "podloga300";
            string secondImageName = "stol300";

            // pairs with whichever similarity
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            AffineRegionsPairs affineRegionsPairs = new AffineRegionsPairs(firstImageName + ".png.haraff.sift", secondImageName + ".png.haraff.sift");

            stopwatch.Stop();
            Console.WriteLine("Liczba par: " + affineRegionsPairs.Pairs.Count + ", czas wyznaczania par: " + stopwatch.ElapsedMilliseconds / 1000d + "s");

            List <(Point, Point)> lines = affineRegionsPairs.GetPairsAsPointsTuples();

            // pairs with high similarity
            AffineRegionsPairs highSimilarityPairs = affineRegionsPairs.GetPairsWithHighSimilarity(0.95);

            Console.WriteLine("Liczba par z wysokim podobieństwem: " + highSimilarityPairs.Pairs.Count);

            stopwatch.Restart();
            Matrix <double>          affineModel       = RANSAC.GetBestModel(highSimilarityPairs, new AffineTransformation());
            List <AffineRegionsPair> properAffinePairs = RANSAC.GetProperPairs(affineRegionsPairs, affineModel, new AffineTransformation());

            stopwatch.Stop();
            Console.WriteLine("Liczba poprawnych par (według transformaty afinicznej): " + properAffinePairs.Count + ", czas sprawdzania par: " + stopwatch.ElapsedMilliseconds / 1000d + "s");

            stopwatch.Restart();
            Matrix <double>          homographyModel       = RANSAC.GetBestModel(highSimilarityPairs, new HomographyTransformation());
            List <AffineRegionsPair> properHomographyPairs = RANSAC.GetProperPairs(affineRegionsPairs, homographyModel, new HomographyTransformation());

            stopwatch.Stop();
            Console.WriteLine("Liczba poprawnych par (według transformaty homograficznej): " + properHomographyPairs.Count + ", czas sprawdzania par: " + stopwatch.ElapsedMilliseconds / 1000d + "s");



            List <(Point, Point)> properAffineLines = properAffinePairs.Select(p => (new Point((int)p.FirstImageRegion.X, (int)p.FirstImageRegion.Y),
                                                                                     new Point((int)p.SecondImageRegion.X, (int)p.SecondImageRegion.Y))).ToList();

            List <(Point, Point)> properHomographyLines = properHomographyPairs.Select(p => (new Point((int)p.FirstImageRegion.X, (int)p.FirstImageRegion.Y),
                                                                                             new Point((int)p.SecondImageRegion.X, (int)p.SecondImageRegion.Y))).ToList();

            Image firstImage  = Image.FromFile(firstImageName + ".png");
            Image secondImage = Image.FromFile(secondImageName + ".png");

            Application.EnableVisualStyles();
            Application.Run(new ImagesDisplay(firstImage, secondImage,
                                              lines,
                                              properAffineLines,
                                              properHomographyLines
                                              ));
        }
Example #3
0
        public static List <AffineRegionsPair> GetProperPairs(AffineRegionsPairs pairs, Matrix <double> model, Transformation transformation)
        {
            List <AffineRegionsPair> properPairs = new List <AffineRegionsPair>();

            foreach (AffineRegionsPair pair in pairs.Pairs)
            {
                double error = transformation.ModelError(model, pair);
                if (error < MAX_ERROR)
                {
                    properPairs.Add(pair);
                }
            }

            return(properPairs);
        }
Example #4
0
        public List <AffineRegionsPair> GetRandomSample(AffineRegionsPairs pairs, int samplesNum)
        {
            List <AffineRegionsPair> samples = new List <AffineRegionsPair>();

            for (int i = 0; i < samplesNum; i++)
            {
                AffineRegionsPair pair;
                do
                {
                    pair = pairs.GetRandom();
                } while (samples.Contains(pair));
                samples.Add(pair);
            }

            return(samples);
        }
Example #5
0
 public abstract List <AffineRegionsPair> GetRandomSample(AffineRegionsPairs pairs);
 public override List <AffineRegionsPair> GetRandomSample(AffineRegionsPairs pairs)
 {
     return(GetRandomSample(pairs, 3));
 }