Example #1
0
        public void TestScaleDescaleComparison()
        {
            int width  = 100;
            int height = 100;

            bool[][] mat     = new bool[width][];
            var      rEngine = new Random();

            for (int x = 0; x < mat.Length; ++x)
            {
                mat[x] = new bool[height];
                for (int y = 0; y < mat[x].Length; ++y)
                {
                    mat[x][y] = rEngine.Next(2) == 1 ? true : false;
                }
            }
            ImageMatrix matrix   = new ImageMatrix(mat);
            var         creator  = new ImageCreator();
            var         scaled   = MatrixTools.Scale(matrix, 50, 50);
            var         descaled = MatrixTools.Scale(scaled, 100, 100);
            float       s        = MatrixTools.EqualPixelRatio(descaled, matrix);

            if (s > 0.5)
            {
                Console.WriteLine("TEST_Scaling: Passed, scale equality: " + s.ToString());
            }
            else
            {
                Console.WriteLine("TEST_Scaling: fail, scale equality: " + s.ToString());
            }
        }
Example #2
0
        private char MatchLetter(ImageMatrix letter, IEnumerable <ImageMatrix> matchers)
        {
            char  theOne   = '_';
            float theRatio = 0;

            foreach (var m in matchers)
            {
                float ratio = MatrixTools.EqualPixelRatio(m, letter);
                if (ratio > theRatio)
                {
                    theRatio = ratio;
                    theOne   = m.Character;
                }
            }
            return(theOne);
        }
Example #3
0
        public void TestImageMatrixReadAndWrite()
        {
            PrepareImage();
            ImageCreator creator    = new ImageCreator();
            string       matrixFile = simplePageUrl.Replace(".png", "MAT.txt");

            matrix.ToFullMatrix().SaveMatrixToFile(matrixFile);
            var   mat   = new ImageMatrix(matrixFile);
            float ratio = MatrixTools.EqualPixelRatio(matrix, mat);

            if (ratio > 0.995)
            {
                Console.WriteLine("TEST_MatrixR/W: PASSED, ratio: " + ratio.ToString());
            }
            else
            {
                Console.WriteLine("TEST_MatrixR/W: FAIL, compare ratio: " + ratio.ToString());
            }
            matrixFile = matrixFile.Replace(".txt", ".png");
            creator.CreateImageOutOfMatrix(mat).Save(matrixFile);
        }