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 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 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 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 OrientationAngleTest() { 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[] orientOut = new float[width * height]; for (int i = 0; i < height - 1; i++) { for (int j = 0; j < width - 1; j++) { sourceBytes[i * width + j] = (float)bytes[i, j]; orientOut[i * width + j] = 0.0f; } } OrientationFieldInPixels(orientOut, sourceBytes, width, height); PixelwiseOrientationField field = new PixelwiseOrientationField(bytes, 16); 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]; } } field.NewOrientation(orient_2D); field.SaveAboveToFile(image); }
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); }
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" ); }
public void SingularityRegionDetectionTest() { var image = Resources._8_2; var intBmp = ImageHelper.LoadImageAsInt(Resources._8_2); PixelwiseOrientationField field = new PixelwiseOrientationField(intBmp, 8); int width = intBmp.GetLength(0); int height = intBmp.GetLength(1); var orient = field.Orientation; System.IO.StreamWriter file = new System.IO.StreamWriter(@"D:\Orientation.txt"); for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { file.Write((int)(orient[i, j] * 10000)); file.Write(" "); } file.WriteLine(); } for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { orient[i, j] = (orient[i, j] * 10000) / 10000; } } SingularityRegionDetection D = new SingularityRegionDetection(orient); double[,] Result = D.Detect(orient); double[,] revertedResult = new double[height, width]; for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { revertedResult[height - 1 - j, i] = Result[i, j]; } } Bitmap bmp = D.MakeBitmap(revertedResult); bmp.Save("Result.jpg"); }
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(); }
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" ); }
//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); }