예제 #1
0
        //
        //                         Устранение фазовой неоднозначности
        //
        public static ZArrayDescriptor Shift_Picture(ZArrayDescriptor zArrayPicture, double o_gr, double o_mn)
        {
            if (zArrayPicture == null)
            {
                MessageBox.Show("SumClass ZArrayDescriptor array == null"); return(null);
            }
            int width  = zArrayPicture.width;
            int height = zArrayPicture.height;
            ZArrayDescriptor z_array = new  ZArrayDescriptor(width, height);
            double           max     = getMax(zArrayPicture);
            //double min = getMin(zArrayPicture);
            double min = o_mn;

            for (int j = 0; j < width; j++)
            {
                for (int i = 0; i < height; i++)
                {
                    double c = zArrayPicture.array[i, j];
                    if (c > o_gr)
                    {
                        c = min - (max - c);
                    }
                    z_array.array[i, j] = c;
                }
            }


            return(z_array);
        }
예제 #2
0
        public static ZArrayDescriptor Range_Array1(ZArrayDescriptor zArrayPicture, double fmax)
        {
            if (zArrayPicture == null)
            {
                MessageBox.Show("SumClass ZArrayPicture == null"); return(null);
            }
            int width  = zArrayPicture.width;
            int height = zArrayPicture.height;
            ZArrayDescriptor rezult = new ZArrayDescriptor(width, height);

            double min = getMin(zArrayPicture);
            double max = getMax(zArrayPicture);

            if (max == min)
            {
                return(rezult);
            }

            double max1 = max - min;

            //MessageBox.Show("fmax1 = " + fmax);

            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    double fc = zArrayPicture.array[i, j];

                    rezult.array[i, j] = fmax * (fc - min) / max1;
                }
            }
            return(rezult);
        }
예제 #3
0
        /// <summary>
        /// Суммирование строк в массиве от 0 до h1
        /// </summary>
        /// <param name="zArray"></param>
        /// <returns></returns>
        public static ZArrayDescriptor Sum_zArrayY_ALL(ZArrayDescriptor zArray)
        {
            if (zArray == null)
            {
                MessageBox.Show(" Sum_zArrayY: zArrayDescriptor == null"); return(null);
            }
            int w1 = zArray.width;
            int h1 = zArray.height;

            ZArrayDescriptor res_array = new ZArrayDescriptor(w1, h1);

            double[] array_line = new double[w1];

            for (int i = 0; i < w1; i++)
            {
                for (int j = 0; j < h1; j++)
                {
                    array_line[i] += zArray.array[i, j];
                }
            }

            for (int i = 0; i < w1; i++)
            {
                for (int j = 0; j < h1; j++)
                {
                    res_array.array[i, j] = array_line[i] / h1;
                }
            }

            return(res_array);
        }
예제 #4
0
        //  Увеличение размера файла в 2 раза простым повторением

/*
 *      public static ZArrayDescriptor Filt_2_1(ZArrayDescriptor amp)
 *      {
 *
 *          int w1 = amp.width;
 *          int h1 = amp.height;
 *          int w2 = 2*w1;
 *          int h2 = 2*h1;
 *          ZArrayDescriptor res_array = new ZArrayDescriptor(w2, h2);
 *
 *          for (int i = 0; i < w2; i ++)
 *              for (int j = 0; j < h2; j ++)
 *              {
 *                  res_array.array[i, j] = amp.array[i/2, j/2];
 *              }
 *          return res_array;
 *      }
 */
        //  Увеличение размера файла в 2 раза с усреднением

        public static ZArrayDescriptor Filt_2_1_s(ZArrayDescriptor amp)
        {
            int w1 = amp.width;
            int h1 = amp.height;
            int w2 = 2 * w1;
            int h2 = 2 * h1;
            ZArrayDescriptor res_array = new ZArrayDescriptor(w2, h2);

            for (int i = 0; i < w2 - 2; i++)
            {
                for (int j = 0; j < h2 - 2; j++)
                {
                    if (i % 2 == 0 || i % 2 == 0)
                    {
                        res_array.array[i, j] = amp.array[i / 2, j / 2];
                    }
                    else
                    {
                        int    ii = i / 2, jj = j / 2;
                        double a = (amp.array[ii, jj] + amp.array[ii, jj + 1] +
                                    amp.array[ii + 1, jj] + amp.array[ii + 1, jj + 1]);
                        res_array.array[i, j] = a / 4;
                    }
                }
            }
            return(res_array);
        }
