Ejemplo n.º 1
0
        public void Filter(SkeletonBuilder skeleton)
        {
            foreach (SkeletonBuilder.Minutia minutia in skeleton.Minutiae)
            {
                if (minutia.Ridges.Count == 2 && minutia.Ridges[0].Reversed != minutia.Ridges[1])
                {
                    SkeletonBuilder.Ridge extended = minutia.Ridges[0].Reversed;
                    SkeletonBuilder.Ridge removed = minutia.Ridges[1];
                    if (extended.Points.Count < removed.Points.Count)
                    {
                        Calc.Swap(ref extended, ref removed);
                        extended = extended.Reversed;
                        removed = removed.Reversed;
                    }

                    extended.Points.RemoveAt(extended.Points.Count - 1);
                    foreach (Point point in removed.Points)
                        extended.Points.Add(point);

                    extended.End = removed.End;
                    removed.Detach();
                }
            }
            DotRemover.Filter(skeleton);
            Logger.Log(skeleton);
        }
Ejemplo n.º 2
0
 public void Filter(SkeletonBuilder skeleton)
 {
     foreach (SkeletonBuilder.Minutia minutia in skeleton.Minutiae)
     {
         if (minutia.Ridges.Count == 3)
         {
             for (int exit = 0; exit < 3; ++exit)
             {
                 SkeletonBuilder.Ridge exitRidge = minutia.Ridges[exit];
                 SkeletonBuilder.Ridge arm1 = minutia.Ridges[(exit + 1) % 3];
                 SkeletonBuilder.Ridge arm2 = minutia.Ridges[(exit + 2) % 3];
                 if (arm1.End == arm2.End && exitRidge.End != arm1.End && arm1.End != minutia && exitRidge.End != minutia)
                 {
                     SkeletonBuilder.Minutia end = arm1.End;
                     if (end.Ridges.Count == 3 && arm1.Points.Count <= MaxArmLength && arm2.Points.Count <= MaxArmLength)
                     {
                         arm1.Detach();
                         arm2.Detach();
                         SkeletonBuilder.Ridge merged = new SkeletonBuilder.Ridge();
                         merged.Start = minutia;
                         merged.End = end;
                         foreach (Point point in Calc.ConstructLine(minutia.Position, end.Position))
                             merged.Points.Add(point);
                     }
                     break;
                 }
             }
         }
     }
     KnotRemover.Filter(skeleton);
     Logger.Log(skeleton);
 }
Ejemplo n.º 3
0
        public void Filter(SkeletonBuilder skeleton)
        {
            PriorityQueueF<Gap> queue = new PriorityQueueF<Gap>();
            foreach (SkeletonBuilder.Minutia end1 in skeleton.Minutiae)
                if (end1.Ridges.Count == 1 && end1.Ridges[0].Points.Count >= MinEndingLength)
                    foreach (SkeletonBuilder.Minutia end2 in skeleton.Minutiae)
                        if (end2 != end1 && end2.Ridges.Count == 1 && end1.Ridges[0].End != end2
                            && end2.Ridges[0].Points.Count >= MinEndingLength && IsWithinLimits(end1, end2))
                        {
                            Gap gap;
                            gap.End1 = end1;
                            gap.End2 = end2;
                            queue.Enqueue(Calc.DistanceSq(end1.Position, end2.Position), gap);
                        }

            BinaryMap shadow = SkeletonShadow.Draw(skeleton);
            while (queue.Count > 0)
            {
                Gap gap = queue.Dequeue();
                if (gap.End1.Ridges.Count == 1 && gap.End2.Ridges.Count == 1)
                {
                    Point[] line = Calc.ConstructLine(gap.End1.Position, gap.End2.Position);
                    if (!IsOverlapping(line, shadow))
                        AddRidge(skeleton, shadow, gap, line);
                }
            }

            KnotRemover.Filter(skeleton);
            Logger.Log(skeleton);
        }
Ejemplo n.º 4
0
        public object Clone()
        {
            SkeletonBuilder clone = new SkeletonBuilder();

            Dictionary<Minutia, Minutia> minutiaClones = new Dictionary<Minutia, Minutia>();
            foreach (Minutia minutia in AllMinutiae)
            {
                Minutia minutiaClone = new Minutia(minutia.Position);
                minutiaClone.Valid = minutia.Valid;
                clone.AddMinutia(minutiaClone);
                minutiaClones[minutia] = minutiaClone;
            }

            Dictionary<Ridge, Ridge> ridgeClones = new Dictionary<Ridge, Ridge>();
            foreach (Minutia minutia in AllMinutiae)
            {
                foreach (Ridge ridge in minutia.Ridges)
                {
                    if (!ridgeClones.ContainsKey(ridge))
                    {
                        Ridge ridgeClone = new Ridge();
                        ridgeClone.Start = minutiaClones[ridge.Start];
                        ridgeClone.End = minutiaClones[ridge.End];
                        foreach (Point point in ridge.Points)
                            ridgeClone.Points.Add(point);
                        ridgeClones[ridge] = ridgeClone;
                        ridgeClones[ridge.Reversed] = ridgeClone.Reversed;
                    }
                }
            }
            return clone;
        }
