コード例 #1
0
        public void FastHoughTransformCircle(ImageRec DestImageData)
        {
            int slope2;
            int dx;
            int dy;

            int iy = 0;
            int ix = 0;
            int i;

            int MaxDi = (Width + Height) / 4;

            for (int x = 0; x < Width; x++)
            {
                for (int y = 0; y < Height; y++)
                {
                    i = x + y * Width;

                    dx = PrimarryBuffer[i];
                    dy = SecondaryBuffer[i];

                    slope2 = (dx * dx) + (dy * dy);

                    if (slope2 > SlopeTrashould)
                    {
                        if (bComp(dy, dx))
                        {
                            for (ix = 0; ix < Width; ix++)
                            {
                                iy = (int)((ix - x) * dx / dy + y); //Create orthogonal line
                                if (iy >= 0 && iy < DestImageData.Height)
                                {
                                    DestImageData.PrimarryBuffer[ix + iy * DestImageData.Width] += 1;
                                }
                            }
                        }
                        else
                        {
                            for (iy = 0; iy < Height; iy++)
                            {
                                ix = (int)((iy - y) * dy / dx + x); //Create orthogonal line
                                if (ix >= 0 && ix < DestImageData.Width)
                                {
                                    DestImageData.PrimarryBuffer[ix + iy * DestImageData.Width] += 1;
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #2
0
        public void CircleDiameterStat(ImageRec DestImageData, PatternPoint Item)
        {
            int dist;
            int dy     = 0;
            int dx     = 0;
            int iy     = 0;
            int ix     = 0;
            int slope2 = 0;

            int[] LineBuffer = new int[48];

            int SquareRadius = (int)Item.AverageDistance / 2;

            for (int i = 0; i < Item.Points.Length; i++)
            {
                int CountSum = 0;

                for (int x = -SquareRadius; x < SquareRadius; x++)
                {
                    ix = Item.Points[i].X + x;

                    for (int y = -SquareRadius; y < SquareRadius; y++)
                    {
                        iy = Item.Points[i].Y + y;

                        if (iy > 0 && ix > 0 && iy < Height - 1 && ix < Width - 1)
                        {
                            dx = PrimarryBuffer[GetIndex(ix, iy)];
                            dy = SecondaryBuffer[GetIndex(ix, iy)];

                            slope2 = (dx * dx) + (dy * dy);

                            if (slope2 > (256 * 256 * 16))
                            {
                                dist = Isqrt(x * x + y * y);

                                if (dist < SquareRadius)
                                {
                                    DestImageData.PrimarryBuffer[DestImageData.GetIndex(dist * 16 / SquareRadius, i * 2)] += (128 / (dist + 1));
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #3
0
        public MainWindow()
        {
            InitializeComponent();

            byte[] imageBuffer;
            int    imageWidth;
            int    imageHeight;
            string filePath = "..\\..\\test\\WP_20141125_004.png";
            double dpi      = 96;

            System.Diagnostics.Debug.WriteLine(Environment.CurrentDirectory);

            FastLookUpTable PatternTable = new FastLookUpTable();

            PatternTable.LoadFromFile("..\\..\\test\\output.dat");

            ImageArrayFromFile(filePath, out imageBuffer, out imageWidth, out imageHeight);

            ImageRec MyIR = new ImageRec(imageWidth, imageHeight);
            ImageRec MyHT = new ImageRec(imageWidth, imageHeight);
            ImageRec MyDi = new ImageRec(imageWidth, imageHeight);


            //MyHT.LoopMode = true;

            MyIR.SetImageData(imageBuffer, 1);

            DateTime StartTime = DateTime.UtcNow;


            MyIR.GausFilter();

            ElipsedTime(StartTime, "GausFilter");

            MyIR.Convolute();

            ElipsedTime(StartTime, "Convolute");

            MyIR.SuppressNonMaximum();

            ElipsedTime(StartTime, "SuppressNonMaximum");

            MyIR.FastHoughTransformCircle(MyDi);

            ElipsedTime(StartTime, "HoughTransformCircle");

            MyDi.GausFilter();

            ElipsedTime(StartTime, "GausFilter");

            MyDi.Singulate(16, 16, 10);

            ElipsedTime(StartTime, "Singulate");

            MyDi.FindNeighbors();

            var PointTrip = MyDi.FindPattern();


            /*for (int i = 0; i < 7; i++ )
             * {
             *  System.Diagnostics.Debug.WriteLine(PointTrip.Points[i].X + "; " + PointTrip.Points[i].Y);
             * }*/

            ElipsedTime(StartTime, "FindHexPoint");

            if (PointTrip != null)
            {
                var data = MyIR.GetPatternData(PointTrip);

                PointTrip.GetAngleTo(0);


                MyIR.CircleDiameterStat(MyDi, PointTrip);

                ElipsedTime(StartTime, "GetPatternData");
                PatternTable.Select(data);
            }



            System.Diagnostics.Debug.WriteLine(PatternTable.X + "; " + PatternTable.Y + "; " + PatternTable.Rotation);


            ElipsedTime(StartTime, "PatternTable.Select");

            MyIR.CombineBuffers();

            //MyDi.RelativeThreshold(0.2);

            MyHT.SetImageData(imageBuffer, 1);

            MyIR.NormelizeImage();
            MyHT.NormelizeImage();
            MyDi.NormelizeImage();



            var bmp1 = BitmapSource.Create(MyHT.Width, MyHT.Height, dpi, dpi, PixelFormats.Bgra32, null, MyHT.Get32BitArray(), MyHT.Width * 4);

            TestImage.Source = bmp1;

            var bmp2 = BitmapSource.Create(MyIR.Width, MyIR.Height, dpi, dpi, PixelFormats.Bgra32, null, MyIR.Get32BitArray(), MyIR.Width * 4);

            OutPutImage.Source = bmp2;

            var bmp3 = BitmapSource.Create(MyDi.Width, MyDi.Height, dpi, dpi, PixelFormats.Bgra32, null, MyDi.Get32BitArray(), MyDi.Width * 4);

            StattImage.Source = bmp3;

            TestImage.Width  = bmp1.Width;
            TestImage.Height = bmp1.Height;

            OutPutImage.Width  = bmp2.Width;
            OutPutImage.Height = bmp2.Height;

            StattImage.Width  = bmp3.Width;
            StattImage.Height = bmp3.Height;
        }