예제 #5
0
        // Конструктор для заполнения фазы (Амплитуда постоянная)

        public ZComplexDescriptor(ZArrayDescriptor descriptorToCopy, double am)
        {
            if (descriptorToCopy == null)
            {
                MessageBox.Show("ZComplexDescriptor == NULL"); return;
            }

            width  = descriptorToCopy.width;
            height = descriptorToCopy.height;
            array  = new Complex[width, height];

            double max = SumClass.getMax(descriptorToCopy);
            double min = SumClass.getMin(descriptorToCopy);

            //MessageBox.Show("width =" + Convert.ToString(width) + "height =" + Convert.ToString(height));
            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    double a = descriptorToCopy.array[i, j];
                    a           = (a - min) * 2.0 * Math.PI / (max - min);
                    a           = a - Math.PI;
                    array[i, j] = Complex.FromPolarCoordinates(am, a);

                    //array[i, j] = new Complex(1.0, descriptorToCopy.array[i, j]);
                }
            }
        }
예제 #6
0
        public static ZArrayDescriptor Filt1_NхN(ZArrayDescriptor amp, int k) // Для нечетных k
        {
            int w1 = amp.width;
            int h1 = amp.height;

            ZArrayDescriptor res_array = new ZArrayDescriptor(w1, h1);

            for (int i = 0; i < w1; i++)
            {
                for (int j = 0; j < h1; j++)
                {
                    res_array.array[i, j] = amp.array[i, j];
                }
            }

            for (int i = k / 2; i < w1 - k / 2 - 1; i++)
            {
                for (int j = k / 2; j < h1 - k / 2 - 1; j++)
                {
                    res_array.array[i, j] = Sum_NхN(amp, k, i, j);
                }
            }

            return(res_array);
        }
예제 #7
0
        //------------------------------------------------------------------------------------------------  ZArrayDescriptor
        public static void saveZArray(ZArrayDescriptor arrayDescriptor)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();

            saveFileDialog.Filter           = "array files (*.zarr)|*.zarr|All files (*.*)|*.*";
            saveFileDialog.FilterIndex      = 1;
            saveFileDialog.RestoreDirectory = true;

            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    Stream stream;
                    if ((stream = saveFileDialog.OpenFile()) != null)
                    {
                        BinaryFormatter serializer = new BinaryFormatter();
                        serializer.Serialize(stream, arrayDescriptor);
                        stream.Close();
                    }
                }
                catch (Exception ex)
                {
                    System.Windows.Forms.MessageBox.Show("Ошибка при записи файла double : " + ex.Message);
                }
            }
        }
예제 #8
0
        public static void ROT180_D()             // Поворот zArrayDescriptor[regImage] на 180 градусов
        {
            if (Form1.zArrayDescriptor[Form1.regImage] == null)
            {
                MessageBox.Show(" ROR_TRNS  zArrayDescriptor [" + Form1.regImage + "] == NULL"); return;
            }

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

            ZArrayDescriptor zArray = new ZArrayDescriptor(nx, ny);

            for (int i = 0; i < nx; i++)
            {
                for (int j = 0; j < ny; j++)
                {
                    zArray.array[i, j] = Form1.zArrayDescriptor[Form1.regImage].array[i, ny - 1 - j];
                }
            }
            //MessageBox.Show(" ROR_TRNS 1");

            Form1.zArrayDescriptor[Form1.regImage] = zArray;
            //MessageBox.Show(" ROR_TRNS 2");
            VisualRegImage(Form1.regImage);
        }