Ejemplo n.º 5
0
 Point GetAngleSample(SkeletonBuilder.Minutia minutia)
 {
     SkeletonBuilder.Ridge ridge = minutia.Ridges[0];
     if (AngleSampleOffset < ridge.Points.Count)
         return ridge.Points[AngleSampleOffset];
     else
         return ridge.End.Position;
 }
Ejemplo n.º 6
0
 public void Trace(BinaryMap binary, SkeletonBuilder skeleton)
 {
     List<Point> minutiaPoints = FindMinutiae(binary);
     Dictionary<Point, List<Point>> linking = LinkNeighboringMinutiae(minutiaPoints);
     Dictionary<Point, SkeletonBuilder.Minutia> minutiaMap = ComputeMinutiaCenters(linking, skeleton);
     TraceRidges(binary, minutiaMap);
     FixLinkingGaps(skeleton);
     Logger.Log(skeleton);
 }
Ejemplo n.º 7
0
 public void Filter(SkeletonBuilder skeleton)
 {
     foreach (SkeletonBuilder.Minutia minutia in skeleton.Minutiae)
     {
         if (minutia.Ridges.Count > 2)
             minutia.Valid = false;
     }
     Logger.Log(skeleton);
 }
Ejemplo n.º 8
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);
 }
Ejemplo n.º 9
0
 public void Filter(SkeletonBuilder skeleton)
 {
     List<SkeletonBuilder.Minutia> removed = new List<SkeletonBuilder.Minutia>();
     foreach (SkeletonBuilder.Minutia minutia in skeleton.Minutiae)
         if (minutia.Ridges.Count == 0)
             removed.Add(minutia);
     foreach (SkeletonBuilder.Minutia minutia in removed)
         skeleton.RemoveMinutia(minutia);
     Logger.Log(skeleton);
 }
Ejemplo n.º 10
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);
     }
 }
Ejemplo n.º 11
0
 public void Filter(SkeletonBuilder skeleton)
 {
     foreach (SkeletonBuilder.Minutia minutia in skeleton.Minutiae)
     {
         if (minutia.Ridges.Count == 1 && minutia.Ridges[0].End.Ridges.Count >= 3)
             if (minutia.Ridges[0].Points.Count < MinTailLength)
                 minutia.Ridges[0].Detach();
     }
     DotRemover.Filter(skeleton);
     KnotRemover.Filter(skeleton);
     Logger.Log(skeleton);
 }
Ejemplo n.º 12
0
 public Size GetSize(SkeletonBuilder skeleton)
 {
     RectangleC rect = new RectangleC(0, 0, 1, 1);
     foreach (SkeletonBuilder.Minutia minutia in skeleton.Minutiae)
     {
         rect.Include(minutia.Position);
         foreach (SkeletonBuilder.Ridge ridge in minutia.Ridges)
             if (ridge.Start.Position.Y <= ridge.End.Position.Y)
                 foreach (Point point in ridge.Points)
                     rect.Include(point);
     }
     return rect.Size;
 }
Ejemplo n.º 13
0
 public void FixLinkingGaps(SkeletonBuilder skeleton)
 {
     foreach (SkeletonBuilder.Minutia minutia in skeleton.Minutiae)
     {
         foreach (SkeletonBuilder.Ridge ridge in minutia.Ridges)
         {
             if (ridge.Points[0] != minutia.Position)
             {
                 Point[] filling = Calc.ConstructLine(ridge.Points[0], minutia.Position);
                 for (int i = 1; i < filling.Length; ++i)
                     ridge.Reversed.Points.Add(filling[i]);
             }
         }
     }
 }
