public void OrientationRegularizationAngleTest()
 {
     var image = Resources._1;
     var bytes = ImageHelper.LoadImage<int>(Resources._1);
     int height = bytes.GetLength(0);
     int width = bytes.GetLength(1);
     float[] sourceBytes = new float[height * width];
     float[] orientInp = new float[height * width];
     float[] orientOut = new float[height * width];
     PixelwiseOrientationField field1 = new PixelwiseOrientationField(bytes, 16);
     for (int i = 0; i < height; i++)
     {
         for (int j = 0; j < width; j++)
         {
             sourceBytes[i * width + j] = (float)bytes[i, j];
             orientInp[i * width + j] = (float)field1.Orientation[i, j];
             orientOut[i * width + j] = 0.0f;
         }
     }
     OrientationRegularization(orientOut, orientInp, height, width, 25);
     double[,] orient_2D = new double[height, width];
     for (int i = 0; i < height; i++)
         for (int j = 0; j < width; j++)
             orient_2D[i, j] = orientOut[i * width + j];
     //field1.NewOrientation(orient_2D);
     field1.SaveAboveToFile(image);
 }
        public void SingularityRegionDetectionTest()
        {
            var intBmp = ImageHelper.LoadImage<int>(Properties.Resources._1_1);
            int width = intBmp.GetLength(0);
            int height = intBmp.GetLength(1);

            PixelwiseOrientationField field = new PixelwiseOrientationField(intBmp, 8);

            var orient = field.Orientation;
            float[] linOrient = new float [width * height];

            for (int i = 0; i < width; i++ )
            {
                for (int j = 0; j < height; j++)
                {
                    linOrient[i * height + j] = (float)orient[i, j];
                }
            }

            float[] target = new float [width * height];

            Detect(linOrient, width, height, target);

            /*int[,] result = new int[width, height];
            for (int i = 0; i < width; ++i)
            {
                for (int j = 0; j < height; ++j)
                {
                    result[i, j] = (int)(target[j * width + i] * 255);
                }
            }

            ImageHelper.SaveArrayToBitmap(result).Save("Result.jpg");*/
        }
 public static List<Minutia> GetMinutias(int[,] data, PixelwiseOrientationField oField)
 {
     int width = data.GetLength(1);
     int height = data.GetLength(0);
     List<Minutia> minutias = new List<Minutia>();
     for (int y = 0; y < height; y++)
     {
         for (int x = 0; x < width; x++)
         {
             if (IsMinutia(data, x, y))
             {
                 Minutia m = new Minutia();
                 m.X = x;
                 m.Y = y;
                 m.Angle = (float) GetCorrectAngle(
                     data,
                     oField,
                     x,
                     y
                 );
                 minutias.Add(m);
             }
         }
     }
     return minutias;
 }
        public static Bitmap SingularityDetect(int[,] arr, int blockSize)
        {
            PixelwiseOrientationField img = new PixelwiseOrientationField(arr, 16);
            var oriented = img.Orientation;

               for (int i = 1; i < arr.GetLength(0)-2; i += blockSize)
            {
                for (int j = 1; j < arr.GetLength(1)-2; j += blockSize)
                {
                    var k = AngleSum(i, j, arr, blockSize, oriented);
                    if (Math.Abs(k - Math.PI) < 0.001 || Math.Abs(k + Math.PI) < 0.001 || Math.Abs(k - 2 * Math.PI) < 0.001 )
                    {
                        for (int t = i-blockSize/2; t <= i+blockSize/2; t++)
                        {
                            for (int l = j-blockSize/2; l <= j+blockSize/2; l++)
                            {
                                if (i - blockSize/2 < 0 || i + blockSize/2 > arr.GetLength(0) || j - blockSize/2 < 0 ||
                                    j + blockSize / 2 > arr.GetLength(1) || arr.GetLength(0) - t <0)
                                    continue;
                               // detectedImg.SetPixel(t+1, arr.GetLength(1) - t+1, Color.Chartreuse);
                                arr[t, l] = 128;
                            }
                        }

                    }
                }
            }

               // var k = AngleSum(40, 40, arr, blockSize, oriented);
            Bitmap detectedImg = ImageHelper.SaveArrayToBitmap(arr);
            return detectedImg;
        }
 public void OrientationRegularizationTest()
 {
     var image = Resources.SampleFinger;
       var bytes = ImageHelper.LoadImage<int>(Resources.SampleFinger);
       PixelwiseOrientationField field = new PixelwiseOrientationField(bytes, 16);
       OrientationFieldRegularization new_field = new OrientationFieldRegularization(field.Orientation, 25);
       field.NewOrientation(new_field.LocalOrientation());
       field.SaveAboveToFile(image);
 }
        public void PixelwiseOrientationTest()
        {
            var image = Resources.SampleFinger;
            var bytes = ImageHelper.LoadImage<int>(Resources.SampleFinger);

            PixelwiseOrientationField field = new PixelwiseOrientationField(bytes, 16);

            //double orientation = field.GetOrientation(1, 1);
            field.SaveAboveToFile(image);
        }