예제 #9
0
        public static ZArrayDescriptor loadImage()
        {
            OpenFileDialog dialog1 = new OpenFileDialog();

            dialog1.Filter           = "All files (*.*)|*.*|bmp files (*.bmp)|*.bmp";
            dialog1.FilterIndex      = 1;
            dialog1.RestoreDirectory = true;


            if (dialog1.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    dialog1.InitialDirectory = dialog1.FileName;

                    Image            newImage = Image.FromFile(dialog1.FileName);
                    ZArrayDescriptor z_array  = new ZArrayDescriptor(newImage.Width, newImage.Height);
                    z_array = Util_array.getArrayFromImage(newImage);

                    return(z_array);
                }
                catch (Exception ex) { System.Windows.Forms.MessageBox.Show("class File_Helper Ошибка при чтении изображения" + ex.Message); return(null); }
            }
            return(null);
        }
        //
        //                     Добавление фазового сдвига  fz и получение голограммы
        //
        public static ZArrayDescriptor Model_pl_PSI(double am, ZComplexDescriptor cmpl0,
                                                    double AngleX, double AngleY, double Lambda, double dx, double noise, double fz)
        {
            int    NX = cmpl0.width;
            int    NY = cmpl0.height;
            double kx = dx / NX;
            double ky = dx / NY;

            ZArrayDescriptor cmpl = new ZArrayDescriptor(NX, NY);     // Результирующий фронт

            am = SumClass.getAverage(cmpl0);                          // Амплитуда опорного пучка равна средней амплитуды объектного
            //MessageBox.Show("am = " + am + " fz= " + fz);

            Random rnd = new Random((int)DateTime.Now.Ticks & 0x0000FFFF);

            for (int i = 0; i < NX; i++)
            {
                for (int j = 0; j < NY; j++)
                {
                    double fz1 = 2 * Math.PI * (Math.Sin(AngleX) * kx * i + Math.Sin(AngleY) * ky * j) / Lambda;
                    double fa  = rnd.NextDouble() * 2.0 * Math.PI - Math.PI;

                    double f0 = fz1 + fa * noise + fz;

                    double Ap = cmpl0.array[i, j].Magnitude;                                   // амплитуда объектного пучка
                    double Fp = cmpl0.array[i, j].Phase;                                       // Фаза объектного пучка
                    cmpl.array[i, j] = Ap * Ap + am * am + 2 * Ap * am * Math.Cos(Fp - f0);    // Интенсивность
                }
            }

            return(cmpl);
        }
예제 #11
0
        //
        //         Из PictureBox в  ZArrayDescriptor.array
        //
        public static ZArrayDescriptor getArrayFromImage(PictureBox pictureBox)
        {
            if (pictureBox == null)
            {
                MessageBox.Show("pictureBox == null"); return(null);
            }


            int        w1   = pictureBox.Image.Width;
            int        h1   = pictureBox.Image.Height;
            Bitmap     bmp1 = new Bitmap(pictureBox.Image, w1, h1);
            BitmapData data = ImageProcessor.getBitmapData(bmp1);


            ZArrayDescriptor result = new ZArrayDescriptor();

            result.array  = new double[w1, h1];
            result.width  = w1;
            result.height = h1;

            for (int i = 0; i < w1; i++)
            {
                for (int j = 0; j < h1; j++)
                {
                    Color c = ImageProcessor.getPixel(i, j, data);
                    result.array[i, j] = (c.R + c.G + c.B) / 3;
                    //result.array[i, j] = ImageProcessor.getPixel_blue(j, i, data);
                }
            }

            bmp1.UnlockBits(data);

            return(result);
        }
예제 #12
0
        public static ZArrayDescriptor loadZArray()
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter           = "array files (*.zarr)|*.zarr|All files (*.*)|*.*";
            openFileDialog.FilterIndex      = 1;
            openFileDialog.RestoreDirectory = true;

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    Stream myStream;
                    if ((myStream = openFileDialog.OpenFile()) != null)
                    {
                        using (myStream)
                        {
                            BinaryFormatter  deserializer = new BinaryFormatter();
                            ZArrayDescriptor savedArray   = (ZArrayDescriptor)deserializer.Deserialize(myStream);
                            myStream.Close();
                            return(savedArray);
                        }
                    }
                }
                catch (Exception ex)
                {
                    System.Windows.Forms.MessageBox.Show("Ошибка при чтении файла double  :" + ex.Message);
                    return(null);
                }
            }

            return(null);
        }
