示例#1
0
        public BinaryMap Binarize(float[,] input, float[,] baseline, BinaryMap mask, BlockMap blocks)
        {
            BinaryMap binarized = new BinaryMap(input.GetLength(1), input.GetLength(0));

            Parallel.For(0, blocks.AllBlocks.Height, delegate(int blockY)
            {
                for (int blockX = 0; blockX < blocks.AllBlocks.Width; ++blockX)
                {
                    if (mask.GetBit(blockX, blockY))
                    {
                        RectangleC rect = blocks.BlockAreas[blockY, blockX];
                        for (int y = rect.Bottom; y < rect.Top; ++y)
                        {
                            for (int x = rect.Left; x < rect.Right; ++x)
                            {
                                if (input[y, x] - baseline[y, x] > 0)
                                {
                                    binarized.SetBitOne(x, y);
                                }
                            }
                        }
                    }
                }
            });
            Logger.Log(binarized);
            return(binarized);
        }
示例#2
0
 public void Draw(SkeletonBuilder skeleton, BinaryMap binary)
 {
     foreach (SkeletonBuilder.Minutia minutia in skeleton.Minutiae)
     {
         binary.SetBitOne(minutia.Position);
         foreach (SkeletonBuilder.Ridge ridge in minutia.Ridges)
         {
             if (ridge.Start.Position.Y <= ridge.End.Position.Y)
             {
                 foreach (Point point in ridge.Points)
                 {
                     binary.SetBitOne(point);
                 }
             }
         }
     }
 }
示例#3
0
 void AddRidge(SkeletonBuilder skeleton, BinaryMap shadow, Gap gap, Point[] line)
 {
     SkeletonBuilder.Ridge ridge = new SkeletonBuilder.Ridge();
     foreach (Point point in line)
     {
         ridge.Points.Add(point);
     }
     ridge.Start = gap.End1;
     ridge.End   = gap.End2;
     foreach (Point point in line)
     {
         shadow.SetBitOne(point);
     }
 }
示例#4
0
        public BinaryMap DetectLowContrast(byte[,] contrast)
        {
            BinaryMap result = new BinaryMap(contrast.GetLength(1), contrast.GetLength(0));

            for (int y = 0; y < result.Height; ++y)
            {
                for (int x = 0; x < result.Width; ++x)
                {
                    if (contrast[y, x] < Limit)
                    {
                        result.SetBitOne(x, y);
                    }
                }
            }
            Logger.Log(result);
            return(result);
        }
示例#5
0
        public BinaryMap DetectLowContrast(byte[,] contrast, BlockMap blocks)
        {
            List <byte> sortedContrast = new List <byte>();

            foreach (byte contrastItem in contrast)
            {
                sortedContrast.Add(contrastItem);
            }
            sortedContrast.Sort();
            sortedContrast.Reverse();

            int pixelsPerBlock   = Calc.GetArea(blocks.PixelCount) / blocks.AllBlocks.TotalArea;
            int sampleCount      = Math.Min(sortedContrast.Count, SampleSize / pixelsPerBlock);
            int consideredBlocks = Math.Max(Convert.ToInt32(sampleCount * SampleFraction), 1);

            int averageContrast = 0;

            for (int i = 0; i < consideredBlocks; ++i)
            {
                averageContrast += sortedContrast[i];
            }
            averageContrast /= consideredBlocks;
            byte limit = Convert.ToByte(averageContrast * RelativeLimit);

            BinaryMap result = new BinaryMap(blocks.BlockCount.Width, blocks.BlockCount.Height);

            for (int y = 0; y < result.Height; ++y)
            {
                for (int x = 0; x < result.Width; ++x)
                {
                    if (contrast[y, x] < limit)
                    {
                        result.SetBitOne(x, y);
                    }
                }
            }
            Logger.Log(result);
            return(result);
        }
示例#6
0
        public BinaryMap Filter(BinaryMap input)
        {
            RectangleC rect = new RectangleC(new Point(BorderDistance, BorderDistance),
                                             new Size(input.Width - 2 * BorderDistance, input.Height - 2 * BorderDistance));
            BinaryMap output = new BinaryMap(input.Size);

            Parallel.For(rect.RangeY.Begin, rect.RangeY.End, delegate(int y)
            {
                for (int x = rect.Left; x < rect.Right; ++x)
                {
                    RectangleC neighborhood = new RectangleC(
                        new Point(Math.Max(x - Radius, 0), Math.Max(y - Radius, 0)),
                        new Point(Math.Min(x + Radius + 1, output.Width), Math.Min(y + Radius + 1, output.Height)));

                    int ones = 0;
                    for (int ny = neighborhood.Bottom; ny < neighborhood.Top; ++ny)
                    {
                        for (int nx = neighborhood.Left; nx < neighborhood.Right; ++nx)
                        {
                            if (input.GetBit(nx, ny))
                            {
                                ++ones;
                            }
                        }
                    }

                    double voteWeight = 1.0 / neighborhood.TotalArea;
                    if (ones * voteWeight >= Majority)
                    {
                        output.SetBitOne(x, y);
                    }
                }
            });
            Logger.Log(output);
            return(output);
        }
