Esempio n. 1
0
        /// <summary>
        ///     Computes Euclidean distance between the specified minutiae.
        /// </summary>
        /// <param name="m0">A minutia.</param>
        /// <param name="m1">A minutia.</param>
        /// <returns>
        ///     Distance computed from the specified minutiae.
        /// </returns>
        public double Compare(Minutia m0, Minutia m1)
        {
            double diff0 = m0.Y - m1.Y;
            double diff1 = m0.X - m1.X;

            return(Math.Sqrt(diff0 * diff0 + diff1 * diff1));
        }
 public MinutiaMapper(Minutia minutia)
 {
     Minutia t = new Minutia(0, 0, 0);
     dAngle = t.Angle - minutia.Angle;
     this.template = t;
     this.query = minutia;
 }
        public static List<Minutia> FromByteArray(byte[] data)
        {
            int cursor = 27;
            // Reading Number of Minutiae
            byte mtiaeCount = data[cursor++];
            List<Minutia> list = new List<Minutia>(mtiaeCount);
            // Reading minutiae
            for (int i = 0; i < mtiaeCount; i++, cursor += 6)
            {
                var mtiaTypeCode = (data[cursor] >> 6) & 3;
                var mtiaType = mtiaTypeCode == 0
                                   ? MinutiaType.Unknown
                                   : mtiaTypeCode == 1 ? MinutiaType.End : MinutiaType.Bifurcation;

                var x = ((data[cursor] & 63) << 8) | (data[cursor + 1]);
                var y = ((data[cursor + 2] & 63) << 8) | (data[cursor + 3]);
                var angle = Convert.ToDouble(2 * Math.PI - data[cursor + 4] * 2.0 * Math.PI / 255.0);

                var mtia = new Minutia
                {
                    MinutiaType = mtiaType,
                    X = (short)x,
                    Y = (short)y,
                    Angle = angle
                };
                list.Add(mtia);
            }

            return list;
        }
Esempio n. 4
0
        public static List <Minutia> FromByteArray(byte[] data)
        {
            int cursor = 27;
            // Reading Number of Minutiae
            byte           mtiaeCount = data[cursor++];
            List <Minutia> list       = new List <Minutia>(mtiaeCount);

            // Reading minutiae
            for (int i = 0; i < mtiaeCount; i++, cursor += 6)
            {
                var mtiaTypeCode = (data[cursor] >> 6) & 3;
                var mtiaType     = mtiaTypeCode == 0
                                   ? MinutiaType.Unknown
                                   : mtiaTypeCode == 1 ? MinutiaType.End : MinutiaType.Bifurcation;

                var x     = ((data[cursor] & 63) << 8) | (data[cursor + 1]);
                var y     = ((data[cursor + 2] & 63) << 8) | (data[cursor + 3]);
                var angle = Convert.ToDouble(2 * Math.PI - data[cursor + 4] * 2.0 * Math.PI / 255.0);

                var mtia = new Minutia
                {
                    MinutiaType = mtiaType,
                    X           = (short)x,
                    Y           = (short)y,
                    Angle       = angle
                };
                list.Add(mtia);
            }

            return(list);
        }
Esempio n. 5
0
        public MinutiaMapper(Minutia minutia)
        {
            Minutia t = new Minutia(0, 0, 0);

            dAngle        = t.Angle - minutia.Angle;
            this.template = t;
            this.query    = minutia;
        }
 internal GOwMtia(Minutia mnt, OrientationImage dImg)
 {
     Minutia = mnt;
     Segments = new Segment[6];
     for (int i = 0; i < Segments.Length; i++)
     {
         Segments[i] = new Segment(i * (2 * Math.PI / 6) + mnt.Angle, mnt, dImg);
     }
 }
 public Minutia Map(Minutia m)
 {
     return new Minutia
     {
         Angle = m.Angle + dAngle,
         X = Convert.ToInt16(Math.Round((m.X - query.X) * Math.Cos(dAngle) - (m.Y - query.Y) * Math.Sin(dAngle) + template.X)),
         Y = Convert.ToInt16(Math.Round((m.X - query.X) * Math.Sin(dAngle) + (m.Y - query.Y) * Math.Cos(dAngle) + template.Y))
     };
 }
Esempio n. 8
0
 public Minutia Map(Minutia m)
 {
     return(new Minutia
     {
         Angle = m.Angle + dAngle,
         X = Convert.ToInt16(Math.Round((m.X - query.X) * Math.Cos(dAngle) - (m.Y - query.Y) * Math.Sin(dAngle) + template.X)),
         Y = Convert.ToInt16(Math.Round((m.X - query.X) * Math.Sin(dAngle) + (m.Y - query.Y) * Math.Cos(dAngle) + template.Y))
     });
 }