예제 #13
0
        public static ComplexNumber[] ToArrayByRows(ZArrayDescriptor ampl)   // Прямое преобразование массива в FFT из ZArrayDescriptor
        {
            //Stopwatch sw = new Stopwatch();
            // sw.Start();
            int row = ampl.width;
            int col = ampl.height;

            int count = row * col;

            ComplexNumber[] array = new ComplexNumber[count];
            int             k     = 0;

            for (int i = 0; i < row; i++)
            {
                for (int j = 0; j < col; j++)
                {
                    array[k] = new ComplexNumber(ampl.array[i, j], 0);
                    k++;
                }
            }

            // sw.Stop();
            // Console.WriteLine("Copy matrix to one dimaensional array: {0}", sw.Elapsed);

            return(array);
        }
예제 #14
0
        public static ZArrayDescriptor Filt1_2х2(ZArrayDescriptor amp)
        {
            int w1 = amp.width;
            int h1 = amp.height;

            ZArrayDescriptor res_array = new ZArrayDescriptor(w1, h1);

            for (int i = 0; i < w1; i++)
            {
                for (int j = 0; j < h1; j++)
                {
                    res_array.array[i, j] = amp.array[i, j];
                }
            }

            for (int i = 0; i < w1 - 1; i++)
            {
                for (int j = 0; j < h1 - 1; j++)
                {
                    res_array.array[i, j] = Sum_2х2(amp, i, j);
                }
            }

            return(res_array);
        }
        public void Stolb_a0(int i, int N2x, ZArrayDescriptor data2, int Ny, int NyP)
        {
            int N2 = 0;

            if (Ny > NyP)
            {
                N2 = (Ny - NyP) / 2;
                for (int j = 0; j < N2; j++)
                {
                    array[i, j] = 0;                          // 127;
                }
                for (int j = N2; j < Ny - N2; j++)
                {
                    array[i, j] = data2.array[i - N2x, j - N2];
                }
                for (int j = Ny - N2; j < Ny; j++)
                {
                    array[i, j] = 0;                                // 127;
                }
            }
            else
            {
                for (int j = 0; j < Ny; j++)
                {
                    array[i, j] = data2.array[i - N2x, j];
                }
            }
        }
        // Сложение с плоской волной => интенсивность в центральное окно

        public static ZArrayDescriptor Model_pl_ADD_I(double am, ZComplexDescriptor cmpl0,
                                                      double AngleX, double AngleY, double Lambda, double dx, double noise, double fzr)
        {
            MessageBox.Show("am = " + am);
            int NX = cmpl0.width;
            int NY = cmpl0.height;

            //ZComplexDescriptor cmpl1 = new ZComplexDescriptor(NX, NY);      // Фронт под углом AngleX,  AngleY
            ZArrayDescriptor cmpl = new ZArrayDescriptor(NX, NY);             // Результирующая интенсивность
            double           kx   = dx / NX;
            double           ky   = dx / NY;

            // a = (a - min) * 2.0 * Math.PI / (max - min);   -pi +pi
            //am = SumClass.getAverage(cmpl0);  // Средняя интенсивность комплексного массива

            Random rnd = new Random((int)DateTime.Now.Ticks & 0x0000FFFF);

            for (int i = 0; i < NX; i++)
            {
                for (int j = 0; j < NY; j++)
                {
                    double fz = 2 * Math.PI * (Math.Sin(AngleX) * kx * i + Math.Sin(AngleY) * ky * j) / Lambda;
                    double fa = rnd.NextDouble() * 2.0 * Math.PI - Math.PI;
                    double f0 = fz + fa * noise + fzr;
                    //Complex Pl = Complex.FromPolarCoordinates(am, f0);

                    //cmpl.array[i, j] = cmpl0.array[i, j] + Pl;
                    double a = cmpl0.array[i, j].Magnitude;
                    double f = cmpl0.array[i, j].Phase;
                    cmpl.array[i, j] = a * a + am * am + 2 * a * am * Math.Cos(f - f0);
                }
            }
            cmpl = SumClass.Range_Array1(cmpl, am);      // Приведение к диапазону от 0 до am
            return(cmpl);
        }
        // Конструктор array из  zArray
        // если изображение меньше чем  Nx,  Ny, то оно помещается в левый угол, если изображение больше, то оно обрезается
        //
        public ZArrayDescriptor(ZArrayDescriptor zArrayPicture, int Nx, int Ny, int k)
        {
            if (zArrayPicture == null)
            {
                MessageBox.Show("zArrayPicture = NULL"); return;
            }
            if (k != 1)
            {
                MessageBox.Show(" ZArrayDescriptor k != 1"); return;
            }


            width  = Nx;
            height = Ny;
            array  = new double[Nx, Ny];
            int Nx_z = zArrayPicture.width;
            int Ny_z = zArrayPicture.height;

            Nx_z = Math.Min(Nx, Nx_z);
            Ny_z = Math.Min(Ny, Ny_z);

            for (int i = 0; i < Nx_z; i++)
            {
                for (int j = 0; j < Ny_z; j++)
                {
                    array[i, j] = zArrayPicture.array[i, j];
                }
            }
        }