Esempio n. 7
0
        public static void SaveAboveToFile(this PixelwiseOrientationField field, Bitmap undercoat, string name, bool openFileAfterSaving = false)
        {
            var bmp = SaveAboveToBitmap(field, undercoat);

            bmp.Save(name, ImageHelper.GetImageFormatFromExtension(name));
            if (openFileAfterSaving)
            {
                Process.Start(name);
            }
        }
        public void MinutiaDetectorBasicTest()
        {
            var image = Resources.skeleton;
            var bytes = ImageHelper.LoadImage<int>(image);
            PixelwiseOrientationField field = new PixelwiseOrientationField(bytes, 16);

            int minutiaSize = Marshal.SizeOf(typeof(Minutia));
            IntPtr minutiasArrayPtr = Marshal.AllocHGlobal(minutiaSize * bytes.GetLength(0) * bytes.GetLength(1));

            int minutiasCount = GetMinutias(
                minutiasArrayPtr,
                array2Dto1D(bytes),
                array2Dto1D(field.Orientation),
                bytes.GetLength(1),
                bytes.GetLength(0)
            );

            List<Minutia> minutias = new List<Minutia>(minutiasCount);

            for (int i = 0; i < minutiasCount; i++)
            {
                IntPtr ptr = new IntPtr(minutiasArrayPtr.ToInt32() + minutiaSize * i);
                minutias.Add(
                    (Minutia)Marshal.PtrToStructure(
                        new IntPtr(minutiasArrayPtr.ToInt32() + minutiaSize * i),
                        typeof(Minutia)
                    )
                );
            }

            Marshal.FreeHGlobal(minutiasArrayPtr);

            //List<Minutia> minutias = new List<Minutia>(minutiasArray.Take(minutiasCount));

            //field.SaveAboveToFile(image, Path.GetTempPath() + "//minutiaDetectionOrientationField.bmp", true);

            //System.Console.WriteLine(Path.GetTempPath());//result path
            //System.Console.WriteLine(minutias.Count);
            System.Console.WriteLine(minutiasCount);

            ImageHelper.MarkMinutiae(
                image,
                minutias,
                Path.GetTempPath() + "//minutiaDetectionMinutiae.png"
            );
            ImageHelper.MarkMinutiaeWithDirections(
                image,
                minutias,
                Path.GetTempPath() + "//minutiaDetectionMinutiaeWithDirections.png"
            );
        }
Esempio n. 9
0
        static void Main(string[] args)
        {
            var bytes = ImageHelper.LoadImage<int>("D:\\SmrSchl\\DB2_bmp\\DB2_bmp\\1_5.bmp");

            PixelwiseOrientationField field = new PixelwiseOrientationField(bytes, 16);

            SmoothOrientationField SO_field = new SmoothOrientationField(field.Orientation);
            field.NewOrientation(SO_field.LocalOrientation());

              //  Filter f = new Filter(16, 2.5);
              //  f.WriteMatrix();

               // Console.Read();
        }