Ejemplo n.º 14
0
        public void Filter(SkeletonBuilder skeleton)
        {
            ////Testing Start
            //Count++;
            //var inFileDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), "skeletonInput" + Count + ".bin");
            //var outFileDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), "skeletonInput" + Count + ".bin");
            //var file = new FileStream(inFileDir, FileMode.OpenOrCreate);
            //var binWrite = new BinaryWriter(file);

            //foreach (var i in skeleton.Minutiae)
            //{
            //    binWrite.Write(i.Valid);
            //    Console.WriteLine("Input Valid: " + i.Valid);
            //    binWrite.Write(i.Position.X);
            //    Console.WriteLine("Postion X: " + i.Position.X);
            //    binWrite.Write(i.Position.Y);
            //    Console.WriteLine("Position Y: " + i.Position.Y);

            //    foreach (var ridge in i.Ridges)
            //    {
            //        binWrite.Write(ridge.Start.Position.X);
            //        Console.WriteLine("Postion X: " + ridge.Start.Position.X);
            //        binWrite.Write(ridge.Start.Position.Y);
            //        Console.WriteLine("Position Y: " + ridge.Start.Position.Y);
            //        binWrite.Write(ridge.End.Position.X);
            //        Console.WriteLine("Postion X: " + ridge.End.Position.X);
            //        binWrite.Write(ridge.End.Position.Y);
            //        Console.WriteLine("Position Y: " + ridge.End.Position.Y);
            //        foreach (var point in ridge.Points)
            //        {
            //            binWrite.Write(point.X);
            //            binWrite.Write(point.Y);
            //        }
            //    }
            //    Console.WriteLine(i);
            //}
            //binWrite.Close();
            //file.Close();
            ////Testing Finish

            List<SkeletonBuilder.Minutia> removed = new List<SkeletonBuilder.Minutia>();
            foreach (SkeletonBuilder.Minutia minutia in skeleton.Minutiae)
                if (minutia.Ridges.Count == 0)
                    removed.Add(minutia);
            foreach (SkeletonBuilder.Minutia minutia in removed)
                skeleton.RemoveMinutia(minutia);
            Logger.Log(skeleton);
        }
Ejemplo n.º 15
0
 public void Filter(SkeletonBuilder skeleton)
 {
     foreach (SkeletonBuilder.Minutia minutia in skeleton.Minutiae)
     {
         if (minutia.Ridges.Count == 1 && minutia.Ridges[0].End.Ridges.Count >= 3)
         {
             if (minutia.Ridges[0].Points.Count < MinTailLength)
             {
                 minutia.Ridges[0].Detach();
             }
         }
     }
     DotRemover.Filter(skeleton);
     KnotRemover.Filter(skeleton);
     Logger.Log(skeleton);
 }
Ejemplo n.º 16
0
 public void Filter(SkeletonBuilder skeleton)
 {
     foreach (SkeletonBuilder.Minutia minutia in skeleton.Minutiae)
     {
         if (minutia.Ridges.Count == 1)
         {
             SkeletonBuilder.Ridge ridge = minutia.Ridges[0];
             if (ridge.End.Ridges.Count == 1 && ridge.Points.Count < MinFragmentLength)
             {
                 ridge.Detach();
             }
         }
     }
     DotRemover.Filter(skeleton);
     Logger.Log(skeleton);
 }
Ejemplo n.º 17
0
 public void FixLinkingGaps(SkeletonBuilder skeleton)
 {
     foreach (SkeletonBuilder.Minutia minutia in skeleton.Minutiae)
     {
         foreach (SkeletonBuilder.Ridge ridge in minutia.Ridges)
         {
             if (ridge.Points[0] != minutia.Position)
             {
                 Point[] filling = Calc.ConstructLine(ridge.Points[0], minutia.Position);
                 for (int i = 1; i < filling.Length; ++i)
                 {
                     ridge.Reversed.Points.Add(filling[i]);
                 }
             }
         }
     }
 }
Ejemplo n.º 18
0
        public void Filter(SkeletonBuilder skeleton)
        {
            List <SkeletonBuilder.Minutia> removed = new List <SkeletonBuilder.Minutia>();

            foreach (SkeletonBuilder.Minutia minutia in skeleton.Minutiae)
            {
                if (minutia.Ridges.Count == 0)
                {
                    removed.Add(minutia);
                }
            }
            foreach (SkeletonBuilder.Minutia minutia in removed)
            {
                skeleton.RemoveMinutia(minutia);
            }
            Logger.Log(skeleton);
        }
Ejemplo n.º 19
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);
                 }
             }
         }
     }
 }
