/// <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 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);
        }
Beispiel #3
0
        public MinutiaMapper(Minutia minutia)
        {
            Minutia t = new Minutia(0, 0, 0);

            dAngle        = t.Angle - minutia.Angle;
            this.template = t;
            this.query    = minutia;
        }
Beispiel #4
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))
     });
 }
Beispiel #5
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))
            });
        }
Beispiel #6
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);
        }
Beispiel #7
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
            });
        }
Beispiel #8
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);
        }
Beispiel #9
0
 public MinutiaMapper(Minutia query, Minutia template)
 {
     dAngle        = template.Angle - query.Angle;
     this.template = template;
     this.query    = query;
 }