示例#1
0
        public float find_HD_match(IrisCode irisCode, IrisCode matchIrisCode)
        {
            int j;

            int length = matchIrisCode.size;

            if (irisCode.size < length)
            {
                length = irisCode.size;
            }
            int   diff_c     = 0;
            int   usable_bit = 0;
            float HD         = 0;

            for (j = 0; j < length; j++)
            {
                if (irisCode.mask[j] == 0 && matchIrisCode.mask[j] == 0)
                {
                    if (matchIrisCode.bit[j] != irisCode.bit[j])
                    {
                        diff_c++;
                    }
                    usable_bit++;
                }
            }
            HD = (float)diff_c / usable_bit;

            return(HD);
        }
示例#2
0
        public float PerformByteMatch(IrisCode probe, IrisCode candidate, int max_shift)
        {
            float best_value = 1.0f;

            for (int i = 0; i < max_shift; i++)
            {
                uint[] bit_geser_candidate_left   = CyclicShiftLeft(i, candidate.newBit);
                uint[] bit_geser_candidate_right  = CyclicShiftRight(i, candidate.newBit);
                uint[] mask_geser_candidate_left  = CyclicShiftLeft(i, candidate.newMask);
                uint[] mask_geser_candidate_right = CyclicShiftRight(i, candidate.newMask);

                float result_kiri  = BitwiseVerify(probe.newBit, bit_geser_candidate_left, probe.newMask, mask_geser_candidate_left);
                float result_kanan = BitwiseVerify(probe.newBit, bit_geser_candidate_right, probe.newMask, mask_geser_candidate_right);

                if (result_kiri < best_value)
                {
                    best_value = result_kiri;
                }
                if (result_kanan < best_value)
                {
                    best_value = result_kanan;
                }
            }

            return(best_value);
        }
示例#3
0
        public IrisCode shift_left(int degree)
        {
            IrisCode irisCodeResult = new IrisCode();
            int      length         = matchIrisCode.size;

            irisCodeResult.size = length;

            int j, c, d;

            byte[] temp      = new byte[length];
            byte[] temp_mask = new byte[length];

            for (j = 0; j < length; j++)
            {
                c = j + degree;
                if (c >= length)
                {
                    d = c - length;
                }
                else
                {
                    d = c;
                }
                temp[j]      = matchIrisCode.bit[d];
                temp_mask[j] = matchIrisCode.mask[d];
            }

            irisCodeResult.bit  = temp;
            irisCodeResult.mask = temp_mask;

            return(irisCodeResult);
        }
示例#4
0
        public IrisCode shift_right(int degree)
        {
            IrisCode irisCodeResult = new IrisCode();
            int      length         = matchIrisCode.size;

            irisCodeResult.size = length;

            int j, c, d;

            byte[] temp      = new byte[length];
            byte[] temp_mask = new byte[length];

            for (j = length - 1; j >= 0; j--)
            {
                c = j - degree;
                if (c < 0)
                {
                    d = c + length;
                }
                else
                {
                    d = c;
                }
                temp[j]      = matchIrisCode.bit[d];
                temp_mask[j] = matchIrisCode.mask[d];
            }

            irisCodeResult.bit  = temp;
            irisCodeResult.mask = temp_mask;

            return(irisCodeResult);
        }
示例#5
0
        public static IrisCode NewImport(byte[] template)
        {
            IrisCode irisCode = new IrisCode();

            int size = 2048;

            using (MemoryStream stream = new MemoryStream(template))
            {
                using (BinaryReader reader = new BinaryReader(stream, Encoding.UTF8))
                {
                    // 4B magic "IRIS"
                    AssertException.Check(new String(reader.ReadChars(4)) == "IRIS", "This is not an IRIS template.");

                    // 4B ex
                    AssertException.Check(new String(reader.ReadChars(4)) == "CODE", "This is not an IRIS template.");

                    // 4B total length (including header)
                    AssertException.Check(IPAddress.NetworkToHostOrder(reader.ReadInt32()) == template.Length, "Invalid template length.");

                    // 1B rubbish (eye position, zeroed)
                    reader.ReadByte();

                    // 1B rubbish (zeroed)
                    reader.ReadByte();

                    irisCode.size    = size;
                    irisCode.bit     = new byte[size];
                    irisCode.mask    = new byte[size];
                    irisCode.newBit  = new uint[size / 32];
                    irisCode.newMask = new uint[size / 32];

                    for (int i = 0; i < size / 32; ++i)
                    {
                        uint num = ReverseBytes(reader.ReadUInt32());
                        irisCode.newBit[i] = num;
                    }
                    // 2B rubbish (extra data length, zeroed)
                    reader.ReadInt16();
                    for (int i = 0; i < size / 32; ++i)
                    {
                        uint num = ReverseBytes(reader.ReadUInt32());
                        irisCode.newMask[i] = num;
                    }
                }
            }
            return(irisCode);
        }