Esempio n. 9
0
        public Minutia Map(Minutia m)
        {
            double newAngle = m.Angle + dAngle;
            double sin      = Math.Sin(dAngle);
            double cos      = Math.Cos(dAngle);

            return(new Minutia
            {
                Angle = (newAngle > 2 * Math.PI) ? newAngle - 2 * Math.PI : (newAngle < 0) ? newAngle + 2 * Math.PI : newAngle,
                X = Convert.ToInt16(Math.Round((m.X - query.X) * cos - (m.Y - query.Y) * sin + template.X)),
                Y = Convert.ToInt16(Math.Round((m.X - query.X) * sin + (m.Y - query.Y) * cos + template.Y))
            });
        }
        internal MtiaTriplet(Int16[] mIdxs, List<Minutia> minutiae)
        {
            this.minutiae = minutiae;
            mtiaIdxs = mIdxs;

            Minutia[] mtiaArr = new Minutia[3];
            mtiaArr[0] = minutiae[MtiaIdxs[0]];
            mtiaArr[1] = minutiae[MtiaIdxs[1]];
            mtiaArr[2] = minutiae[MtiaIdxs[2]];

            d[0] = dist.Compare(mtiaArr[0], mtiaArr[1]);
            d[1] = dist.Compare(mtiaArr[1], mtiaArr[2]);
            d[2] = dist.Compare(mtiaArr[0], mtiaArr[2]);
        }
Esempio n. 11
0
        private static Minutia MtiaFromByteArray(byte[] bytes)
        {
            var mtia = new Minutia();
            int info = (bytes[3] << 24) | (bytes[2] << 16) | (bytes[1] << 8) | bytes[0];

            mtia.MinutiaType = (MinutiaType)(3 & info);
            info           >>= 2;
            mtia.Angle       = 2 * Math.PI * (255 & info) / 255;
            info           >>= 8;
            mtia.Y           = Convert.ToInt16(info & 2047);
            info           >>= 11;
            mtia.X           = Convert.ToInt16(info & 2047);

            return(mtia);
        }
        internal OBMtiaDescriptor(Minutia mnt, OrientationImage dImg)
        {
            Minutia = mnt;
            //difRadio = (int) Math.Truncate((Resolution/25.4)*ridgePeriod*2);

            EmptyFeaturesCount = 0;
            Orientations = new double[72];
            for (int i = 0, j = 0; i < 4; i++)
            {
                var curr = GetOrientations(initRadio + i * difRadio, Minutia, dImg);
                for (int k = 0; k < curr.Length; k++)
                {
                    Orientations[j++] = curr[k];
                    if (double.IsNaN(curr[k]))
                        EmptyFeaturesCount++;
                }
            }
        }
