Beispiel #1
0
        private void button1_Click_1(object sender, EventArgs e)
        {
            //把低對比關鍵點除掉
            bitmap = orignBitmap.Clone(cloneRect, format);
            for (int i = 0; i < bitmap.Width; i++)
            {
                for (int j = 0; j < bitmap.Height; j++)
                {
                    if (DiffPoint[i, j] != 0)
                    {
                        int tempmax = orignGrayImage[i, j], tempmin = orignGrayImage[i, j];
                        for (int tempi = 0; tempi < 3; tempi++)
                        {
                            for (int tempj = 0; tempj < 3; tempj++)
                            {
                                tempmax = orignGrayImage[i - 1 + tempi, j - 1 + tempj] > tempmax ? orignGrayImage[i - 1 + tempi, j - 1 + tempj] : tempmax;
                                tempmin = orignGrayImage[i - 1 + tempi, j - 1 + tempj] < tempmin ? orignGrayImage[i - 1 + tempi, j - 1 + tempj] : tempmin;
                            }
                        }
                        if (tempmax - tempmin < 3)
                        {
                            DiffPoint[i, j] = 0;
                        }
                    }
                }
            }
            for (int i = 0; i < bitmap.Width; i++)
            {
                for (int j = 0; j < bitmap.Height; j++)
                {
                    if (DiffPoint[i, j] > 0 && BoardKeypoint[i, j] == 0)
                    {
                        if (BoardKeypoint[i, j] == 0)
                        {
                            inteInfo[inteInfoCounter].isNotEmpty = true;
                            inteInfo[inteInfoCounter].x          = i;
                            inteInfo[inteInfoCounter].y          = j;
                            BoardKeypoint[i, j] = 1;

                            Array.Resize(ref inteInfo, inteInfo.Length + 1);
                            inteInfoCounter++;
                            inteInfo[inteInfoCounter] = new InterestedInformations();
                        }
                    }
                }
            }

            refreshScreen(0, 0);
            label1.Text = "低對比消除";
        }
Beispiel #2
0
        public Form1()
        {
            InitializeComponent();

            pictureBox1.Image = myImage;
            orignBitmap       = new Bitmap(myImage);

            format    = orignBitmap.PixelFormat;
            cloneRect = new Rectangle(0, 0, orignBitmap.Width, orignBitmap.Height);

            bitmap        = orignBitmap.Clone(cloneRect, format);
            textBox1.Text = 2 + "";
            textBox2.Text = 0.4 + "";
            textBox3.Text = 20 + "";
            textBox4.Text = 0 + "";
            textBox5.Text = 0 + "";

            inteInfoCounter = 0;
            inteInfo        = new InterestedInformations[1];
            inteInfo[0]     = new InterestedInformations();

            pictureBox1.Image = bitmap;
        }
