示例#1
0
        /// <summary>
        /// BPF от реального массива по строкам
        /// </summary>
        /// <param name="zarray"></param>
        /// <param name="sdvig"></param>   Сдвиг
        /// <returns></returns>
        public static ZComplexDescriptor BPF_Real(ZArrayDescriptor zarray, int sdvig)
        {
            int nx = zarray.width;
            int ny = zarray.height;

            int m  = 1;
            int nn = 2;

            for (int i = 1; ; i++)
            {
                nn = nn * 2; if (nn > nx)
                {
                    m = i; break;
                }
            }
            int n = Convert.ToInt32(Math.Pow(2.0, m));                                  // N=2**m


            // MessageBox.Show("nx: " + nx  + "   m: " + m + "   n: " + n);

            //Complex[] array_exp = P_EXP(m + 1);                             // Экспонента для BPF
            //int[] array_inv = Invers(m, nx);                                // Инверсия элементов массива для БПФ

            Complex[] Array  = new Complex[n];                               // Выходной массив
            Complex[] ArrayX = new Complex[n];                               // Комплексный массив экспоненты сдвига

            for (int i = 0; i < n; i++)
            {
                double a = 2 * Math.PI * sdvig * i / n;
                ArrayX[i] = new Complex(Math.Cos(a), -Math.Sin(a));
            }

            ZComplexDescriptor resultArray = new ZComplexDescriptor(n, ny);  // Re=zArrayPicture Im=0

            for (int j = 0; j < ny; j++)
            {
                for (int i = 0; i < n; i++)
                {
                    Array[i] = new Complex(zarray.array[i, j], 0.0);
                }
                for (int i = 0; i < n; i++)
                {
                    Array[i] = Array[i] * ArrayX[i];
                }
                //Array = BPF_Q(Array, m, array_exp, array_inv);
                Array = Furie.GetFourierTransform(Array, m);
                for (int i = 0; i < n; i++)
                {
                    resultArray.array[i, j] = Array[i];
                }
            }

            return(resultArray);
        }
示例#2
0
        public static void Complex_ArrayDescriptor(ZComplexDescriptor[] zComplex, ZArrayDescriptor[] zArrayDescriptor, int regComplex)     // Из zComplex в zArrayDescriptor
        {
            if (zComplex[regComplex] == null)
            {
                MessageBox.Show("ZComplexDescriptor: Complex_ArrayDescriptor:  zComplex[regComplex] == NULL"); return;
            }

            int width  = zComplex[regComplex].width;
            int height = zComplex[regComplex].height;

            double[,] Image_double = new double[width, height];

            Image_double = Furie.Re(zComplex[regComplex].array);
            zArrayDescriptor[regComplex * 4 + 0] = new ZArrayDescriptor(Image_double);

            Image_double = Furie.Im(zComplex[regComplex].array);
            zArrayDescriptor[regComplex * 4 + 1] = new ZArrayDescriptor(Image_double);

            Image_double = Furie.Amplituda(zComplex[regComplex].array);
            zArrayDescriptor[regComplex * 4 + 2] = new ZArrayDescriptor(Image_double);

            Image_double = Furie.Faza(zComplex[regComplex].array);
            zArrayDescriptor[regComplex * 4 + 3] = new ZArrayDescriptor(Image_double);
        }
        public static void Conv_D(int k3, int k4, int k5, ProgressBar progressBar1) // Корреляция двух вещественных массивов
        {
            k3--; k4--; k5--;                                                       // Массив 1 ->  0

            //MessageBox.Show("k3= " + k3 + " - k4= " + k4 + " = k5= " + k5);

            if (Form1.zArrayDescriptor[k3] == null)
            {
                MessageBox.Show("Mul_C zComplex[" + k3 + "] == NULL"); return;
            }
            if (Form1.zArrayDescriptor[k4] == null)
            {
                MessageBox.Show("Mul_C zComplex[" + k4 + "] == NULL"); return;
            }

            int nx = Form1.zArrayDescriptor[k3].width;
            int ny = Form1.zArrayDescriptor[k3].height;

            int nx1 = Form1.zArrayDescriptor[k4].width;
            int ny1 = Form1.zArrayDescriptor[k4].height;

            if ((nx != nx1) || (ny != ny1))
            {
                MessageBox.Show("Mul_C Размеры массивов не согласованы"); return;
            }


            progressBar1.Visible = true;
            progressBar1.Minimum = 1;
            progressBar1.Maximum = 3;
            progressBar1.Value   = 1;
            progressBar1.Step    = 1;


            ZArrayDescriptor b = new ZArrayDescriptor(ny, nx);

            for (int i = 0; i < nx; i++)                                    // Транспонирование первого массива
            {
                for (int j = 0; j < ny; j++)
                {
                    b.array[j, i] = Form1.zArrayDescriptor[k3].array[i, j];
                }
            }
            progressBar1.PerformStep();                             // ------------------------------------ 1 шаг

            ZComplexDescriptor zCmpl1 = new ZComplexDescriptor(b);  // Конструктор для заполнения реальной части и мнимой части = 0
            ZComplexDescriptor zCmpl2 = new ZComplexDescriptor(Form1.zArrayDescriptor[k4]);

            zCmpl1 = FurieN.BPF2(zCmpl1); progressBar1.PerformStep();       // ------------------------------------ 2 шаг
            zCmpl2 = FurieN.BPF2(zCmpl2); progressBar1.PerformStep();       // ------------------------------------ 3 шаг

            ZComplexDescriptor a = new ZComplexDescriptor(nx, nx);          // Результирующая матрица (ny x nx)*(nx * ny) = (nx x nx)

            progressBar1.Maximum = nx;
            progressBar1.Value   = 1;

            Complex s0 = new Complex(0, 0);

            for (int i = 0; i < nx; i++)
            {
                for (int j = 0; j < nx; j++)
                {
                    Complex s = s0;
                    for (int y = 0; y < ny; y++)
                    {
                        s += zCmpl1.array[y, j] * zCmpl2.array[i, y];     // Строка на столбец
                    }
                    a.array[i, j] = s;
                }
                progressBar1.PerformStep();
            }
            progressBar1.Value = 1;

            a = FurieN.BPF2(a);                                             // ------------------------------------ 5 шаг
            Form1.zArrayDescriptor[k5] = Furie.zAmplituda(a);


            VisualRegImage(k5);
        }