Ejemplo n.º 20
0
        public Size GetSize(SkeletonBuilder skeleton)
        {
            RectangleC rect = new RectangleC(0, 0, 1, 1);

            foreach (SkeletonBuilder.Minutia minutia in skeleton.Minutiae)
            {
                rect.Include(minutia.Position);
                foreach (SkeletonBuilder.Ridge ridge in minutia.Ridges)
                {
                    if (ridge.Start.Position.Y <= ridge.End.Position.Y)
                    {
                        foreach (Point point in ridge.Points)
                        {
                            rect.Include(point);
                        }
                    }
                }
            }
            return(rect.Size);
        }
Ejemplo n.º 21
0
 Dictionary<Point, SkeletonBuilder.Minutia> ComputeMinutiaCenters(Dictionary<Point, List<Point>> linking, SkeletonBuilder skeleton)
 {
     Dictionary<Point, SkeletonBuilder.Minutia> centers = new Dictionary<Point, SkeletonBuilder.Minutia>();
     foreach (Point currentPos in linking.Keys)
     {
         List<Point> linkedMinutiae = linking[currentPos];
         Point primaryPos = linkedMinutiae[0];
         if (!centers.ContainsKey(primaryPos))
         {
             Point sum = new Point();
             foreach (Point linkedPos in linkedMinutiae)
                 sum = Calc.Add(sum, linkedPos);
             Point center = new Point(sum.X / linkedMinutiae.Count, sum.Y / linkedMinutiae.Count);
             SkeletonBuilder.Minutia minutia = new SkeletonBuilder.Minutia(center);
             skeleton.AddMinutia(minutia);
             centers[primaryPos] = minutia;
         }
         centers[currentPos] = centers[primaryPos];
     }
     return centers;
 }
Ejemplo n.º 22
0
        public void Filter(SkeletonBuilder skeleton)
        {
            PriorityQueueF <Gap> queue = new PriorityQueueF <Gap>();

            foreach (SkeletonBuilder.Minutia end1 in skeleton.Minutiae)
            {
                if (end1.Ridges.Count == 1 && end1.Ridges[0].Points.Count >= MinEndingLength)
                {
                    foreach (SkeletonBuilder.Minutia end2 in skeleton.Minutiae)
                    {
                        if (end2 != end1 && end2.Ridges.Count == 1 && end1.Ridges[0].End != end2 &&
                            end2.Ridges[0].Points.Count >= MinEndingLength && IsWithinLimits(end1, end2))
                        {
                            Gap gap;
                            gap.End1 = end1;
                            gap.End2 = end2;
                            queue.Enqueue(Calc.DistanceSq(end1.Position, end2.Position), gap);
                        }
                    }
                }
            }

            BinaryMap shadow = SkeletonShadow.Draw(skeleton);

            while (queue.Count > 0)
            {
                Gap gap = queue.Dequeue();
                if (gap.End1.Ridges.Count == 1 && gap.End2.Ridges.Count == 1)
                {
                    Point[] line = Calc.ConstructLine(gap.End1.Position, gap.End2.Position);
                    if (!IsOverlapping(line, shadow))
                    {
                        AddRidge(skeleton, shadow, gap, line);
                    }
                }
            }

            KnotRemover.Filter(skeleton);
            Logger.Log(skeleton);
        }
Ejemplo n.º 23
0
        public object Clone()
        {
            SkeletonBuilder clone = new SkeletonBuilder();

            Dictionary <Minutia, Minutia> minutiaClones = new Dictionary <Minutia, Minutia>();

            foreach (Minutia minutia in AllMinutiae)
            {
                Minutia minutiaClone = new Minutia(minutia.Position);
                minutiaClone.Valid = minutia.Valid;
                clone.AddMinutia(minutiaClone);
                minutiaClones[minutia] = minutiaClone;
            }

            Dictionary <Ridge, Ridge> ridgeClones = new Dictionary <Ridge, Ridge>();

            foreach (Minutia minutia in AllMinutiae)
            {
                foreach (Ridge ridge in minutia.Ridges)
                {
                    if (!ridgeClones.ContainsKey(ridge))
                    {
                        Ridge ridgeClone = new Ridge();
                        ridgeClone.Start = minutiaClones[ridge.Start];
                        ridgeClone.End   = minutiaClones[ridge.End];
                        foreach (Point point in ridge.Points)
                        {
                            ridgeClone.Points.Add(point);
                        }
                        ridgeClones[ridge]          = ridgeClone;
                        ridgeClones[ridge.Reversed] = ridgeClone.Reversed;
                    }
                }
            }

            return(clone);
        }