예제 #18
0
        //  Усреднение 2х2 точек с уменьшением размера файла со сдвигом

        public static ZArrayDescriptor Filt_2х2(ZArrayDescriptor amp, int kx, int ky)   // int kx, int ky - сдвиг массива точек
        {
            int w1 = amp.width;
            int h1 = amp.height;
            int w2 = w1 / 2;
            int h2 = h1 / 2;
            ZArrayDescriptor res_array = new ZArrayDescriptor(w2, h2);

            for (int i = 0; i < w1; i += 2)
            {
                for (int j = 0; j < h1; j += 2)
                {
                    res_array.array[i / 2, j / 2] = amp.array[i, j];
                }
            }

            for (int i = 0; i < w1 - kx - 1; i += 2)
            {
                for (int j = 0; j < h1 - ky - 1; j += 2)
                {
                    double a = (amp.array[i + kx, j + ky] + amp.array[i + kx, j + 1 + ky] +
                                amp.array[i + 1 + kx, j + ky] + amp.array[i + 1 + kx, j + 1 + ky]);
                    res_array.array[i / 2, j / 2] = a / 4;
                }
            }
            return(res_array);
        }
예제 #19
0
//-------------------------------------------------------------------------------------------------------------------------



        public static ZArrayDescriptor ATAN_am(ZArrayDescriptor[] zArrayPicture, double[] fzz)
        {
            // 8, 9, 10, 11   ->    Complex[1]

            int w1 = zArrayPicture[0].width;
            int h1 = zArrayPicture[0].height;

            ZArrayDescriptor faza = new ZArrayDescriptor(w1, h1);

            int n_sdv = 4;                                                       // Число фазовых сдвигов

            double[] i_sdv = new double[4];
            double[] v_sdv = new double[4];                                  // Вектор коэффициентов
            double[] k_sin = new double[4];
            double[] k_cos = new double[4];


            for (int i = 0; i < n_sdv; i++)
            {
                k_sin[i] = Math.Sin(fzz[i]);
                k_cos[i] = Math.Cos(fzz[i]);
            }


            for (int i = 0; i < w1; i++)
            {
                for (int j = 0; j < h1; j++)
                {
                    i_sdv[0] = zArrayPicture[0].array[i, j];
                    i_sdv[1] = zArrayPicture[1].array[i, j];
                    i_sdv[2] = zArrayPicture[2].array[i, j];
                    i_sdv[3] = zArrayPicture[3].array[i, j];

                    // ------                                     Формула расшифровки

                    v_sdv[0]         = i_sdv[1] - i_sdv[n_sdv - 1];
                    v_sdv[n_sdv - 1] = i_sdv[0] - i_sdv[n_sdv - 2];

                    for (int ii = 1; ii < n_sdv - 1; ii++)
                    {
                        v_sdv[ii] = i_sdv[ii + 1] - i_sdv[ii - 1];
                    }

                    double fz1 = 0;
                    double fz2 = 0;

                    for (int ii = 0; ii < n_sdv; ii++)
                    {
                        fz1 += v_sdv[ii] * k_sin[ii];
                        fz2 += v_sdv[ii] * k_cos[ii];
                    }


                    faza.array[i, j] = Math.Atan2(fz1, fz2);
                }
            }

            return(faza);
        }