Esempio n. 13
0
        public static MinutiaPair Compute(List <MinutiaPair> pairs)
        {
            double qX      = 0,
                   tX      = 0,
                   qY      = 0,
                   tY      = 0,
                   qAngleX = 0,
                   tAngleX = 0,
                   qAngleY = 0,
                   tAngleY = 0;

            foreach (var pair in pairs)
            {
                qX      += pair.QueryMtia.X;
                qY      += pair.QueryMtia.Y;
                qAngleX += Math.Cos(pair.QueryMtia.Angle);
                qAngleY += Math.Sin(pair.QueryMtia.Angle);

                tX      += pair.TemplateMtia.X;
                tY      += pair.TemplateMtia.Y;
                tAngleX += Math.Cos(pair.TemplateMtia.Angle);
                tAngleY += Math.Sin(pair.TemplateMtia.Angle);
            }
            int     n     = pairs.Count;
            Minutia qMtia = new Minutia()
            {
                Angle = Angle.ComputeAngle(qAngleX / n, qAngleY / n),
                X     = Convert.ToInt16(Math.Round(qX / n)),
                Y     = Convert.ToInt16(Math.Round(qY / n))
            };
            Minutia tMtia = new Minutia()
            {
                Angle = Angle.ComputeAngle(tAngleX / n, tAngleY / n),
                X     = Convert.ToInt16(Math.Round(tX / n)),
                Y     = Convert.ToInt16(Math.Round(tY / n))
            };

            return(new MinutiaPair()
            {
                QueryMtia = qMtia,
                TemplateMtia = tMtia
            });
        }
        public static MinutiaPair Compute(List<MinutiaPair> pairs)
        {
            double qX = 0,
                   tX = 0,
                   qY = 0,
                   tY = 0,
                   qAngleX = 0,
                   tAngleX = 0,
                   qAngleY = 0,
                   tAngleY = 0;
            foreach (var pair in pairs)
            {
                qX += pair.QueryMtia.X;
                qY += pair.QueryMtia.Y;
                qAngleX += Math.Cos(pair.QueryMtia.Angle);
                qAngleY += Math.Sin(pair.QueryMtia.Angle);

                tX += pair.TemplateMtia.X;
                tY += pair.TemplateMtia.Y;
                tAngleX += Math.Cos(pair.TemplateMtia.Angle);
                tAngleY += Math.Sin(pair.TemplateMtia.Angle);
            }
            int n = pairs.Count;
            Minutia qMtia = new Minutia()
            {
                Angle = Angle.ComputeAngle(qAngleX / n, qAngleY / n),
                X = Convert.ToInt16(Math.Round(qX / n)),
                Y = Convert.ToInt16(Math.Round(qY / n))
            };
            Minutia tMtia = new Minutia()
            {
                Angle = Angle.ComputeAngle(tAngleX / n, tAngleY / n),
                X = Convert.ToInt16(Math.Round(tX / n)),
                Y = Convert.ToInt16(Math.Round(tY / n))
            };
            return new MinutiaPair()
            {
                QueryMtia = qMtia,
                TemplateMtia = tMtia
            };
        }
 private double[] GetOrientations(int radio, Minutia mtia, OrientationImage dirImg)
 {
     double[] currOrientations = new double[radio / 3];
     int n = radio / 3;
     double incAng = 2 * Math.PI * 3.0 / radio;
     for (int i = 0; i < n; i++)
     {
         double myAng = mtia.Angle + i * incAng;
         if (myAng > 2 * Math.PI)
             myAng -= (double)(2 * Math.PI);
         Point pnt = SetPosToSPoint(myAng, radio, new Point(mtia.X, mtia.Y));
         int row, col;
         dirImg.GetBlockCoordFromPixel(pnt.X, pnt.Y, out row, out col);
         if ((col < 0) || (row < 0) || (row >= dirImg.Height) ||
             (col >= dirImg.Width) || (dirImg.IsNullBlock(row, col)))
             currOrientations[i] = double.NaN;
         else
             currOrientations[i] =
                 Math.Min(Angle.DifferencePi(mtia.Angle, dirImg.AngleInRadians(row, col)),
                          Angle.DifferencePi(mtia.Angle, dirImg.AngleInRadians(row, col) + Math.PI));
     }
     return currOrientations;
 }
Esempio n. 16
0
 internal Segment(double ang, Minutia mnt, OrientationImage dImg)
 {
     bool endOfPoints = false;
     int i = 1;
     List<double> points = new List<double>();
     while (!endOfPoints)
     {
         Point pnt = SetPosToSPoint(ang, i*interval, new Point(mnt.X, mnt.Y));
         if (IsInBound(pnt, dImg))
         {
             int row, col;
             dImg.GetBlockCoordFromPixel(pnt.X, pnt.Y, out row, out col);
             if ((col < 0) || (row < 0) || (row >= dImg.Height) ||
                 (col >= dImg.Width) || (dImg.IsNullBlock(row, col)))
                 points.Add(double.NaN);
             else
                 points.Add(Math.Min(Angle.DifferencePi(mnt.Angle, dImg.AngleInRadians(row, col)),
                                                            Angle.DifferencePi(mnt.Angle, dImg.AngleInRadians(row, col) + Math.PI)));
             i++;
         }
         else
             endOfPoints = true;
     }
     bool isLastNan = false;
     int j = points.Count - 1;
     while (!isLastNan && j >= 0)
     {
         if (double.IsNaN(points[j]))
         {
             points.RemoveAt(j);
             j--;
         }
         else
             isLastNan = true;
     }
     directions = points.ToArray();
 }
