private static string compareImagesToDefn(string dir, string pattern, string defFileName)
        {
            // "-r" = recursively search subdirectories for files that match pattern
            List <string> filenames = getFiles(dir, pattern);

            Console.WriteLine("Compare images to:  " + defFileName);
            Image defImage = new Image(32, 32);

            defImage.LoadImage(defFileName);

            string output = "";

            foreach (string fileName in filenames)
            {
                Console.WriteLine(fileName);
                Image testImage = new Image();
                testImage.LoadImage(fileName);
                Metrics.ImageDistance id = new Metrics.ImageDistance(defImage, testImage);
                double distance          = id.distance(Metrics.ImageDistance.HAUSDORFF);
                // output += defFileName.Replace(@"C:\Users\sketchers\Documents\Trunk\Data\TrainingResults\Context","") + ", ";
                // output += fileName.Replace(@"C:\Users\sketchers\Documents\Trunk\Data\Context Symbols\TEST","") + ", ";
                output += defFileName + ", ";
                output += fileName + ", ";

                output += distance + ", \n";
            }
            return(output);
        }
        private static string compareImagesByTestFile(string dir, string pattern, List <string> defFileNames)
        {
            // "-r" = recursively search subdirectories for files that match pattern
            List <string> testFiles = getFiles(dir, pattern);

            //Set up column headings
            string output = "Testfile , ";

            foreach (string df in defFileNames)
            {
                output += df + ", ";
            }
            output += "Best Guess, minDist, \n";

            foreach (string tf in testFiles)
            {
                Console.WriteLine(tf);
                Image testImage = new Image();
                testImage.LoadImage(tf);
                output += tf + ", ";
                double minDistance = Double.MaxValue;
                string bestGuess   = "NONE";
                foreach (string df in defFileNames)
                {
                    Image defImage = new Image(32, 32);
                    defImage.LoadImage(df);
                    Metrics.ImageDistance id = new Metrics.ImageDistance(defImage, testImage);
                    double distance          = id.distance(Metrics.ImageDistance.HAUSDORFF);
                    if (distance < minDistance)
                    {
                        minDistance = distance;
                        bestGuess   = df;
                    }
                    output += distance + ", ";
                }
                output += bestGuess + ", " + minDistance + ", \n";
            }
            return(output);
        }
Esempio n. 3
0
        /// <summary>
        /// Finds the amount to move each column by translating all of the columns and finding the best one.
        /// </summary>
        /// <param name="A">Image to match to</param>
        /// <param name="cols">Number of columns to best translation</param>
        /// <param name="dist">Best distance</param>
        public void findBestTranslation(DefinitionImage A, out int cols, out double bestDist)
        {
            double dist;

            bestDist = double.PositiveInfinity;
            cols     = -1;

            Image translated = new Image(this);

            Metrics.ImageDistance id;

            //Go over the potential column translations
            int i, len = _width;

            for (i = 0; i < len; ++i)
            {
                //Store the translation in translated
                TranslateMatrix(i, ref matrix, ref translated.matrix);


                //dist = id.distance(Metrics.ImageDistance.DIRECTEDMODIFIEDHAUSDORFF_AB);
                //dist = id.distance(Metrics.ImageDistance.TANIMOTO) + id.distance(Metrics.ImageDistance.YULE);
                //dist = id.distance(Metrics.ImageDistance.VERTICAL);
                //dist = id.distance(Metrics.ImageDistance.DIRECTEDHAUSDORFF_AB);
                //dist = id.distance(Metrics.ImageDistance.OVERLAPPING_AB);
                //dist = id.distance(Metrics.ImageDistance.HORIZONTAL);
                //id = new Metrics.ImageDistance(translated, A.Polar);
                //dist = id.distance(Metrics.ImageDistance.TANIMOTO) * id.distance(Metrics.ImageDistance.YULE);
                id   = new Metrics.ImageDistance(translated, A.PolarTransform);
                dist = id.distance(Metrics.ImageDistance.DIRECTEDMODIFIEDHAUSDORFF_AB);
                if (dist < bestDist)
                {
                    bestDist = dist;
                    cols     = i;
                }
            }
        }