예제 #20
0
        // Конструктор для случайного заполнения фазы (RANDOM) (Амплитуда из файла, k=1)

        public ZComplexDescriptor(ZArrayDescriptor descriptorToCopy, ZArrayDescriptor amp, int k)
        {
            if (amp == null)
            {
                MessageBox.Show("Ampl == NULL");               return;
            }
            if (descriptorToCopy == null)
            {
                MessageBox.Show("ZArrayDescriptor   == NULL"); return;
            }
            if (k != 1)
            {
                MessageBox.Show(" k!=1 ");                     return;
            }

            width  = amp.width;
            height = amp.height;
            array  = new Complex[width, height];

            double max = SumClass.getMax(descriptorToCopy);
            double min = SumClass.getMin(descriptorToCopy);

            int NX = descriptorToCopy.width;
            int NY = descriptorToCopy.height;

            if (NX > width)
            {
                NX = width;
            }
            if (NY > height)
            {
                NY = height;
            }
            //MessageBox.Show("width =" + Convert.ToString(width) + "height =" + Convert.ToString(height));
            Random rnd = new Random();

            for (int i = 0; i < NX; i++)
            {
                for (int j = 0; j < NY; j++)
                {
                    double am = amp.array[i, j];
                    double fz = descriptorToCopy.array[i, j];
                    double fa = rnd.NextDouble() * 2.0 * Math.PI - Math.PI;
                    fz = fz + fa;
                    //if (fz > Math.PI) fz = fz - Math.PI;
                    //if (fz < -Math.PI) fz = fz + Math.PI;
                    if (am <= 0)
                    {
                        fz = 0;                                       // По шаблону
                    }
                    //if (a > 0) a = rnd.NextDouble() *  Math.PI ; else a = 0;
                    array[i, j] = Complex.FromPolarCoordinates(am, fz);
                }
            }
        }
예제 #21
0
 public void SetImage(ZArrayDescriptor zArray)
 {
     this.imageBox.Invoke
     (
         (MethodInvoker) delegate
     {
         Vizual.Vizual_Picture(zArray, this.imageBox);
         this.imageBox.Refresh();
     }
     );
 }
예제 #22
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);
        }
예제 #23
0
        //  Усреднение 2х2 точек

        public static double Sum_2х2(ZArrayDescriptor amp, int i, int j)   // int kx, int ky - сдвиг массива точек
        {
            int w1 = amp.width;
            int h1 = amp.height;

            double a = 0;

            a = amp.array[i, j] + amp.array[i + 1, j] + amp.array[i, j + 1] + amp.array[i + 1, j + 1];

            return(a / 4);
        }
예제 #24
0
        public static ZArrayDescriptor loadImage_from_File(string str)
        {
            try
            {
                Image            newImage = Image.FromFile(str);
                ZArrayDescriptor z_array  = new ZArrayDescriptor(newImage.Width, newImage.Height);
                z_array = Util_array.getArrayFromImage(newImage);

                return(z_array);
            }
            catch (Exception ex) { System.Windows.Forms.MessageBox.Show("class File_Helper loadImage_from_File Ошибка при чтении изображения" + ex.Message); return(null); }
        }
예제 #25
0
        //----------------------------------------------------------------------------------------------
        //           Cuda  FFT из главного окна
        //----------------------------------------------------------------------------------------------
        public static void Fur_CUDA(ZArrayDescriptor zArrayPicture)                                            // Прямое преобразование Фурье (CUDA)
        {
            //MessageBox.Show("Прямое преобразование Фурье с произвольным числом точек");


            int nx = zArrayPicture.width;
            int ny = zArrayPicture.height;

            System.Diagnostics.Stopwatch sw = new Stopwatch();

            System.Diagnostics.Stopwatch sw1 = new Stopwatch();
            System.Diagnostics.Stopwatch sw3 = new Stopwatch();
            System.Diagnostics.Stopwatch sw4 = new Stopwatch();

            sw.Start();

            ComplexNumber[] Cud_array = ComplexMatrix.ToArrayByRows(zArrayPicture);            // Из двухмерного в одномерный ->  Массив комплексных (Struct)чисел [nx*ny]


            sw.Stop();
            TimeSpan ts = sw.Elapsed;

            MessageBox.Show("CUDA FFT Из двухмерного в одномерный  Время Минут: " + ts.Minutes + "   Время сек: " + ts.Seconds + "   Время миллисек: " + ts.Milliseconds);

            sw1.Start();

            ComplexNumber[] Cud_array1 = CUDA_FFT.CudaFFT(Cud_array, nx, ny);

            sw1.Stop();
            ts = sw1.Elapsed;
            MessageBox.Show("CUDA FFT  Время Минут: " + ts.Minutes + "   Время сек: " + ts.Seconds + "   Время миллисек: " + ts.Milliseconds);

            sw3.Start();
            int k = 0;

            for (int i = 0; i < nx; i++)
            {
                for (int j = 0; j < ny; j++)
                {
                    zArrayPicture.array[i, j] = Complex.FromPolarCoordinates(Cud_array1[k].Real, Cud_array1[k].Imaginary).Magnitude;
                    k++;
                }
            }
            //zArrayPicture.array[i, j] = C_array1[i, j].Magnitude;
            //zArrayPicture = ComplexMatrix.ToArrayByRows_column(Cud_array, nx, ny);

            sw3.Stop();
            ts = sw3.Elapsed;
            MessageBox.Show("CUDA FFT  zArrayPicture.array  Время Минут: " + ts.Minutes + "   Время сек: " + ts.Seconds + "   Время миллисек: " + ts.Milliseconds);
            // Cud_array1 = null;
        }