Esempio n. 17
0
        private static byte[] MtiaToByteArray(Minutia mtia)
        {
            byte[] bytes = new byte[4];
            // Storing value X in the left most 11 bits.
            int blockX = (2047 & mtia.X) << 21;
            // Storing value Y in the next 11 bits.
            int blockY = (2047 & mtia.Y) << 10;
            // Storing value Angle in the next 8 bits.
            int blockAngle = (Convert.ToByte(Math.Round(mtia.Angle * 255 / (2 * Math.PI)))) << 2;
            // Storing value MinutiaType in the last 2 bits.
            int blockType = (int)mtia.MinutiaType;
            // Merging all data
            int info = blockX | blockY | blockAngle | blockType;

            bytes[0] = Convert.ToByte(255 & info);
            info   >>= 8;
            bytes[1] = Convert.ToByte(255 & info);
            info   >>= 8;
            bytes[2] = Convert.ToByte(255 & info);
            info   >>= 8;
            bytes[3] = Convert.ToByte(255 & info);

            return(bytes);
        }
Esempio n. 18
0
 public MinutiaMapper(Minutia query, Minutia template)
 {
     dAngle        = template.Angle - query.Angle;
     this.template = template;
     this.query    = query;
 }
 private byte ComputeRidgeCount(SkeletonImage skeletonImage, Minutia mtia0, Minutia mtia1)
 {
     return skeletonImage.RidgeCount(mtia0.X, mtia0.Y, mtia1.X, mtia1.Y);
 }
 private double ComputeAlpha(Minutia mtia0, Minutia mtia1)
 {
     double x = mtia0.X - mtia1.X;
     double y = mtia0.Y - mtia1.Y;
     return Angle.Difference2Pi(mtia0.Angle, Angle.ComputeAngle(x, y));
 }
        public double[][] LoadTaughtPeople(SOMParams somParams)
        {
            double[][] features;
            var fileName = GetTaughtFeaturesFilenameByParams(somParams);

            People = new List<Person>();
            using (var sr = new StreamReader(fileName))
            {
                var lineCount = File.ReadAllLines(fileName).Count();
                features = new double[lineCount - 1][];
                var count = 0;
                var line = sr.ReadLine();
                var splitStringArray = new string[1] {";"};

                line = sr.ReadLine();
                var members = line.Split(splitStringArray, StringSplitOptions.None);
                var person = new Person(members[0]);
                var finger = new Fingerprint(int.Parse(members[1]));
                var scan = new Scan(int.Parse(members[2]));
                var feature = new Minutia((short)double.Parse(members[3]), (short)double.Parse(members[4]), double.Parse(members[5]))
                {
                    MinutiaType = (MinutiaType)double.Parse(members[6])
                };
                scan.Features.Add(feature);

                features[count] = new double[5];
                features[count][2] = double.Parse(members[3]);
                features[count][3] = double.Parse(members[4]);
                features[count][0] = double.Parse(members[5]);
                features[count][1] = double.Parse(members[6]);
                features[count][4] = double.Parse(members[7]);
                count++;

                // Read lines from the file until the end of the file is reached.
                while ((line = sr.ReadLine()) != null)
                {
                    members = line.Split(splitStringArray, StringSplitOptions.None);

                    features[count] = new double[5];
                    features[count][2] = double.Parse(members[3]);
                    features[count][3] = double.Parse(members[4]);
                    features[count][0] = double.Parse(members[5]);
                    features[count][1] = double.Parse(members[6]);
                    features[count][4] = double.Parse(members[7]);
                    count++;

                    feature = new Minutia((short)double.Parse(members[3]), (short)double.Parse(members[4]), double.Parse(members[5]))
                    {
                        MinutiaType = (MinutiaType)double.Parse(members[6])
                    };
                    scan.Features.Add(feature);

                    var scanId = int.Parse(members[2]);
                    if (scan.Id != scanId)
                    {
                        finger.Scans.Add(scan);
                        scan = new Scan(scanId);
                    }

                    var fingerId = int.Parse(members[1]);
                    if (finger.Id != fingerId)
                    {
                        person.Fingerprints.Add(finger);
                        finger = new Fingerprint(fingerId);
                    }

                    if (person.Id != members[0])
                    {
                        People.Add(person);
                        person = new Person(members[0]);
                    }
                }

                finger.Scans.Add(scan);
                person.Fingerprints.Add(finger);
                People.Add(person);

                sr.Close();
            }

            return features;
        }
        private void LoadPeople()
        {
            var fileName = string.Format(@"{0}{1}", Folder, FeaturesDatabase);
            using (var sr = new StreamReader(fileName))
            {
                var line = sr.ReadLine();
                var splitStringArray = new string[1] {";"};

                line = sr.ReadLine();
                var members = line.Split(splitStringArray, StringSplitOptions.None);
                var person = new Person(members[0]);
                var finger = new Fingerprint(int.Parse(members[1]));
                var scan = new Scan(int.Parse(members[2]));
                var feature = new Minutia(short.Parse(members[3]), short.Parse(members[4]), double.Parse(members[5]))
                {
                    MinutiaType = (MinutiaType) int.Parse(members[6])
                };
                scan.Features.Add(feature);

                // Read lines from the file until the end of the file is reached.
                while ((line = sr.ReadLine()) != null)
                {
                    members = line.Split(splitStringArray, StringSplitOptions.None);

                    feature = new Minutia(short.Parse(members[3]), short.Parse(members[4]), double.Parse(members[5]))
                    {
                        MinutiaType = (MinutiaType) int.Parse(members[6])
                    };
                    scan.Features.Add(feature);

                    var scanId = int.Parse(members[2]);
                    if (scan.Id != scanId)
                    {
                        finger.Scans.Add(scan);
                        scan = new Scan(scanId);
                    }

                    var fingerId = int.Parse(members[1]);
                    if (finger.Id != fingerId)
                    {
                        person.Fingerprints.Add(finger);
                        finger = new Fingerprint(fingerId);
                    }

                    if (person.Id != members[0])
                    {
                        People.Add(person);
                        person = new Person(members[0]);
                    }
                }

                finger.Scans.Add(scan);
                person.Fingerprints.Add(finger);
                People.Add(person);

                sr.Close();
            }
        }
 private double ComputeBeta(Minutia mtia0, Minutia mtia1)
 {
     return Angle.Difference2Pi(mtia0.Angle, mtia1.Angle);
 }
