Esempio n. 1
0
        private void Piramids()
        {
            double sigma0 = 1.6;                              // sigma 0
            double k      = Math.Pow(2.0, (1.0 / (double)S)); // Интервал между масштабами

            int minr = Math.Min(BeginImage.Width, BeginImage.Height);

            O = 0;
            while (minr > 32)
            {
                minr /= 2;
                O++;
            }

            Piramida = new Img[O + 1, S + 3];
            DoG      = new Img[O + 1, S + 2];

            Img    TekImg   = new Img(BeginImage.Bitmap);
            double sigmaD   = sigma0;                      // Действительная сигма
            double sigmaTEK = sigma0;
            int    qq       = 1;

            GaussCore GaussMatrix = new GaussCore(sigma0);

            TekImg.SvertkaWithNormalize(GaussMatrix.Matrix, GaussMatrix.Radius, 1);
            Piramida[0, 0] = new Img(TekImg.Bitmap);

            GlobalSigma = new double[O + 1, S + 3];
            Sigma       = new double[O + 1, S + 3];


            Sigma[0, 0]       = sigmaTEK;
            GlobalSigma[0, 0] = sigmaD;

            for (int o = 0; o < O + 1; o++)
            {
                TekImg = new Img(Piramida[o, 0].Bitmap);
                for (int s = 1; s < S + 3; s++)
                {
                    double sigma1 = sigma0 * Math.Pow(k, (s - 1));
                    double sigma2 = sigma0 * Math.Pow(k, s);
                    sigmaTEK          = Math.Sqrt(sigma2 * sigma2 - sigma1 * sigma1); // Текущая сигма
                    Sigma[o, s]       = sigma2;
                    sigmaD            = sigma0 * Math.Pow(k, qq);
                    GlobalSigma[o, s] = sigmaD;
                    qq++;
                    GaussMatrix = new GaussCore(sigmaTEK);
                    TekImg.SvertkaWithNormalize(GaussMatrix.Matrix, GaussMatrix.Radius, 1);
                    Piramida[o, s] = new Img(TekImg.Bitmap);

                    if ((o + 1) != (O + 1) && s == S)
                    {
                        Piramida[o + 1, 0] = new Img(TekImg.Bitmap);
                        Piramida[o + 1, 0].Downsample();

                        Sigma[o + 1, 0]       = sigma0;
                        GlobalSigma[o + 1, 0] = sigmaD;
                    }
                }
                qq = qq - 2;
            }

            for (int o = 0; o < O + 1; o++)
            {
                for (int s = 0; s < S + 2; s++)
                {
                    double[,] RMtx = new double[Piramida[o, 0].Height, Piramida[o, 0].Width];
                    for (int y = 0; y < Piramida[o, 0].Height; y++)
                    {
                        for (int x = 0; x < Piramida[o, 0].Width; x++)
                        {
                            RMtx[y, x] = Math.Abs(Piramida[o, s + 1].GrayMatrixDouble[y, x] - Piramida[o, s].GrayMatrixDouble[y, x]);
                        }
                    }
                    DoG[o, s] = new Img(RMtx, Piramida[o, 0].Width, Piramida[o, 0].Height);
                    DoG[o, s].Save(BasePath + "Lab 6/i" + Convert.ToString(o) + Convert.ToString(s) + ".png");
                }
            }
        }
Esempio n. 2
0
        /* Пирамида */
        private void button3_Click(object sender, EventArgs e)
        {
            bool mTr = true;

            if (textBox1.Text == "" || textBox2.Text == "")
            {
                mTr = false;
                MessageBox.Show("Введите данные", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            if (mTr)
            {
                F.ClearDir(BasePath + "Lab 2");
                F.ClearDir(BasePath + "Lab 2/Core");

                double sigma0 = Convert.ToDouble(textBox1.Text);  // Сигма 0
                int    S      = Convert.ToInt32(textBox2.Text);   // Число масштабов в октаве
                double k      = Math.Pow(2.0, (1.0 / (double)S)); // Интервал между масштабами

                int minr = Math.Min(IWidth, IHeight);
                int O    = 0;                              // Число октав
                while (minr > 32)
                {
                    minr /= 2;
                    O++;
                }

                Img TekImg = new Img(GrayImg.GrayMatrix, IWidth, IHeight);
                TekImg.Save(BasePath + "Lab 2/000.png");
                double sigmaD   = sigma0;                      // Действительная сигма
                double sigmaTEK = sigma0;
                double qq       = 1;

                GaussCore GaussMatrix = new GaussCore(sigma0);
                Img       GaussImg    = new Img(GaussMatrix.Matrix, GaussMatrix.Size, GaussMatrix.Size);
                TekImg.SvertkaWithNormalize(GaussMatrix.Matrix, GaussMatrix.Radius, 1);
                TekImg.Save(BasePath + "Lab 2/" + "00"
                            + " - S1=" + Convert.ToString(Math.Round(sigma0, 2)) + " - Sd=" + Convert.ToString(Math.Round(sigma0, 2)) + ".png");
                GaussImg.Save(BasePath + "Lab 2/Core/" + "00" + ".png");

                for (int o = 0; o < O; o++)
                {
                    for (int s = 1; s <= S; s++)
                    {
                        double sigma1 = sigma0 * Math.Pow(k, (s - 1));
                        double sigma2 = sigma0 * Math.Pow(k, s);
                        sigmaTEK = Math.Sqrt(sigma2 * sigma2 - sigma1 * sigma1);// Текущая сигма
                        sigmaD   = sigma0 * Math.Pow(k, qq);
                        qq++;
                        GaussMatrix = new GaussCore(sigmaTEK);
                        GaussImg    = new Img(GaussMatrix.Matrix, GaussMatrix.Size, GaussMatrix.Size);
                        TekImg.SvertkaWithNormalize(GaussMatrix.Matrix, GaussMatrix.Radius, 1);
                        TekImg.Save(BasePath + "Lab 2/" + Convert.ToString(o) + Convert.ToString(s)
                                    + " - S1=" + Convert.ToString(Math.Round(sigma2, 2)) + " - Sd=" + Convert.ToString(Math.Round(sigmaD, 2)) + ".png");
                        GaussImg.Save(BasePath + "Lab 2/Core/" + Convert.ToString(o) + Convert.ToString(s) + ".png");
                    }
                    TekImg.Downsample();
                    TekImg.Save(BasePath + "Lab 2/" + Convert.ToString(o + 1) + "0"
                                + " - S1=" + Convert.ToString(Math.Round(sigma0, 2)) + " - Sd=" + Convert.ToString(Math.Round(sigmaD, 2)) + ".png");
                }
            }
        }