Beispiel #3
0
        private void button2_Click_1(object sender, EventArgs e)
        {
            //找角落
            double R, ratio, minR, k = 0.04;
            double det, trace, smallLambda, bigLambda, lambda1, lambda2;
            int    rightPoint = sizeOfw / 2;

            CornerPoint = new int[bitmap.Width, bitmap.Height];
            double[,] tempCornerPoint = new double[bitmap.Width, bitmap.Height];

            minLambda = double.Parse(textBox2.Text); //最小浪打值
            ratio     = double.Parse(textBox2.Text); //兩個浪打的比值
            minR      = double.Parse(textBox3.Text); //R的最小接受值

            for (int i = 1 + rightPoint; i < bitmap.Width - rightPoint - 1; i++)
            {
                for (int j = 1 + rightPoint; j < bitmap.Height - rightPoint - 1; j++)
                {
                    //計算Ix,Iy
                    double[,] M = new double[2, 2];
                    for (int tempi = 0; tempi < sizeOfw; tempi++)
                    {
                        for (int tempj = 0; tempj < sizeOfw; tempj++)
                        {
                            double Ix, Iy;
                            int    nowi = i + tempi - rightPoint, nowj = j + tempj - rightPoint;
                            //分別對x,y微分出Ix,Iy
                            Ix  = orignGrayImage[nowi + 1, nowj - 1] + 2 * orignGrayImage[nowi + 1, nowj] + orignGrayImage[nowi + 1, nowj + 1] - orignGrayImage[nowi - 1, nowj - 1] - 2 * orignGrayImage[nowi - 1, nowj] - orignGrayImage[nowi - 1, nowj + 1];
                            Iy  = orignGrayImage[nowi - 1, nowj + 1] + 2 * orignGrayImage[nowi, nowj + 1] + orignGrayImage[nowi + 1, nowj + 1] - orignGrayImage[nowi - 1, nowj - 1] - 2 * orignGrayImage[nowi, nowj - 1] - orignGrayImage[nowi + 1, nowj - 1];
                            Ix /= 255;
                            Iy /= 255;
                            //將值加總進陣列M
                            M[0, 0] += Ix * Ix * orignGrayImage[nowi, nowj] / (sizeOfw * sizeOfw);
                            M[0, 1] += Ix * Iy * orignGrayImage[nowi, nowj] / (sizeOfw * sizeOfw);
                            M[1, 0]  = M[0, 1];
                            M[1, 1] += Iy * Iy * orignGrayImage[nowi, nowj] / (sizeOfw * sizeOfw);
                        }
                    }
                    //計算det( = )與trace( = Ix^2 + Iy^2)
                    det   = M[0, 0] * M[1, 1] - M[0, 1] * M[1, 0];
                    trace = M[0, 0] + M[1, 1];

                    //計算R,浪打1,浪打2
                    lambda2 = (trace + Math.Sqrt(trace * trace - 4 * det)) / 2;
                    lambda1 = (trace - Math.Sqrt(trace * trace - 4 * det)) / 2;
                    R       = det - k * trace * trace;

                    //找兩個浪打間的最小值
                    //lambda(max) / lambda(min) > 0.8 ?
                    smallLambda = lambda1 < lambda2 ? lambda1 : lambda2;
                    bigLambda   = lambda1 > lambda2 ? lambda1 : lambda2;
                    // && smallLambda / bigLambda > 0.95
                    //if (smallLambda > minLambda)
                    if (R > minR)
                    {
                        tempCornerPoint[i, j] = R;
                    }
                }
            }

            //Suppress non-maximum points
            for (int tempi = sizeOfw, maxX = bitmap.Width - sizeOfw; tempi < maxX; tempi++)
            {
                for (int tempj = sizeOfw, maxY = bitmap.Height - sizeOfw; tempj < maxY; tempj++)
                {
                    double currentValue = tempCornerPoint[tempi, tempj];

                    // for each windows' row
                    for (int trasei = -sizeOfw; (currentValue != 0) && (trasei <= sizeOfw); trasei++)
                    {
                        // for each windows' pixel
                        for (int trasej = -sizeOfw; trasej <= sizeOfw; trasej++)
                        {
                            if (tempCornerPoint[tempi + trasei, tempj + trasej] > currentValue)
                            {
                                currentValue = 0;
                                break;
                            }
                        }
                    }

                    // check if this point is really interesting
                    if (currentValue != 0)
                    {
                        CornerPoint[tempi, tempj]++;
                        if (BoardKeypoint[tempi, tempj] == 0)
                        {
                            inteInfo[inteInfoCounter].isNotEmpty = true;
                            inteInfo[inteInfoCounter].x          = tempi;
                            inteInfo[inteInfoCounter].y          = tempj;
                            inteInfo[inteInfoCounter].R          = tempCornerPoint[tempi, tempj];
                            BoardKeypoint[tempi, tempj]          = 1;

                            Array.Resize(ref inteInfo, inteInfo.Length + 1);
                            inteInfoCounter++;
                            inteInfo[inteInfoCounter] = new InterestedInformations();
                        }
                    }
                }
            }

            refreshScreen(0, 0);

            label1.Text = "尋找角落, " + inteInfoCounter;
        }