示例#6
0
        public float PerformMatching()
        {
            int      i;
            IrisCode tmp_irisCode = new IrisCode();

            tmp_irisCode.size = matchIrisCode.size;
            tmp_irisCode.bit  = matchIrisCode.bit;
            tmp_irisCode.mask = matchIrisCode.mask;

            float HD     = 0;
            float HDl    = 0;
            float HDr    = 0;
            float max_HD = 1;

            for (i = 0; i < 10; i++)
            {
                tmp_irisCode = shift_left(i);
                HDl          = find_HD_match(irisCode, tmp_irisCode);
                tmp_irisCode = shift_right(i);
                HDr          = find_HD_match(irisCode, tmp_irisCode);

                if (HDr < HDl)
                {
                    HD = HDr;
                }
                else
                {
                    HD = HDl;
                }
                if (HD < max_HD)
                {
                    max_HD = HD;
                }
            }

            return(max_HD);
        }
示例#7
0
 public Matching(IrisCode irisCode)
 {
     this.irisCode = irisCode;
 }
示例#8
0
 public Matching(IrisCode irisCode, IrisCode matchIrisCode)
 {
     this.irisCode      = irisCode;
     this.matchIrisCode = matchIrisCode;
 }
示例#9
0
        public static IrisCode Import(byte[] template)
        {
            IrisCode irisCode = new IrisCode();

            int size = 2048;

            using (MemoryStream stream = new MemoryStream(template))
            {
                using (BinaryReader reader = new BinaryReader(stream, Encoding.UTF8))
                {
                    // 4B magic "IRIS"
                    AssertException.Check(new String(reader.ReadChars(4)) == "IRIS", "This is not an IRIS template.");

                    // 4B ex
                    AssertException.Check(new String(reader.ReadChars(4)) == "CODE", "This is not an IRIS template.");

                    // 4B total length (including header)
                    AssertException.Check(IPAddress.NetworkToHostOrder(reader.ReadInt32()) == template.Length, "Invalid template length.");

                    // 1B rubbish (eye position, zeroed)
                    reader.ReadByte();

                    // 1B rubbish (zeroed)
                    reader.ReadByte();

                    irisCode.size = size;
                    irisCode.bit  = new byte[size];
                    irisCode.mask = new byte[size];

                    for (int i = 0; i < size / 8; ++i)
                    {
                        byte num = reader.ReadByte();

                        int    ByteIndex = i * 8;
                        string str       = ToBinary(num);
                        for (byte s = 0; s < 8; s++)
                        {
                            if (str[s] == '1')
                            {
                                irisCode.bit[ByteIndex + s] = 1;
                            }
                            else
                            {
                                irisCode.bit[ByteIndex + s] = 0;
                            }
                        }
                    }
                    // 2B rubbish (extra data length, zeroed)
                    reader.ReadInt16();
                    for (int i = 0; i < size / 8; ++i)
                    {
                        byte   num       = reader.ReadByte();
                        int    ByteIndex = i * 8;
                        string str       = ToBinary(num);
                        for (byte s = 0; s < 8; s++)
                        {
                            if (str[s] == '1')
                            {
                                irisCode.mask[ByteIndex + s] = 1;
                            }
                            else
                            {
                                irisCode.mask[ByteIndex + s] = 0;
                            }
                        }
                    }

                    // 2B rubbish (extra data length, zeroed)
                }
            }
            return(irisCode);
        }
示例#10
0
        public static byte[] Export(IrisCode irisCode)
        {
            byte[] template;
            using (MemoryStream stream = new MemoryStream())
            {
                using (BinaryWriter writer = new BinaryWriter(stream, Encoding.UTF8))
                {
                    checked
                    {
                        // 4B magic "11215"
                        writer.Write("IRIS".ToCharArray());

                        // 4B ex
                        writer.Write("CODE".ToCharArray());

                        // 4B total length (including header, will be updated later)
                        writer.Write(0);

                        // 1B rubbish (eye position, zeroed)
                        writer.Write((byte)0);

                        // 1B rubbish (zeroed)
                        writer.Write((byte)0);

                        int    ByteIndex;
                        byte[] irisBit  = new byte[irisCode.size / 8];
                        byte[] irisMask = new byte[irisCode.size / 8];
                        for (int i = 0; i < irisCode.size / 8; i++)
                        {
                            ByteIndex  = (i * 8);
                            irisBit[i] = (byte)(irisCode.bit[ByteIndex] * 128 + irisCode.bit[ByteIndex + 1] * 64 +
                                                irisCode.bit[ByteIndex + 2] * 32 + irisCode.bit[ByteIndex + 3] * 16 +
                                                irisCode.bit[ByteIndex + 4] * 8 + irisCode.bit[ByteIndex + 5] * 4 +
                                                irisCode.bit[ByteIndex + 6] * 2 + irisCode.bit[ByteIndex + 7]);
                            //      1B bitImage
                            writer.Write(irisBit[i]);
                        }

                        // 2B rubbish (extra data length, zeroed)
                        writer.Write((short)0);

                        for (int i = 0; i < irisCode.size / 8; i++)
                        {
                            ByteIndex   = (i * 8);
                            irisMask[i] = (byte)(irisCode.mask[ByteIndex] * 128 + irisCode.mask[ByteIndex + 1] * 64 +
                                                 irisCode.mask[ByteIndex + 2] * 32 + irisCode.mask[ByteIndex + 3] * 16 +
                                                 irisCode.mask[ByteIndex + 4] * 8 + irisCode.mask[ByteIndex + 5] * 4 +
                                                 irisCode.mask[ByteIndex + 6] * 2 + irisCode.mask[ByteIndex + 7]);
                            //      1B maskImage (ignored, zeroed)
                            writer.Write(irisMask[i]);
                        }

                        // 2B rubbish (extra data length, zeroed)
                        writer.Write((short)0);
                    }
                }
                // update length
                template = stream.ToArray();
                BitConverter.GetBytes(IPAddress.HostToNetworkOrder(template.Length)).CopyTo(template, 8);
            }
            return(template);
        }