Ejemplo n.º 24
0
        SkeletonBuilder ProcessSkeleton(string name, BinaryMap binary)
        {
            SkeletonBuilder skeleton = null;

            DetailLogger.RunInContext(name, delegate ()
            {
                Logger.Log("Binarized", binary);
                BinaryMap thinned = Thinner.Thin(binary);
                skeleton = new SkeletonBuilder();
                RidgeTracer.Trace(thinned, skeleton);

                ////Testing Start
                //var outFileDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), "outputSkeletonRidgeTracer-" + name + DateTime.UtcNow.Millisecond + ".bin");
                //var file = new FileStream(outFileDir, FileMode.CreateNew);
                //var binWrite = new BinaryWriter(file);
                //binWrite.Write(skeleton.Minutiae.Count());
                //Console.WriteLine(skeleton.Minutiae.Count());
                //foreach (var minutia in skeleton.Minutiae)
                //{
                //    binWrite.Write(minutia.Valid);
                //    Console.WriteLine(minutia.Valid);
                //    binWrite.Write(minutia.Position.X);
                //    Console.WriteLine(minutia.Position.X);
                //    binWrite.Write(minutia.Position.Y);
                //    Console.WriteLine(minutia.Position.Y);
                //    binWrite.Write(minutia.Ridges.Count);
                //    Console.WriteLine(minutia.Ridges.Count);
                //}
                //binWrite.Close();
                //file.Close();
                ////Testing Finish

                DotRemover.Filter(skeleton);
                PoreRemover.Filter(skeleton);
                GapRemover.Filter(skeleton);
                TailRemover.Filter(skeleton);
                FragmentRemover.Filter(skeleton);
                BranchMinutiaRemover.Filter(skeleton);
            });
            Count++;
            return skeleton;
        }
Ejemplo n.º 25
0
        Dictionary <Point, SkeletonBuilder.Minutia> ComputeMinutiaCenters(Dictionary <Point, List <Point> > linking, SkeletonBuilder skeleton)
        {
            Dictionary <Point, SkeletonBuilder.Minutia> centers = new Dictionary <Point, SkeletonBuilder.Minutia>();

            foreach (Point currentPos in linking.Keys)
            {
                List <Point> linkedMinutiae = linking[currentPos];
                Point        primaryPos     = linkedMinutiae[0];
                if (!centers.ContainsKey(primaryPos))
                {
                    Point sum = new Point();
                    foreach (Point linkedPos in linkedMinutiae)
                    {
                        sum = Calc.Add(sum, linkedPos);
                    }
                    Point center = new Point(sum.X / linkedMinutiae.Count, sum.Y / linkedMinutiae.Count);
                    SkeletonBuilder.Minutia minutia = new SkeletonBuilder.Minutia(center);
                    skeleton.AddMinutia(minutia);
                    centers[primaryPos] = minutia;
                }
                centers[currentPos] = centers[primaryPos];
            }
            return(centers);
        }
Ejemplo n.º 26
0
 SkeletonBuilder ProcessSkeleton(string name, BinaryMap binary)
 {
     SkeletonBuilder skeleton = null;
     DetailLogger.RunInContext(name, delegate()
     {
         Logger.Log("Binarized", binary);
         BinaryMap thinned = Thinner.Thin(binary);
         skeleton = new SkeletonBuilder();
         RidgeTracer.Trace(thinned, skeleton);
         DotRemover.Filter(skeleton);
         PoreRemover.Filter(skeleton);
         GapRemover.Filter(skeleton);
         TailRemover.Filter(skeleton);
         FragmentRemover.Filter(skeleton);
         BranchMinutiaRemover.Filter(skeleton);
     });
     return skeleton;
 }
Ejemplo n.º 27
0
 public BinaryMap Draw(SkeletonBuilder skeleton)
 {
     BinaryMap binary = new BinaryMap(GetSize(skeleton));
     Draw(skeleton, binary);
     return binary;
 }
Ejemplo n.º 28
0
        bool IsWithinLimits(SkeletonBuilder.Minutia end1, SkeletonBuilder.Minutia end2)
        {
            int distanceSq = Calc.DistanceSq(end1.Position, end2.Position);
            if (distanceSq <= Calc.Sq(RuptureSize))
                return true;
            if (distanceSq > Calc.Sq(GapSize))
                return false;

            byte gapDirection = Angle.AtanB(end1.Position, end2.Position);
            byte direction1 = Angle.AtanB(end1.Position, GetAngleSample(end1));
            if (Angle.Distance(direction1, Angle.Opposite(gapDirection)) > GapAngle)
                return false;
            byte direction2 = Angle.AtanB(end2.Position, GetAngleSample(end2));
            if (Angle.Distance(direction2, gapDirection) > GapAngle)
                return false;
            return true;
        }