static void PI(int img) { System.Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")); Image <Rgba32> image = Image.Load("data\\" + img + ".bmp"); image.Mutate(ctx => ctx.Resize(image.Width / 8, image.Height / 8)); double ConversionFactor = 255 / (5 - 1); double AverageValue; MatrixData m = new MatrixData(image.Width, image.Height); for (int r = 0; r < image.Width; r++) { for (int c = 0; c < image.Height; c++) { AverageValue = (image[r, c].R + image[r, c].B + image[r, c].G) / 3; double pv = ((AverageValue / ConversionFactor) + 0.5) * ConversionFactor; if (pv < 200) { pv = 0; } m[r, c] = pv; } } m = m.HistEQ(); int mp = (int)m.MeanIfPixel((s) => { return(s > 0); }); for (int r = 0; r < image.Width; r++) { for (int c = 0; c < image.Height; c++) { if (m[r, c] < mp) { m[r, c] = 0; } } } m = m.HistEQ(); mp = (int)m.MeanIfPixel((s) => { return(s > 0); }); m = m.NormalizeAllBetween(mp, 255) * 255; m = m - vm; Tuple <int, int> centerBlob = new Tuple <int, int>(0, 0); Tuple <int, int> center = new Tuple <int, int>(image.Width / 2, image.Height / 2); m = m.ToBinary(m.MeanIfPixel((s) => { return(s > 0); })).GetLargestBlob(ref centerBlob); System.Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")); double angle = Math.Atan2(centerBlob.Item1 - center.Item2, centerBlob.Item1 - center.Item1) * (180 / Math.PI); double dist = Math.Abs(Math.Pow(centerBlob.Item1 - centerBlob.Item2, 2) + Math.Pow(center.Item1 - center.Item2, 2)); List <dynamic> output = m.GetVectorizedMatrix().ToList(); output.Add(angle); System.Console.WriteLine("image loaded"); }
public dynamic[] ProcessImage2(dynamic[] input) { //Turn the input vector into a matrix //This matrix represents the image MatrixData pixelMatrix = input.GetReShapedMatrix(19); //Get the emboss edge pixelMatrix = pixelMatrix.GetEmbossEdge(); //Apply with hist EQ function pixelMatrix = pixelMatrix.HistEQ(); //Crop 1 pixel off the edge of the image //this results in a 17x17 image pixelMatrix = pixelMatrix.CropEdges(1); //reduce the size of the image to 16x16 by removing // a random pixel from each row and column pixelMatrix = pixelMatrix.ReduceDimensionByOne(0).ReduceDimensionByOne(1); //Blur the image pixelMatrix = pixelMatrix.ApplyConvolutionFilter(blurFilter); //Reduce the 16x16 image to 8x8 using a custom downsampling algorithm pixelMatrix = pixelMatrix.DownScale(2); //Clamp the output matrix values between 0 and 255 pixelMatrix = pixelMatrix.Clamp(0, 255); //return the pixel matrix as a vector // the size of this vector will be 36 (6x6) return(pixelMatrix.GetVectorizedMatrix()); }
public dynamic[] ProcessImage3(dynamic[] input) { //Turn the input vector into a matrix //This matrix represents the image MatrixData pixelMatrix = input.GetReShapedMatrix(19); //hadamard product pixelMatrix = pixelMatrix * averageFace; //reduce the size of the image to 18x18 by removing // a random pixel from each row and column pixelMatrix = pixelMatrix.ReduceDimensionByOne(0).ReduceDimensionByOne(1); pixelMatrix = pixelMatrix.HistEQ(); return(pixelMatrix.DownScale(2, false).GetVectorizedMatrix()); }