예제 #1
0
        public void CompareSimilarPatterns()
        {
            // Setup
            int bitsPerColour = 8;
            int tileSize = 16;
            int offsetX = 0;
            int offsetY = 0;

            //Bitmap croppedImage = Program.LoadImage(@"C:\Users\nicB\Documents\tileTest.png");
            Program.LoadImage(@"C:\Users\nicB\Documents\tileTest.png", tileSize, offsetX, offsetY);

            //int x = 0;
            //int y = 0;
            int index = 0;

            //Bitmap image1 = Program.GetTileImage(x, y, TileSize);
            Bitmap image1 = Program.GetTileImage(index);
            Tile tile1 = new Tile(image1, bitsPerColour, tileSize, index);
            Console.WriteLine("Tile 1: " + tile1.ToString());

            //x = 16;
            index = 1;
            //Bitmap image2 = Program.GetTileImage(x, y, TileSize);
            Bitmap image2 = Program.GetTileImage(index);
            Tile tile2 = new Tile(image2, bitsPerColour, tileSize, 1);
            Console.WriteLine("Tile 2: " + tile2.ToString());

            // Execution
            Tuple<float, float> results = tile1.GetMatches(tile2);
            float patternMatch = results.Item1;
            float colourMatch = results.Item2;

            bool identical = tile1.IdenticalTo(tile2);

            // Assertion
            float expectedPatternMatch = 223 / 255f;
            Assert.IsTrue(patternMatch == expectedPatternMatch, string.Format("Expected {0}, Actual {1}", expectedPatternMatch, patternMatch));

            Assert.IsFalse(identical);
        }
예제 #2
0
        private static TileGroupMatchResults FindMatchingGroupWithResults(Tile tileToCompare, float patternThreshold, float colourThreshold)
        {
            foreach (TileGroup group in allSortedTiles)
            {
                //int masterIndex = group.MasterIndex;
                //Tile Master = allSubImageTiles[MasterIndex];
                //Tile master = allSubImageTiles.ElementAt(masterIndex);
                Tile master = group.Master;
                Tuple<float, float> results = tileToCompare.GetMatches(master);
                float patternMatch = results.Item1;
                float colourMatch = results.Item2;

                bool areSimilar = Tile.SimilarTo(patternMatch, patternThreshold);
                if (areSimilar == false)
                {
                    continue;
                }

                return new TileGroupMatchResults(group, patternMatch, colourMatch);
            }

            return new TileGroupMatchResults();
        }
예제 #3
0
        public void CompareSimilarToMaster()
        {
            // Setup
            int bitsPerColour = 8;
            int accuracy = 2;
            int tileCount = 32;
            int tileSize = 16;
            int offsetX = 0;
            int offsetY = 0;

            //Bitmap canvas = Program.LoadImage(@"C:\Users\nicB\Documents\tileTest.png");
            Program.LoadImage(@"C:\Users\nicB\Documents\tileTest.png", tileSize, offsetX, offsetY);

            //int x = 0;
            //int y = 0;
            int index = 0;

            //Bitmap image1 = Program.GetTileImage(x, y, TileSize);
            Bitmap image1 = Program.GetTileImage(index);
            Tile master = new Tile(image1, bitsPerColour, tileSize, index);
            //Console.WriteLine("Tile 1: " + tileToDraw.ToString());

            Tile identicalTile = new Tile(image1, bitsPerColour, tileSize, index);

            //x = 16;
            index = 1;
            //Bitmap image2 = Program.GetTileImage(x, y, TileSize);
            Bitmap image2 = Program.GetTileImage(index);
            Tile similarTile = new Tile(image2, bitsPerColour, tileSize, index);
            //Console.WriteLine("Tile 2: " + similarTile.ToString());

            //x = 32;
            index = 2;
            //Bitmap image3 = Program.GetTileImage(x, y, TileSize);
            Bitmap image3 = Program.GetTileImage(index);
            Tile otherSimilarTile = new Tile(image3, bitsPerColour, tileSize, index);
            //Console.WriteLine("Tile 3: " + otherSimilarTile.ToString());

            Tuple<float, float> identicalResults = master.GetMatches(identicalTile);
            float patternMatch = identicalResults.Item1;
            float colourMatch = identicalResults.Item2;
            int identicalHashCode = Tile.GetHashcode(accuracy, patternMatch, colourMatch, tileCount);

            // Execution
            Tuple<float, float> similarResults = master.GetMatches(similarTile);
            patternMatch = similarResults.Item1;
            colourMatch = similarResults.Item2;
            int similarHashCode = Tile.GetHashcode(accuracy, patternMatch, colourMatch, tileCount);

            Tuple<float, float> otherSimilarResults = master.GetMatches(otherSimilarTile);
            patternMatch = similarResults.Item1;
            colourMatch = similarResults.Item2;
            int otherSimilarHashCode = Tile.GetHashcode(accuracy, patternMatch, colourMatch, tileCount);

            // Assertion
            Assert.IsTrue(identicalHashCode == 0, string.Format("Expected 0, Actual {0}", identicalHashCode));

            Assert.IsTrue(similarHashCode == otherSimilarHashCode, string.Format("Expected true, Actual {0} == {1}", similarHashCode, otherSimilarHashCode));
        }