Esempio n. 10
0
        public static Bitmap SaveAboveToBitmap(this PixelwiseOrientationField field, Bitmap undercoat)
        {
            var size       = field.BlockSize;
            int lineLength = field.BlockSize / 2;
            var bmp        = new Bitmap(undercoat.Width * size, undercoat.Height * size);

            for (int x = 0; x < bmp.Width; x++)
            {
                for (int y = 0; y < bmp.Height; y++)
                {
                    bmp.SetPixel(x, y, undercoat.GetPixel(x / size, y / size));
                }
            }

            var gfx = Graphics.FromImage(bmp);

            var pen = new Pen(Brushes.Red)
            {
                Width = 2
            };

            field.Orientation.Select2D(
                (value, row, column) =>
            {
                int x = column * size + size / 2;
                int y = row * size + size / 2;

                Point p0 = new Point
                {
                    X = Convert.ToInt32(x - lineLength * Math.Cos(value)),
                    Y = bmp.Height - 1 - Convert.ToInt32(y - lineLength * Math.Sin(value))
                };

                Point p1 = new Point
                {
                    X = Convert.ToInt32(x + lineLength * Math.Cos(value)),
                    Y = bmp.Height - 1 - Convert.ToInt32(y + lineLength * Math.Sin(value))
                };

                gfx.DrawLine(pen, p0, p1);
                return(0);
            });
            gfx.Save();

            return(bmp);
        }
        public void PoincareDetectionTestMethod()
        {
            var img = ImageHelper.LoadImage<int>(Resource1._44_8);
            int imgWidth = img.GetLength(0), imgHeight = img.GetLength(1);

            PixelwiseOrientationField img2 = new PixelwiseOrientationField(img, 16);
            var oriented = img2.Orientation;

            int[] distPtr = new int[imgWidth*imgHeight];

            float[] orientedPtr = oriented.Select2D(x => (float) x).Make1D();

            int[] imgPtr = img.Make1D();

            PoincareDetect(imgPtr, imgHeight, imgWidth, orientedPtr, distPtr);

            var dist = distPtr.Make2D(imgWidth, imgHeight);
            ImageHelper.SaveArrayAndOpen(dist.Select2D(x=>(double)x),Path.GetTempPath() + Guid.NewGuid() + ".bmp");
        }
        public void MinutiaDetectorBasicTest()
        {
            var image = Resources.skeleton;
            var bytes = ImageHelper.LoadImage<int>(image);
            PixelwiseOrientationField field = new PixelwiseOrientationField(bytes, 16);

            List<Minutia> minutias = MinutiaDetector.GetMinutias(bytes, field);

            //field.SaveAboveToFile(image, Path.GetTempPath() + "//minutiaDetectionOrientationField.bmp", true);

            ImageHelper.MarkMinutiae(
                image,
                minutias,
                Path.GetTempPath() + "//minutiaDetectionMinutiae.png"
            );
            ImageHelper.MarkMinutiaeWithDirections(
                image,
                minutias,
                Path.GetTempPath() + "//minutiaDetectionMinutiaeWithDirections.png"
            );
        }
Esempio n. 13
0
 // a shorter method to be used in tests
 public static void SaveAboveToFile(this PixelwiseOrientationField field, Bitmap undercoat)
 {
     SaveAboveToFile(field, undercoat, ImageHelper.GetTemporaryImageFileName(), true);
 }
        //rotate on PI angle if not right direction
        private static double GetCorrectAngle(int[,] data, PixelwiseOrientationField oField, int x, int y)
        {
            double angle = oField.GetOrientation(data.GetLength(0) - 1 - y, x);
            float PI = 3.141592654f;
            //for 'end line' minutia
            if (NeigboursCount == 1)
            {
                if (angle > 0.0)
                {
                    if ((GetPixel(data, x, y - 1) +
                        GetPixel(data, x + 1, y - 1) +
                        GetPixel(data, x + 1, y))
                        <
                        (GetPixel(data, x, y + 1) +
                        GetPixel(data, x - 1, y + 1) +
                        GetPixel(data, x - 1, y)))
                    {
                        angle += PI;
                    }
                }
                else
                {
                    if ((GetPixel(data, x, y + 1) +
                        GetPixel(data, x + 1, y + 1) +
                        GetPixel(data, x + 1, y))
                        <
                        (GetPixel(data, x, y - 1) +
                        GetPixel(data, x - 1, y - 1) +
                        GetPixel(data, x - 1, y)))
                    {
                        angle += PI;
                    }
                }
            }
            //for 'fork' minutia
            else if (NeigboursCount == 3)
            {
                for (int r = 1; r < 16; r++)
                {
                    double normal = angle + PI / 2;
                    int aboveNormal = 0;
                    int belowNormal = 0;

                    for (int i = -r; i <= r; i++)
                    {
                        for (int j = -r; j <= r; j++)
                        {
                            if (i == j && j == 0)
                            {
                                continue;
                            }
                            if (GetPixel(data, x + j, y + i) == BLACK &&
                                InCircle(x, y, r, x + j, y + i))
                            {
                                double deltaNormalY = - Math.Tan(normal) * j;
                                if (i < deltaNormalY)
                                {
                                    aboveNormal++;
                                }
                                else
                                {
                                    belowNormal++;
                                }
                            }
                        }
                    }
                    if (aboveNormal == belowNormal)
                    {
                        continue;//?
                    }
                    else
                    {
                        if ((aboveNormal > belowNormal &&
                            Math.Tan(angle) > 0.0) ||
                            (aboveNormal < belowNormal &&
                            Math.Tan(angle) < 0.0))
                        {
                            angle += PI;
                        }
                        break;
                    }
                }
            }
            return angle;
        }