Esempio n. 24
0
 public Minutia Map(Minutia m)
 {
     double newAngle = m.Angle + dAngle;
     double sin = Math.Sin(dAngle);
     double cos = Math.Cos(dAngle);
     return new Minutia
     {
         Angle = (newAngle > 2 * Math.PI) ? newAngle - 2 * Math.PI : (newAngle < 0) ? newAngle + 2 * Math.PI : newAngle,
         X = Convert.ToInt16(Math.Round((m.X - query.X) * cos - (m.Y - query.Y) * sin + template.X)),
         Y = Convert.ToInt16(Math.Round((m.X - query.X) * sin + (m.Y - query.Y) * cos + template.Y))
     };
 }
 /// <summary>
 ///     Computes Euclidean distance between the specified minutiae.
 /// </summary>
 /// <param name="m0">A minutia.</param>
 /// <param name="m1">A minutia.</param>
 /// <returns>
 ///     Distance computed from the specified minutiae.
 /// </returns>
 public double Compare(Minutia m0, Minutia m1)
 {
     double diff0 = m0.Y - m1.Y;
     double diff1 = m0.X - m1.X;
     return Math.Sqrt(diff0 * diff0 + diff1 * diff1);
 }
        private static byte[] MtiaToByteArray(Minutia mtia)
        {
            byte[] bytes = new byte[4];
            // Storing value X in the left most 11 bits.
            int blockX = (2047 & mtia.X) << 21;
            // Storing value Y in the next 11 bits.
            int blockY = (2047 & mtia.Y) << 10;
            // Storing value Angle in the next 8 bits.
            int blockAngle = (Convert.ToByte(Math.Round(mtia.Angle * 255 / (2 * Math.PI)))) << 2;
            // Storing value MinutiaType in the last 2 bits.
            int blockType = (int)mtia.MinutiaType;
            // Merging all data
            int info = blockX | blockY | blockAngle | blockType;

            bytes[0] = Convert.ToByte(255 & info);
            info >>= 8;
            bytes[1] = Convert.ToByte(255 & info);
            info >>= 8;
            bytes[2] = Convert.ToByte(255 & info);
            info >>= 8;
            bytes[3] = Convert.ToByte(255 & info);

            return bytes;
        }
        private static Minutia MtiaFromByteArray(byte[] bytes)
        {
            var mtia = new Minutia();
            int info = (bytes[3] << 24) | (bytes[2] << 16) | (bytes[1] << 8) | bytes[0];

            mtia.MinutiaType = (MinutiaType)(3 & info);
            info >>= 2;
            mtia.Angle = 2 * Math.PI * (255 & info) / 255;
            info >>= 8;
            mtia.Y = Convert.ToInt16(info & 2047);
            info >>= 11;
            mtia.X = Convert.ToInt16(info & 2047);

            return mtia;
        }
Esempio n. 28
0
 public MtiaMapper(Minutia query, Minutia template)
 {
     dAngle = template.Angle - query.Angle;
     this.template = template;
     this.query = query;
 }