示例#7
0
        public BinaryMap Thin(BinaryMap input)
        {
            BinaryMap intermediate = new BinaryMap(input.Size);

            intermediate.Copy(input, new RectangleC(1, 1, input.Width - 2, input.Height - 2), new Point(1, 1));

            BinaryMap border          = new BinaryMap(input.Size);
            BinaryMap skeleton        = new BinaryMap(input.Size);
            bool      removedAnything = true;

            for (int i = 0; i < MaxIterations && removedAnything; ++i)
            {
                removedAnything = false;
                for (int j = 0; j < 4; ++j)
                {
                    border.Copy(intermediate);
                    switch (j)
                    {
                    case 0:
                        border.AndNot(intermediate, new RectangleC(1, 0, border.Width - 1, border.Height), new Point(0, 0));
                        break;

                    case 1:
                        border.AndNot(intermediate, new RectangleC(0, 0, border.Width - 1, border.Height), new Point(1, 0));
                        break;

                    case 2:
                        border.AndNot(intermediate, new RectangleC(0, 1, border.Width, border.Height - 1), new Point(0, 0));
                        break;

                    case 3:
                        border.AndNot(intermediate, new RectangleC(0, 0, border.Width, border.Height - 1), new Point(0, 1));
                        break;
                    }
                    border.AndNot(skeleton);

                    for (int odd = 0; odd < 2; ++odd)
                    {
                        Parallel.For(1, input.Height - 1, delegate(int y)
                        {
                            if (y % 2 == odd)
                            {
                                for (int xw = 0; xw < input.WordWidth; ++xw)
                                {
                                    if (border.IsWordNonZero(xw, y))
                                    {
                                        for (int x = xw << BinaryMap.WordShift; x < (xw << BinaryMap.WordShift) + BinaryMap.WordSize; ++x)
                                        {
                                            if (x > 0 && x < input.Width - 1 && border.GetBit(x, y))
                                            {
                                                uint neighbors = intermediate.GetNeighborhood(x, y);
                                                if (IsRemovable[neighbors] ||
                                                    IsEnding[neighbors] && IsFalseEnding(intermediate, new Point(x, y)))
                                                {
                                                    removedAnything = true;
                                                    intermediate.SetBitZero(x, y);
                                                }
                                                else
                                                {
                                                    skeleton.SetBitOne(x, y);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        });
                    }
                }
            }

            Logger.Log(skeleton);
            return(skeleton);
        }
示例#8
0
        public BinaryMap Filter(BinaryMap input)
        {
            ////Testing Start
            //Count++;
            //var inFileDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), "inputBinary" + Count + ".bin");
            //var outFileDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), "outputBinary" + Count + ".bin");
            //var file = new FileStream(inFileDir, FileMode.CreateNew);
            //var binWrite = new BinaryWriter(file);
            //binWrite.Write(input.WordWidth);
            //Console.WriteLine(input.WordWidth);
            //binWrite.Write(input.Width);
            //Console.WriteLine(input.Width);
            //binWrite.Write(input.Height);
            //Console.WriteLine(input.Height);
            //foreach (var i in input.Map)
            //{
            //    binWrite.Write(i);
            //    Console.WriteLine(i);
            //}
            //binWrite.Close();
            //file.Close();
            ////Testing Finish

            RectangleC rect = new RectangleC(new Point(BorderDistance, BorderDistance),
                                             new Size(input.Width - 2 * BorderDistance, input.Height - 2 * BorderDistance));
            BinaryMap output = new BinaryMap(input.Size);

            Parallel.For(rect.RangeY.Begin, rect.RangeY.End, delegate(int y)
            {
                for (int x = rect.Left; x < rect.Right; ++x)
                {
                    RectangleC neighborhood = new RectangleC(
                        new Point(Math.Max(x - Radius, 0), Math.Max(y - Radius, 0)),
                        new Point(Math.Min(x + Radius + 1, output.Width), Math.Min(y + Radius + 1, output.Height)));

                    int ones = 0;
                    for (int ny = neighborhood.Bottom; ny < neighborhood.Top; ++ny)
                    {
                        for (int nx = neighborhood.Left; nx < neighborhood.Right; ++nx)
                        {
                            if (input.GetBit(nx, ny))
                            {
                                ++ones;
                            }
                        }
                    }

                    double voteWeight = 1.0 / neighborhood.TotalArea;
                    if (ones * voteWeight >= Majority)
                    {
                        output.SetBitOne(x, y);
                    }
                }
            });
            Logger.Log(output);

            ////Testing
            //file = new FileStream(outFileDir, FileMode.CreateNew);
            //binWrite = new BinaryWriter(file);
            //binWrite.Write(output.WordWidth);
            //binWrite.Write(output.Width);
            //binWrite.Write(output.Height);
            //foreach (var i in output.Map)
            //{
            //    binWrite.Write(i);
            //}
            //binWrite.Close();
            //file.Close();
            ////Testing End

            return(output);
        }