示例#4
0
        public static ZComplexDescriptor Inverse2_BPF(int sdvig, int DX)
        {
            //if (Form1.zComplex[k1] == null) { MessageBox.Show("FurieN zComplex[k2] == NULL"); return null; }


            //int nx = Form1.zArrayPicture.width;
            //if (nx % 2 != 0) nx = nx - 1;                            // n - должно быть четным
            //int ny = 50;
            //nx = 4874;

            int nx = 4096;
            int ny = 200;
            int m  = 1;
            int nn = 2;

            for (int i = 1; ; i++)
            {
                nn = nn * 2; if (nn > nx)
                {
                    m = i; break;
                }
            }
            int n = Convert.ToInt32(Math.Pow(2.0, m));                        // N=2**m

            Complex[] ArrayX = new Complex[nx];                               // Комплексный массив экспоненты сдвига
            Complex[] Array  = new Complex[nx];



            ZComplexDescriptor resultArray = new ZComplexDescriptor(nx, ny);  // Re=zArrayPicture Im=0

            // for (int i = 0; i < nx; i++)
            // {
            //     double a = 2 * Math.PI * sdvig * i / nx;
            //     ArrayX[i] = new Complex(Math.Cos(a), -Math.Sin(a));
            // }

            for (int j = 0; j < ny; j++)                                        // Преобразование Фурье
            {
                for (int i = 0; i < nx; i++)
                {
                    Array[i] = new Complex(Form1.zArrayPicture.array[i, j], 0.0);
                }
                //for (int i = 0; i < nx; i++) { Array[i] = Array[i] * ArrayX[i]; }
                Array = Furie.GetFourierTransform(Array, m);
                for (int i = 0; i < nx; i++)
                {
                    resultArray.array[i, j] = Array[i];
                }
            }

            Complex[] ArrayY = new Complex[nx];
            for (int i = sdvig, j = 0; i < sdvig + DX; i++, j++)
            {
                ArrayY[i] = new Complex(DX - j, DX - j);
            }
            for (int i = sdvig, j = 0; i > sdvig - DX; i--, j++)
            {
                ArrayY[i] = new Complex(DX - j, DX - j);
            }

            //for (int i = sdvig, j = 0; i < sdvig + DX; i++, j++) { ArrayY[nx-i] = new Complex(DX - j, DX - j); }
            //for (int i = sdvig, j = 0; i > sdvig - DX; i--, j++) { ArrayY[nx-i] = new Complex(DX - j, DX - j); }

            //for (int i = nx - DX, k = 0; i < nx; i++, k++) { ArrayY[i] = new Complex(k, 0); }
            //for (int i = 0; i < DX; i++) { ArrayY[i] = ArrayY[i] / DX; }
            //for (int i = nx - DX; i < nx; i++) { ArrayY[i] = ArrayY[i] / DX; }

            //for (int i = 4004; i < 4028; i++) { ArrayY[i] = new Complex(1, 0); }
            //for (int i = nx - DX; i < nx; i++) { Array[i] = new Complex(1, 0); }

            for (int j = 0; j < ny; j++)
            {
                for (int i = 0; i < nx; i++)
                {
                    Array[i] = resultArray.array[i, j] * ArrayY[i];
                }
                //for (int i = 0; i < nx; i++) { Array[i] = resultArray.array[i, j] ; }
                Array = Furie.GetInverseFourierTransform(Array, m);
                for (int i = 0; i < nx; i++)
                {
                    resultArray.array[i, j] = Array[i];
                }
            }

            return(resultArray);
        }
示例#5
0
        public static ZComplexDescriptor Inverse_BPF(int k2, int sdvig, int DX)
        {
            int nx = 4096;
            int ny = 200;

            int m  = 1;
            int nn = 2;

            for (int i = 1; ; i++)
            {
                nn = nn * 2; if (nn > nx)
                {
                    m = i; break;
                }
            }
            int n = Convert.ToInt32(Math.Pow(2.0, m));                                  // N=2**m


            MessageBox.Show("nx: " + nx + "   m: " + m);

            Complex[] Array = new Complex[nx];
            for (int i = 0; i < DX; i++)
            {
                Array[i] = new Complex(1, 0);
            }
            for (int i = nx - DX; i < nx; i++)
            {
                Array[i] = new Complex(1, 0);
            }

            for (int i = 0; i < DX; i++)
            {
                Array[i] = new Complex(DX - i, 0);
            }
            for (int i = nx - DX, k = 0; i < nx; i++, k++)
            {
                Array[i] = new Complex(k, 0);
            }
            for (int i = 0; i < DX; i++)
            {
                Array[i] = Array[i] / DX;
            }
            for (int i = nx - DX; i < nx; i++)
            {
                Array[i] = Array[i] / DX;
            }


            Array = Furie.GetInverseFourierTransform(Array, m);

            ZComplexDescriptor resultArray = new ZComplexDescriptor(nx, ny);  // Re=zArrayPicture Im=0

            for (int j = 0; j < ny; j++)
            {
                for (int i = 0; i < nx; i++)
                {
                    resultArray.array[i, j] = Array[i];
                }
            }

            return(resultArray);
        }