예제 #26
0
        public static ZArrayDescriptor Change_trapezium(ZArrayDescriptor zArrayDescriptor, Form1.Coords[] X)
        {
            Sort4(X);
            // int k = regComplex * 4;

            if (zArrayDescriptor == null)
            {
                MessageBox.Show(" Change_rectangle: zArrayDescriptor == null"); return(null);
            }
            int w1 = zArrayDescriptor.width;
            int h1 = zArrayDescriptor.height;

            int max_x = Max_x(X);
            int max_y = Max_y(X);


            ZArrayDescriptor zArray1 = new ZArrayDescriptor(max_x, max_y);


            for (int j = 0; j < max_y; j++)
            {
                for (int i = 0; i < max_x; i++)
                {
                    Form1.Coords R1 = YYY(X[0], X[1], max_y, j);
                    Form1.Coords R2 = YYY(X[2], X[3], max_y, j);
                    double       x  = X[0].x + i;
                    double       y  = Y(R1, R2, (int)x, max_y);
                    int          ix = (int)x;
                    int          iy = (int)y;
                    //MessageBox.Show(" x " + x + " y " + y);
                    if (iy < 0 || iy > h1)
                    {
                        continue;
                    }
                    if (ix < 0 || ix > w1)
                    {
                        continue;
                    }
                    zArray1.array[i, j] = zArrayDescriptor.array[ix, iy];
                    //zArray1.array[i, j] = Intens(zArrayDescriptor, x, y);
                }
            }


            return(zArray1);

            //MessageBox.Show(" max_x " + max_x + "max_y " + max_y);
            // if (iy < 0 || iy > h1)                       MessageBox.Show(" iy " + iy + " x= " + x + " y= " + y + " R1.y= " + R1.y + " R2.y= " + R2.y);
            // if (ix<0 || ix > w1)  MessageBox.Show(" ix " + ix + " x= " + x + "y= " + y + " i= " + i + "j= " + j);
            //
        }
예제 #27
0
        public ComplexMatrix(ZArrayDescriptor ampl)
        {
            this.rowCount    = ampl.width;
            this.columnCount = ampl.height;

            this.dataArray = new Complex[this.rowCount, this.columnCount];
            for (int row = 0; row < rowCount; row++)
            {
                for (int column = 0; column < columnCount; column++)
                {
                    this.dataArray[row, column] = Complex.FromPolarCoordinates(ampl.array[row, column], 0);
                }
            }
        }
        //--------------------------------------------------------------------------------------------------------------------
        // Конструктор array из  zArray
        // если изображение меньше чем  Nx,  Ny, то оно помещается в центре, а по краям 0
        // если изображение больше, то оно обрезается
        public ZArrayDescriptor(ZArrayDescriptor zArrayPicture, int Nx, int Ny)
        {
            if (zArrayPicture == null)
            {
                MessageBox.Show("zArrayPicture = NULL"); return;
            }


            width  = Nx;
            height = Ny;
            array  = new double[Nx, Ny];

            int NxP = zArrayPicture.width;
            int NyP = zArrayPicture.height;

            // MessageBox.Show("NX= " + Convert.ToString(Nx) + "Ny= " + Convert.ToString(Nx));
            // MessageBox.Show("NxP= " + Convert.ToString(NxP) + "NyP= " + Convert.ToString(NyP));

            int N2 = 0;

            if (Nx > NxP)
            {
                N2 = (Nx - NxP) / 2;
                for (int i = 0; i < N2; i++)
                {
                    for (int j = 0; j < Ny; j++)
                    {
                        array[i, j] = 0.0;
                    }
                }
                for (int i = N2; i < Nx - N2; i++)
                {
                    Stolb_a(i, N2, zArrayPicture, Ny, NyP);
                }
                for (int i = Nx - N2; i < Nx; i++)
                {
                    for (int j = 0; j < Ny; j++)
                    {
                        array[i, j] = 0.0;
                    }
                }
            }
            else
            {
                for (int i = 0; i < Nx; i++)
                {
                    Stolb_a(i, 0, zArrayPicture, Ny, NyP);
                }
            }
        }
