コード例 #1
0
ファイル: Program.cs プロジェクト: thezaza101/sc_ANN
        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");
        }