示例#11
0
        public static void Main(string[] args)
        {
            string basepath = "Berhasil";

            int[] success = { 1, 3, 4, 5, 6, 7, 9, 10, 12, 14, 1, 3, 4, 5, 6, 7, 9, 10, 12, 14,
                              1, 3, 4, 5, 6, 7, 9, 10, 12, 14, 1, 3, 4, 5, 6, 7, 9, 10, 12, 14, 1, 3, 4, 5, 6, 7, 9, 10, 12, 14,
                              1, 3, 4, 5, 6, 7, 9, 10, 12, 14, 1, 3, 4, 5, 6, 7, 9, 10, 12, 14, 1, 3, 4, 5, 6, 7, 9, 10, 12, 14,
                              1, 3, 4, 5, 6, 7, 9, 10, 12, 14, 1, 3, 4, 5, 6, 7, 9, 10, 12, 14 };

            string[] firstPath  = new string[success.Length];
            string[] secondPath = new string[success.Length];

            byte[][] arr_iris_01 = new byte[success.Length][];
            byte[][] arr_iris_02 = new byte[success.Length][];

            double[] single_runtime_old = new double[100];
            double[] single_runtime_new = new double[100];
            double   runtime_total_new = 0.0, runtime_total_old = 0.0;

            for (int i = 0; i < success.Length; i++)
            {
                firstPath[i]  = basepath + "\\percobaan_" + success[i].ToString("D3") + "_l1.iris";
                secondPath[i] = basepath + "\\percobaan_" + success[i].ToString("D3") + "_l2.iris";

                arr_iris_01[i] = System.IO.File.ReadAllBytes(firstPath[i]);
                arr_iris_02[i] = System.IO.File.ReadAllBytes(secondPath[i]);
            }

            for (int k = 0; k < 100; k++)
            {
                // Create new stopwatch
                Stopwatch stopwatch = new Stopwatch();
                // Begin timing
                stopwatch.Start();
                for (int j = 0; j < success.Length; j++)
                {
                    IrisCode irisData_A = IrisTemplate.Import(arr_iris_01[j]);
                    IrisCode irisData_B = IrisTemplate.Import(arr_iris_02[j]);
                    Matching matching   = new Matching(irisData_A, irisData_B);
                    float    res        = matching.PerformMatching();
                    //Console.WriteLine((j + 1) + " : " + res);
                }
                TimeSpan ts = stopwatch.Elapsed;
                // Stop timing
                stopwatch.Stop();
                //Console.WriteLine("OLD APPROACH : ");
                //Console.WriteLine("Running Time : " + ts.TotalMilliseconds);
                single_runtime_old[k] = ts.TotalMilliseconds;
                runtime_total_old    += single_runtime_old[k];
                //Console.WriteLine("\n");

                // Create new stopwatch
                Stopwatch stopwatch2 = new Stopwatch();
                // Begin timing
                stopwatch2.Start();
                for (int j = 0; j < success.Length; j++)
                {
                    Matching m           = new Matching();
                    IrisCode irisData_01 = IrisTemplate.NewImport(arr_iris_01[j]);
                    IrisCode irisData_02 = IrisTemplate.NewImport(arr_iris_02[j]);
                    float    hasil       = m.PerformByteMatch(irisData_01, irisData_02, 10);
                    //Console.WriteLine((j + 1) + " : " + hasil);
                }
                TimeSpan ts2 = stopwatch2.Elapsed;
                // Stop timing
                stopwatch2.Stop();
                //Console.WriteLine("NEW APPROACH : ");
                //Console.WriteLine("Running Time : " + ts2.TotalMilliseconds);
                single_runtime_new[k] = ts2.TotalMilliseconds;
                runtime_total_new    += single_runtime_new[k];
                //Console.WriteLine("\n");
            }

            for (int k = 0; k < 100; k++)
            {
                Console.WriteLine(single_runtime_new[k]);
            }
            Console.WriteLine("-----------------");
            for (int k = 0; k < 100; k++)
            {
                Console.WriteLine(single_runtime_old[k]);
            }
            Console.WriteLine();

            Console.WriteLine("Metode Lama : " + runtime_total_old);
            Console.WriteLine("Metode Baru : " + runtime_total_new);

            Console.WriteLine("Press Enter to Exit...");
            Console.ReadLine();
        }