Ejemplo n.º 1
0
 public TurboMatrix(SubMatrix from)
 {
     if (from.Height != DATA.letterHeight || from.Width != DATA.letterWidth)
     {
         Console.WriteLine("WARNING: create turbo matrix from non suitable SubMatrix, not in standard size");
     }
     matrix = new List <List <int> >(from.Height);
     Task[] tasks = new Task[from.Height];
     for (int y = 0; y < from.Height; ++y)
     {
         matrix[y].Add(from.Get(0, y) ? 1 : 0);
         tasks[y] = Task.Factory.StartNew(
             (cord) => matrix[(int)cord].AddRange(CountIntervalsinARow(from, (int)cord)), y);
     }
     Task.WaitAll(tasks);
 }
Ejemplo n.º 2
0
        public static float EqualPixelRatio(SubMatrix lhs, ImageMatrix rhs)
        {
            int eq = 0;

            for (int x = 0; x < lhs.Width; ++x)
            {
                for (int y = 0; y < lhs.Height; ++y)
                {
                    if (!(rhs.Get(x, y) ^ lhs.Get(x, y)))
                    {
                        eq++;
                    }
                }
            }
            return((float)eq / (lhs.Width * lhs.Height));
        }
Ejemplo n.º 3
0
        public Bitmap CreateImageOutOfMatrix(SubMatrix matrix)
        {
            if (matrix == null)
            {
                return(CreateSpace());
            }
            Bitmap map = new Bitmap(matrix.Width, matrix.Height);

            for (int x = 0; x < matrix.Width; ++x)
            {
                for (int y = 0; y < matrix.Height; ++y)
                {
                    map.SetPixel(x, y, matrix.Get(x, y) ? Color.Black : Color.White);
                }
            }
            return(map);
        }
Ejemplo n.º 4
0
        private List <int> CountIntervalsinARow(SubMatrix mat, int y)
        {
            List <int>        counter        = new List <int>();
            int               currentCounter = 0;
            Func <bool, bool> choser;

            if (mat.Get(0, y))
            {
                choser = BlackApprover;
            }
            else
            {
                choser = WhiteApprover;
            }
            for (int x = 0; x < mat.Width; ++x)
            {
                if (choser(mat.Get(x, y)))
                {
                    currentCounter++;
                }
                else
                {
                    if (choser == BlackApprover)
                    {
                        choser = WhiteApprover;
                    }
                    else
                    {
                        choser = BlackApprover;
                    }
                    counter.Add(currentCounter);
                    currentCounter = 0;
                }
            }
            if (currentCounter > 0)
            {
                counter.Add(currentCounter);
            }
            return(counter);
        }
Ejemplo n.º 5
0
 public SubMatrixTools(SubMatrix mat)
 {
     matrix = mat;
 }