예제 #29
0
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        // Конструктор для заполения реальной части и мнимой части
        // k=0   Re
        // k=1   Im
        // k=2   re im=0
        // value.Real, value.Imaginary
        public ZComplexDescriptor(ZArrayDescriptor descriptorToCopy, ZComplexDescriptor a, int k)
        {
            if (descriptorToCopy == null)
            {
                MessageBox.Show("ZArrayDescriptor == NULL"); return;
            }
            if (a == null)
            {
                MessageBox.Show("ZComplexDescriptor == NULL"); return;
            }

            width  = a.width;
            height = a.height;

            int w1 = descriptorToCopy.width;
            int h1 = descriptorToCopy.height;

            MessageBox.Show("k= " + k + "width= " + width + "height = " + height + "w1 = " + w1 + "h1 = " + h1);


            if (w1 > width || h1 > height)
            {
                MessageBox.Show("ZComplexDescriptor.cs ZArrayDescriptor > ZComplexDescriptor"); return;
            }

            int x1 = (width - w1) / 2;
            int y1 = (height - h1) / 2;

            array = new Complex[width, height];
            //MessageBox.Show("width =" + Convert.ToString(width) + "height =" + Convert.ToString(height));

            for (int i1 = 0; i1 < w1; i1++)
            {
                for (int j1 = 0; j1 < h1; j1++)
                {
                    int i = i1 + x1;
                    int j = j1 + y1;
                    //Double c = descriptorToCopy.array[i, j];
                    if (k == 0)
                    {
                        array[i, j] = new Complex(descriptorToCopy.array[i1, j1], a.array[i1, j1].Imaginary);
                    }
                    if (k != 0)
                    {
                        array[i, j] = new Complex(a.array[i1, j1].Real, descriptorToCopy.array[i1, j1]);
                    }
                }
            }
        }
예제 #30
0
        public static ZArrayDescriptor Filt_2_1_2(ZArrayDescriptor amp)   // int kx, int ky - сдвиг массива точек
        {
            int w1 = amp.width;
            int h1 = amp.height;
            int w2 = 2 * w1;
            int h2 = 2 * h1;

            ZArrayDescriptor tmp_array = new ZArrayDescriptor(w2, h2);
            ZArrayDescriptor res_array = new ZArrayDescriptor(w2, h2);

            double[] ar1;
            double[] ar2;

            for (int i = 0; i < w1; i++)
            {
                ar1 = new double[h1];
                ar2 = new double[h2];
                for (int j = 0; j < h1; j++)
                {
                    ar1[j] = amp.array[i, j];
                }
                ar2 = set_1_2(ar1);

                for (int j = 0; j < h2; j++)
                {
                    tmp_array.array[i, j] = ar2[j];
                }
            }

            for (int j = 0; j < h2; j++)
            {
                ar1 = new double[w1];
                ar2 = new double[w2];
                for (int i = 0; i < w1; i++)
                {
                    ar1[i] = tmp_array.array[i, j];
                }

                ar2 = set_1_2(ar1);

                for (int i = 0; i < w2; i++)
                {
                    res_array.array[i, j] = ar2[i];
                }
            }

            return(res_array);
        }