private void Button_Click(object sender, RoutedEventArgs e) { ZArrayDescriptor result = new ZArrayDescriptor(firstPhase.width, firstPhase.height); for (int x = 0; x < firstPhase.width; x++) { for (int y = 0; y < firstPhase.height; y++) { long firstPhaseValue = firstPhase.array[x][y]; long secondPhaseValue = secondPhase.array[x][y]; long currentMaskValue = table.array[secondPhaseValue][firstPhaseValue]; int lineNumber = (int)(currentMaskValue / 10); //Console.WriteLine("lineNumber = " + lineNumber); //if ((lineNumber <= 9) && (lineNumber > 0)) { result.array[x][y] = secondPhaseValue + 241*(lineNumber - 1); } } } if (phaseUnwrappedWithNewMethod != null) { phaseUnwrappedWithNewMethod(result); } }
private void processImages(object sender, DoWorkEventArgs doWorkEventArgs) { int width = someImages[0].width; int height = someImages[0].height; //описание - https://ru.wikipedia.org/wiki/%D0%9A%D0%B8%D1%82%D0%B0%D0%B9%D1%81%D0%BA%D0%B0%D1%8F_%D1%82%D0%B5%D0%BE%D1%80%D0%B5%D0%BC%D0%B0_%D0%BE%D0%B1_%D0%BE%D1%81%D1%82%D0%B0%D1%82%D0%BA%D0%B0%D1%85 RemainderTheoremImplementator theoremImplementator = new RemainderTheoremImplementator(sineNumbers); int firstImageMax = (int)Utils.maxFromArray(someImages[0]); int secondImageMax = (int)Utils.maxFromArray(someImages[1]); ZArrayDescriptor resultDescriptor = new ZArrayDescriptor(secondImageMax + 1, firstImageMax + 1); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { List<long> currentImageValues = new List<long>(); for(int i = 0; i < someImages.Count; i++) { ZArrayDescriptor currentDescriptor = someImages[i]; long currentPhase = currentDescriptor.array[x][y]; currentImageValues.Add(currentPhase); } long resultPoint = theoremImplementator.getSolution(currentImageValues); resultDescriptor.array[currentImageValues[1]][currentImageValues[0]] = resultPoint; } } doWorkEventArgs.Result = resultDescriptor; }
public ZArrayDescriptor(ZArrayDescriptor descriptorToCopy) { if (descriptorToCopy == null) { return; } array = new long[descriptorToCopy.width] []; for (int i = 0; i < descriptorToCopy.width; i++) { array[i] = new long[descriptorToCopy.height]; } width = descriptorToCopy.width; height = descriptorToCopy.height; for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { array[i][j] = descriptorToCopy.array[i][j]; } } }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //Public Methods ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public static ZArrayDescriptor process(ZArrayDescriptor inputArray) { ZArrayDescriptor result = new ZArrayDescriptor(inputArray.width, inputArray.height); for (int x = 1; x < inputArray.width - 1; x++) { for (int y = 1; y < inputArray.height - 1; y++) { long P9 = inputArray.array[x - 1][y - 1]; long P2 = inputArray.array[x][y - 1]; long P3 = inputArray.array[x + 1][y - 1]; long P4 = inputArray.array[x + 1][y]; long P5 = inputArray.array[x + 1][y + 1]; long P6 = inputArray.array[x][y + 1]; long P7 = inputArray.array[x - 1][y + 1]; long P8 = inputArray.array[x - 1][y]; long P1 = inputArray.array[x][y]; List<long> parameter = new List<long>(8); parameter.Add(P2); parameter.Add(P3); parameter.Add(P4); parameter.Add(P5); parameter.Add(P6); parameter.Add(P7); parameter.Add(P8); parameter.Add(P9); long A = ZhangSuenAlgorithmImplementator.A(parameter); long B = ZhangSuenAlgorithmImplementator.B(parameter); if (((B >= 2) && (B <= 6)) && (A == 1) && (P2*P4*P6 == 0) && (P4 * P6 * P8 == 0)) { P1 = 0; } else { P1 = 2; } if (((B >= 2) && (B <= 6)) && (A == 1) && (P2 * P4 * P8 == 0) && (P2 * P6 * P8 == 0)) { P1 = 0; } else { P1 = 2; } } } return result; }
public Faza2Pi(ZArrayDescriptor[] newSource) { InitializeComponent(); sineNumbers1.Text = Convert.ToString(sineNumber1); sineNumbers2.Text = Convert.ToString(sineNumber2); source = newSource; }
public NewMethodUnwrapForm(ZArrayDescriptor firstPhase, ZArrayDescriptor secondPhase, ZArrayDescriptor table) { InitializeComponent(); this.table = table; this.secondPhase = secondPhase; this.firstPhase = firstPhase; }
public Tabl_Sub(ZArrayDescriptor[] newSource) { InitializeComponent(); textBox1_sub.Text = Convert.ToString(m1); textBox2_sub.Text = Convert.ToString(m2); textBox3_sub.Text = Convert.ToString(m3); source = newSource; }
//Life Cycle ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public ZhangSuenAlgorithmImplementator(ZArrayDescriptor input) { this.input = input; WorkerReportsProgress = true; WorkerSupportsCancellation = true; DoWork += processImage; }
static Int64[,] Z; // Глобальный массив результирующих фаз (Размер задается при расшифровке) #endregion Fields #region Methods ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Заполнение массива bmp_r ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public static int bmp_2pi(ZArrayDescriptor[] img, int NOD, int[,] bmp_r, int Diag, int pr_obr, int sdvg_x) { int r; int g; int w = img[0].width; int h = img[0].height; int[] ims1 = new int[h]; int[] ims2 = new int[h]; int[] ims3 = new int[h]; //double fn1 = (double)(n1 - 1) / 255; //double fn2 = (double)(n2 - 1) / 255; int all = w; int done = 0; PopupProgressBar.show(); int count = 0; //int max = 0; // ------------------------------------------------------------------------- По фигуре из 3 квадрата for (int i = 0; i < w; i++) { for (int j = 0; j <h; j++) { if (img[2].array[i][j] == 0) { ims3[j] = 0; } else { ims3[j] = 1; ims1[j] = (int)(img[1].array[i][j] / NOD); ims2[j] = (int)(img[0].array[i][j] / NOD); } } for (int j = 0; j < h; j++) { if (ims3[j] != 0) { r = ims1[j]; r = r + sdvg_x; if (r > n1) r -= n1; g = ims2[j]; bmp_r[g, r]++; count++; } } done++; PopupProgressBar.setProgress(done, all); } // MessageBox.Show(" Max = " + max.ToString()); PopupProgressBar.close(); return (count); }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public UnwrapForm(ZArrayDescriptor[] images) { InitializeComponent(); sineNumbers1.Text = Convert.ToString(firstSineNumber); sineNumbers2.Text = Convert.ToString(secondSineNumber); periodsNumber.Text = Convert.ToString(poriodsNumber); //cutLevelTextBox.Text = Convert.ToString(0); textBox1.Text = Convert.ToString(0); this.images = images; }
private void loadSecondArray(object sender, RoutedEventArgs e) { if (firstDescriptor == null) { return; } secondDescriptor = FilesHelper.loadZArray(); Bitmap firstBitmap = FilesHelper.bitmapSourceToBitmap(Utils.getImageFromArray(firstDescriptor)); Bitmap secondBitmap = FilesHelper.bitmapSourceToBitmap(Utils.getImageFromArray(secondDescriptor, Utils.RGBColor.Red)); Bitmap result = Utils.mergeBitmaps(firstBitmap, secondBitmap); imageToComparation.Source = FilesHelper.bitmapToBitmapImage(result); }
public TableFaza(ZArrayDescriptor[] newSource) { InitializeComponent(); textBox1_fz.Text = Convert.ToString(fz[0]); textBox2_fz.Text = Convert.ToString(fz[1]); textBox3_fz.Text = Convert.ToString(fz[2]); textBox4_fz.Text = Convert.ToString(fz[3]); textBox5_fz.Text = Convert.ToString(fz[4]); sineNumbers1.Text = Convert.ToString(sineNumber1); sineNumbers2.Text = Convert.ToString(sineNumber2); fz1 = new double[5]; fz1[0] = fz[0]; fz1[1] = fz[1]; fz1[2] = fz[2]; fz1[3] = fz[3]; fz1[4] = fz[4]; source = newSource; }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public FiltrationForm(FiltrationType filtrationType, ZArrayDescriptor image) { InitializeComponent(); this.filtrationType = filtrationType; this.image = image; if (filtrationType == FiltrationType.Smoothing) { filtrationTypeLabel.Text = "Сглаживание"; } else if (filtrationType == FiltrationType.Median) { filtrationTypeLabel.Text = "Медианный"; } }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public static ZArrayDescriptor cutZArray(ZArrayDescriptor someDescriptor, int min, int max) { for (int i = 0; i < someDescriptor.width; i++) { for (int j = 0; j < someDescriptor.height; j++) { if (someDescriptor.array[i][j] > max) { someDescriptor.array[i][j] = max; } if (someDescriptor.array[i][j] < min) { someDescriptor.array[i][j] = min; } } } return someDescriptor; }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// private static ZArrayDescriptor createSineImage(int imageNumber, double phase, int totalImages, double amplitudeDistortionPercent, double phaseDistortionPercent, double gammaCorrection) { double phaseShiftInDegrees = (360.0 / totalImages) * imageNumber; double phaseShiftInRadians = Utils.degreeToRadian(phaseShiftInDegrees); ZArrayDescriptor newSineImage = new ZArrayDescriptor(SINE_IMAGE_WIDTH, SINE_IMAGE_HEIGHT); for (int i = 0; i < newSineImage.width; i++) { double x = i / (phase / 10.0); const double multiplier = 100.0; const double AMPLITUDE_INITIAL_VALUE = 1.0; int amplitudeRandomPercent = random.Next((int)(-(amplitudeDistortionPercent * multiplier) / 2.0f), (int)((amplitudeDistortionPercent * multiplier) / 2.0f)); double amplitudeRandomValue = amplitudeRandomPercent * AMPLITUDE_INITIAL_VALUE / multiplier / 100.0f; const double PHASE_INITIAL_VALUE = 360.0; int phaseRandomPercent = random.Next((int)(-(phaseDistortionPercent * multiplier) / 2.0), (int)((phaseDistortionPercent * multiplier) / 2.0)); double phaseRandomValueInDegrees = phaseRandomPercent * PHASE_INITIAL_VALUE / multiplier / 100.0; double phaseRandomValueInRadians = Utils.degreeToRadian(phaseRandomValueInDegrees); double resultValue = Math.Sin(x + phaseShiftInRadians + phaseRandomValueInRadians); resultValue = (resultValue + 1.0) / 2.0 + amplitudeRandomValue + ((amplitudeDistortionPercent) / 2.0 / 100.0) * AMPLITUDE_INITIAL_VALUE; resultValue = Math.Pow(resultValue, gammaCorrection); resultValue *= 255.0; for (int j = 0; j < newSineImage.height; j++) { newSineImage.array[i][j] = (long)resultValue; } } return newSineImage; }
// 1, ... ,5 -> 11 6, ..., 10 -> 12 // -------------------------------------------------------------------------------------------- // 5-х точечный алгоритм // -------------------------------------------------------------------------------------------- private void button1_Click(object sender, EventArgs e) { sineNumber1 = Convert.ToInt32(sineNumbers1.Text); sineNumber2 = Convert.ToInt32(sineNumbers2.Text); fz[0] = Convert.ToInt32(textBox1_fz.Text); fz[1] = Convert.ToInt32(textBox2_fz.Text); fz[2] = Convert.ToInt32(textBox3_fz.Text); fz[3] = Convert.ToInt32(textBox4_fz.Text); fz[4] = Convert.ToInt32(textBox5_fz.Text); ZArrayDescriptor[] firstSource = new ZArrayDescriptor[5]; for (int i = 0; i < 5; i++) { firstSource[i] = source[i]; } Res d = new Res(); d.result1 = FazaClass.ATAN_1234(firstSource, fz, sineNumber2); ZArrayDescriptor[] secondSource = new ZArrayDescriptor[5]; for (int i = 5; i < 10; i++) { secondSource[i - 5] = source[i]; } d.result2 = FazaClass.ATAN_1234(secondSource, fz, sineNumber1); Close(); atan_Unwrapped(d); }
//---------------------------------------------------------------------------------------------- // Восстановление полной фазы по известной востановленной целочисленным методом //---------------------------------------------------------------------------------------------- public static ZArrayDescriptor Pi2_V(ZArrayDescriptor f1, ZArrayDescriptor fp, int sineNumber, int sdvg) { int w1 = f1.width; int h1 = f1.height; long[][] result = new long[w1][]; for (int i = 0; i < w1; i++) { result[i] = new long[h1]; } int all = w1; int done = 0; PopupProgressBar.show(); for (int i = 0; i < w1-4; i++) { for (int j = 0; j < h1; j++) { long a = f1.array[i][j]; a += sdvg; if (a > sineNumber) a -= sineNumber; long b = fp.array[i][j]; while (Math.Abs(a - b) >= sineNumber) { if (a < b) a += sineNumber; if (a > b) a -= sineNumber; } if (Math.Abs(a - b) >= 80) { if (a < b) a += sineNumber; if (a > b) a -= sineNumber; } result[i][j] = a; } done++; PopupProgressBar.setProgress(done, all); } PopupProgressBar.close(); ZArrayDescriptor wrappedPhase = new ZArrayDescriptor(); wrappedPhase.array = result; wrappedPhase.width = w1; wrappedPhase.height = h1; return wrappedPhase; }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public static void drawGraph(ZArrayDescriptor someImage, int pointX, int pointY, double ratio) { int w1 = someImage.width; int h1 = someImage.height; int[] bufr = new int[w1]; int[] bufyr = new int[h1]; int[] bufg = new int[w1]; int[] bufyg = new int[h1]; int[] bufb = new int[w1]; int[] bufyb = new int[h1]; if (pointX >= w1 || pointY >= h1) { return; } for (int i = 0; i < w1; i++) { bufr[i] = (int) (someImage.array[i][pointY] * ratio); bufg[i] = (int)(someImage.array[i][pointY] * ratio); bufb[i] = (int)(someImage.array[i][pointY] * ratio); } for (int i = 0; i < h1; i++) { bufyr[i] = (int)(someImage.array[pointX][i] * ratio); bufyg[i] = (int)(someImage.array[pointX][i] * ratio); bufyb[i] = (int)(someImage.array[pointX][i] * ratio); } Form fo = new GraphForm(pointX, pointY, w1, h1, bufr, bufyr, bufg, bufyg, bufb, bufyb); fo.Show(); fo.StartPosition = FormStartPosition.Manual; fo.Show(); }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public static void drawGraph(ZArrayDescriptor someImage, int pointX, int pointY) { drawGraph(someImage, pointX, pointY, 1); }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// private void loadImageAsync(object sender, DoWorkEventArgs doWorkEventArgs) { BitmapImage newSource = (BitmapImage)doWorkEventArgs.Argument; if (newSource == null) { return; } zArrayDescriptor = Utils.getArrayFromImage(newSource); Bitmap resizedImage; if ((imageContainer.ActualWidth != 0) && (imageContainer.ActualHeight != 0)) { Size imageContainerSize = new Size(imageContainer.ActualWidth, imageContainer.ActualHeight); resizedImage = ResizeImage(FilesHelper.bitmapSourceToBitmap(Utils.getImageFromArray(zArrayDescriptor)), imageContainerSize); } else { resizedImage = FilesHelper.bitmapSourceToBitmap(Utils.getImageFromArray(zArrayDescriptor)); } if (zArrayDescriptor != null) { imageWidth = zArrayDescriptor.width; imageHeight = zArrayDescriptor.height; if (Environment.Is64BitProcess == false) { FilesHelper.saveDescriptorWithName(zArrayDescriptor, getFilePath()); zArrayDescriptor = null; } } doWorkEventArgs.Result = FilesHelper.bitmapToBitmapImage(resizedImage); }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public void setzArrayDescriptorWithoutImageGenerating(ZArrayDescriptor newDescriptor) { zArrayDescriptor = newDescriptor; if (zArrayDescriptor != null) { imageWidth = zArrayDescriptor.width; imageHeight = zArrayDescriptor.height; } else { imageWidth = 0; imageHeight = 0; } }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public void setzArrayDescriptor(ZArrayDescriptor newDescriptor) { zArrayDescriptor = newDescriptor; if (zArrayDescriptor != null) { Bitmap resizedImage; if ((imageContainer.ActualWidth != 0) && (imageContainer.ActualHeight != 0)) { Size imageContainerSize = new Size(imageContainer.ActualWidth, imageContainer.ActualHeight); resizedImage = ResizeImage(FilesHelper.bitmapSourceToBitmap(Utils.getImageFromArray(zArrayDescriptor)), imageContainerSize); } else { resizedImage = FilesHelper.bitmapSourceToBitmap(Utils.getImageFromArray(zArrayDescriptor)); } image.Source = FilesHelper.bitmapToBitmapImage(resizedImage); imageWidth = zArrayDescriptor.width; imageHeight = zArrayDescriptor.height; if (Environment.Is64BitProcess == false) { FilesHelper.saveDescriptorWithName(zArrayDescriptor, getFilePath()); zArrayDescriptor = null; } } else { image.Source = null; } }
// Расшифровка //----------------------------------------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------------------------------------- public static ZArrayDescriptor pi2_rshfr(ZArrayDescriptor[] img, int sN1, int sN2, int Diag, int pr_obr, int sdvg_x) { int w = img[0].width; int h = img[0].height; int NOD=China(sN1, sN2); // Проверка на взаимную простоту // Вычисление формулы sN1, sN2 -> в глобальные n1, n2 // int[,] bmp_r = new int[sN2 + 3, sN1 + 3]; // Массив точек в таблице 2pi // bmp_2pi(img, bmp_r, Diag, pr_obr, sdvg_x); // Заполнение массива bmp_r Z = new Int64[w, h]; GLBL_FAZE(n1, n2, Diag); // Заполнение массива glbl_faze[] (Все -1 кроме номеров полос) // glbl_faze1[] расширяется значениям номеров полос // РАСШИФРОВКА (Заполнение Z[,]) rash_2pi(img[1], img[0], img[2], NOD, sdvg_x, n1, n2, Diag, Z); ZArrayDescriptor result = new ZArrayDescriptor(); result.array = new long[w][]; for (int i = 0; i < w; i++) { result.array[i] = new long[h]; } result.width = w; result.height = h; for (int i = 0; i < w; i++) // Отображение точек на pictureBox01 { for (int j = 0; j < h; j++) { result.array[i][j] = Z[i, j]; } } //Z_bmp(result, Z); // Z -> bmp с масштабированием (bmp3 - маска) return result; }
// --------------------------------------------------------------------------------------------------------------------------- Рисование таблицы (параметры) (b2, b1) ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // Построение таблицы // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public static void Graph_China2(ZArrayDescriptor[] img, int NOD, int Diag, bool rb, int pr_obr, int sdvg_x, int X, int Y) { int max_x = (n1 + n2) * scale, max_y = 800; int w1 = n2, hh = n1; f_sin = new Form(); f_sin.Size = new Size(max_x + 8, max_y + 8); f_sin.StartPosition = FormStartPosition.Manual; pc1 = new PictureBox(); pc1.BackColor = Color.White; pc1.Location = new Point(0, 8); pc1.Size = new Size(max_x, max_y); pc1.SizeMode = PictureBoxSizeMode.StretchImage; pc1.BorderStyle = BorderStyle.Fixed3D; Bitmap btmBack = new Bitmap(max_x + 8, max_y + 8); //изображение Graphics grBack = Graphics.FromImage(btmBack); pc1.BackgroundImage = btmBack; f_sin.Controls.Add(pc1); Pen p1 = new Pen(Color.Black, 1); Pen p2 = new Pen(Color.Red, 1); Pen p3 = new Pen(Color.Blue, 1); Pen p4 = new Pen(Color.Gold, 1); Font font = new Font("Arial", 16, FontStyle.Regular, GraphicsUnit.Pixel); grBack.DrawLine(p1, x0, y0, x0, hh * scale + y0); grBack.DrawLine(p1, x0, hh * scale + y0, 2 * w1 * scale + x0, hh * scale + y0); grBack.DrawLine(p1, w1 * scale + x0, hh * scale + y0, w1 * scale + x0, y0); grBack.DrawLine(p1, w1 * scale + x0, y0, x0, y0); StringFormat drawFormat = new StringFormat(StringFormatFlags.NoClip); string s = n2.ToString(); grBack.DrawString("b2 " + s, font, new SolidBrush(Color.Black), w1 * scale + x0 + 8, y0 - 8, drawFormat); s = n1.ToString(); grBack.DrawString("b1 " + s, font, new SolidBrush(Color.Black), x0, hh * scale + 20 + 10 * scale, drawFormat); // ---------------------------------------------------------------------------------------------------------------- GLBL_FAZE(n1, n2, Diag); // Заполнение glbl_faze[] и glbl_faze1[] - допустимые границы диапазона // -----------------------------------------------------------------------------------------------Отрисовка диагоналей Int32 A = Diag * Math.Max(n1, n2); Int32 pf; for (int b2 = 0; b2 < n2; b2++) // Диагонали { pf = M2 * N2 * b2 % (n1 * n2); if (pf < A) { grBack.DrawLine(p2, x0 + b2 * scale, y0, x0 + b2 * scale + n1 * scale, hh * scale + y0); pf = pf / n1; // glbl_faze[n1 + b2] = pf; s = pf.ToString(); grBack.DrawString(s, font, new SolidBrush(Color.Black), x0 + b2 * scale, y0 - 4 * scale, drawFormat); } } for (int b1 = 0; b1 < n1; b1++) { pf = M1 * N1 * b1 % (n1 * n2); if (pf < A) { grBack.DrawLine(p3, x0, y0 + b1 * scale, x0 + n1 * scale - b1 * scale, hh * scale + y0); pf = pf / n1; // glbl_faze[n1 - b1] = pf; s = pf.ToString(); grBack.DrawString(s, font, new SolidBrush(Color.Black), x0 - 10 * scale, y0 + b1 * scale, drawFormat); } } // Нумерация внизу таблицы for (int i = 0; i < n1 + n2; i++) { int bb = glbl_faze[i]; if (bb >= 0) { s = bb.ToString(); grBack.DrawString(s, font, new SolidBrush(Color.Black), x0 + i * scale, y0 + n1 * scale + 8 * scale, drawFormat); } } // int mxx = 0, mxx_x = 0, mnx_x = 0, cntr = 0; int mnx = 0; // Отрисовка границ допустимого диапазона(Gold) mnx = glbl_faze1[0]; for (int i = 0; i < n1 + n2; i++) { int bb = glbl_faze1[i]; if (bb != mnx) { mnx = bb; grBack.DrawLine(p4, x0 + i * scale, y0 + hh * scale, x0, y0 + hh * scale - i * scale); } } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Заполнение массива bmp_r ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// int[,] bmp_r = new int[n2 + 3, n1 + 3]; int count = bmp_2pi(img, NOD, bmp_r, Diag, pr_obr, sdvg_x); ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Рисование точек в таблице по диагоналям ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// int b = 0, ib2 = 0, ib1 = 0; for (ib2 = 0; ib2 < n2 - 1; ib2++) { for (ib1 = 0; ib1 < n1 - 1; ib1++) { b = bmp_r[ib2, ib1]; if (b > pr_obr) { grBack.DrawRectangle(new Pen(Color.FromArgb(146, 24, 47)), x0 + ib2 * scale, y0 + ib1 * scale, 1, 1); } } } // -------------------------------------------------------------------------------------Рисование одной точки X, Y int is1; int is2; is1 = (int)img[1].array[X][Y]; is1 += sdvg_x; if (is1 > n1) is1 -= n1; is2 = (int)img[0].array[X][Y]; grBack.DrawRectangle(new Pen(Color.FromArgb(0, 255, 0)), x0 + is2 * scale, y0 + is1 * scale, 25, 25); //MessageBox.Show(" x = " + is2 + " Y = " + is1); //-------------------------------------------------------------------------------------------------------------------- pc1.Refresh(); f_sin.Show(); bmp_gstgr(bmp_r); // гистограмма }
// -------------------------------------------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------------------------------------------- public static void pi2_frml2(ZArrayDescriptor[] img, int sN1, int sN2, int Diag, bool rb, int pr_obr, int sdvg_x, int X, int Y) { int NOD = China(sN1, sN2); MessageBox.Show(" M1 = " + M1 + " N1 = " + N1 + " M2 = " + M2 + " N2 = " + N2 + " M1*N1 = " + M1*N1 + " M2*N2 = " + M2*N2); Graph_China2(img, NOD, Diag, rb, pr_obr, sdvg_x, X, Y); // Вычисление формулы => n1, n2, NOD // Построение таблицы }
public static ZArrayDescriptor ATAN_Carre(ZArrayDescriptor[] img, int sineNumber) { int w1 = img[0].width; int h1 = img[0].height; long[][] result = new long[w1][]; // массив для значений фаз for (int i = 0; i < w1; i++) { result[i] = new long[h1]; } // Число фазовых сдвигов double pi = Math.PI; double pi2 = sineNumber / (Math.PI * 2); double tg; double max = -99999; double min = 99999; // x>0 y>0 atan(y/x) // x<0 y>=0 atan(y/x) + pi // atan2(y,x) = x<0 y<0 atan(y/x) - pi // x=0 y>0 pi/2 // x=0 y<0 -pi/2 // x=0 y=0 undefined int all = w1; int done = 0; PopupProgressBar.show(); for (int i = 0; i < w1; i++) { for (int j = 0; j < h1; j++) { long i1 = img[0].array[i][j]; // ------ Формула расшифровки long i2 = img[1].array[i][j]; long i3 = img[2].array[i][j]; long i4 = img[3].array[i][j]; double ay = (i1 - i4) + (i2 - i3); double ax = (i2 + i3) - (i1 + i4); double c = 3 * (i2 - i3) - (i1 - i4); double r = 0; if ( (ax == 0) && (ay > 0) ) { r = (-pi/2 + pi + pi/4); } if ((ax == 0) && (ay < 0)) { r = (+pi / 2 + pi + pi / 4); } if ((ax >= 0) && (ay == 0)) { r = 0 + pi + pi / 4; } if ((ax < 0) && (ay == 0)) { r = (-pi + pi + pi / 4); } double x = Math.Abs(ax); double y = Math.Abs(ay * c); double b = Math.Sqrt(y) /x; tg = Math.Atan(b); // if (tg == Double.NaN) MessageBox.Show(" Double.NaN "); // if (tg == Double.NegativeInfinity) MessageBox.Show(" NegativeInfinity "); // if (tg == Double.PositiveInfinity) MessageBox.Show(" PositiveInfinity "); if (ax > 0) { if (ay > 0) { r = (-tg + pi + pi/4); } if (ay < 0) { r = ( tg + pi + pi/4); } } if (ax < 0) { if (ay > 0) { r = (tg + pi / 4); } if (ay < 0) { r = (-tg + pi / 4); if (r < 0) r += 2*pi; } } //long r1 = (long)((r - pi34) * pi2); //if (r1 < 0) r1 += (sineNumber+1); if (r > max) max = r; if (r < min) min = r; long r1 = (long)((r ) * pi2); //if (r1 < 0) r1 += (sineNumber+1); result[i][j] = r1; } done++; PopupProgressBar.setProgress(done, all); } PopupProgressBar.close(); ZArrayDescriptor wrappedPhase = new ZArrayDescriptor(); wrappedPhase.array = result; wrappedPhase.width = w1; wrappedPhase.height = h1; return wrappedPhase; }
// ----------------------------------------------------------------------------------------------------------------------------------- // ----------------------------------- Вычитание наклона -> в вещественный массив Z ------------------------------- // ----------------------------------------------------------------------------------------------------------------------------------- public static ZArrayDescriptor Z_sub(int x1, int y1, int x2, int y2, ZArrayDescriptor descriptor, double cosinusDegrees) { double cos = Math.Cos(cosinusDegrees * Math.PI / 180); y2 = y1; long z1 = descriptor.array[x1][y1]; long z2 = descriptor.array[x2][y2]; //MessageBox.Show(" X1 = " + x1 + " X2 = " + x2 + " y1 = " + y1 + " y2 = " + y2); double tt = (z2 - z1)*cos / (double)(x2 - x1); long[] s = new long[descriptor.width]; for (int i = 0; i < descriptor.width; i++) { s[i] = (Int64)(tt * (i - x1)) + (z1); } ZArrayDescriptor result = new ZArrayDescriptor(); result.width = descriptor.width; result.height = descriptor.height; result.array = new long[result.width][]; for (int i = 0; i < result.width; i++) { result.array[i] = new long[result.height]; } for (int i = 0; i < descriptor.width; i++) { for (int j = 0; j < descriptor.height; j++) { result.array[i][j] = descriptor.array[i][j] - s[i]; } } return result; }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// private void processImage(object sender, DoWorkEventArgs doWorkEventArgs) { if ((CancellationPending == true)) { doWorkEventArgs.Cancel = true; return; } double[] cArray = new double[phaseShifts.Count()]; for (int i = 0; i < cArray.Count(); i++) { cArray[i] = Math.Cos(phaseShifts[i] * (Math.PI /180.0)); } double[] sArray = new double[phaseShifts.Count()]; for (int i = 0; i < sArray.Count(); i++) { sArray[i] = Math.Sin(phaseShifts[i] * (Math.PI / 180.0)); } int[][] transformationMatrix = new int[phaseShifts.Length][]; for (int i = 0; i < phaseShifts.Length; i++) { transformationMatrix[i] = new int[phaseShifts.Length]; } int initialOnePosition = 1; int initialMinusOnePosition = phaseShifts.Length - 1; for (int i = 0; i < phaseShifts.Length; i++) { transformationMatrix[initialOnePosition][i] = 1; transformationMatrix[initialMinusOnePosition][i] = -1; initialOnePosition++; if (initialOnePosition > phaseShifts.Length - 1) { initialOnePosition -= phaseShifts.Length; } initialMinusOnePosition++; if (initialMinusOnePosition > phaseShifts.Length - 1) { initialMinusOnePosition -= phaseShifts.Length; } } double[] sinComponents = new double[phaseShifts.Length]; double[] cosComponents = new double[phaseShifts.Length]; for (int i = 0; i < phaseShifts.Length; i++) { double sSum = 0; double cSum = 0; for (int j = 0; j < phaseShifts.Length; j++) { double matrixComponent = transformationMatrix[i][j]; double sArrayComponent = sArray[j]; double cArrayComponent = cArray[j]; sSum += matrixComponent * sArrayComponent; cSum += matrixComponent * cArrayComponent; } sinComponents[i] = sSum; cosComponents[i] = cSum; } double[][] sinResults = new double[imagesWidth][]; for (int i = 0; i < imagesWidth; i++) { sinResults[i] = new double[imagesHeight]; } double[][] cosResults = new double[imagesWidth][]; for (int i = 0; i < imagesWidth; i++) { cosResults[i] = new double[imagesHeight]; } for (int i = 0; i < imagesPath.Count; i++) { ZArrayDescriptor currentDerscriptor = new ZArrayDescriptor(imagesPath[i]); for (int x = 0; x < currentDerscriptor.width; x++) { for (int y = 0; y < currentDerscriptor.height; y++) { long currentImageIntencity = currentDerscriptor.array[x][y]; sinResults[x][y] += currentImageIntencity*sinComponents[i]; cosResults[x][y] += currentImageIntencity * cosComponents[i]; } } } for (int x = 0; x < imagesWidth; x++) { for (int y = 0; y < imagesHeight; y++) { sinResults[x][y] = sinResults[x][y] /** 180.0 / Math.PI*/; cosResults[x][y] = cosResults[x][y] /** 180.0 / Math.PI*/; } } double maxSin = Double.MinValue; double maxCos = Double.MinValue; double minSin = Double.MaxValue; double minCos = Double.MaxValue; for (int x = 0; x < imagesWidth; x++) { for (int y = 0; y < imagesHeight; y++) { maxSin = Math.Max(maxSin, sinResults[x][y]); maxCos = Math.Max(maxCos, cosResults[x][y]); minSin = Math.Min(minSin, sinResults[x][y]); minCos = Math.Min(minCos, cosResults[x][y]); } } int resultWidth = (int) (maxCos - minCos) + 1; int resultHeight = (int)(maxSin - minSin) + 1; long[][] result = new long[resultWidth][]; for (int i = 0; i < resultWidth; i++) { result[i] = new long[resultHeight]; } for (int x = 0; x < imagesWidth; x++) { for (int y = 0; y < imagesHeight; y++) { int sin = (int) sinResults[x][y]; int cos = (int) cosResults[x][y]; int currentSin = (int) ((int) sinResults[x][y] - minSin); int currentCos = (int) ((int) cosResults[x][y] - minCos); result[currentCos][currentSin]+= 1; } } ZArrayDescriptor resultDescriptor = new ZArrayDescriptor(); resultDescriptor.array = result; resultDescriptor.width = resultWidth; resultDescriptor.height = resultHeight; doWorkEventArgs.Result = resultDescriptor; }
// ----------------------------------------------------------------------------------------------------------------------------------- // ----------------------------------- Сама расшифровка -> в вещественный массив Z ------------------------------- // ----------------------------------------------------------------------------------------------------------------------------------- // private static void rash_2pi(ZArrayDescriptor bmp1, ZArrayDescriptor bmp2, ZArrayDescriptor bmp3, int[,] bmp_r, int pr_obr, int sdvg_x, int n1, int n2, int Diag, Int64[,] Z) private static void rash_2pi(ZArrayDescriptor bmp1, ZArrayDescriptor bmp2, ZArrayDescriptor bmp3, int NOD, int sdvg_x, int n1, int n2, int Diag, Int64[,] Z) { //MessageBox.Show(" sdvg = " + sdvg_x + " n1 = " + n1 + " n2 = " + n2); int w = bmp1.width; int h = bmp1.height; int all = w; int done = 0; PopupProgressBar.show(); for (int i = 0; i < w; i++) { for (int j = 0; j < h; j++) { int i1 = (int)(bmp1.array[i][j]); int i2 = (int)(bmp2.array[i][j]); Z[i, j] = GLBL_R(n1, n2, i1, i2, sdvg_x, NOD); } //MessageBox.Show(" i = " + i); done++; PopupProgressBar.setProgress(done, all); } PopupProgressBar.close(); }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public ZArrayDescriptor getzArrayDescriptor() { if (zArrayDescriptor == null) { zArrayDescriptor = FilesHelper.readDescriptorWithName(getFilePath()); } return zArrayDescriptor; }