private void n5_KeyDown(object sender, KeyEventArgs e) { var temp = (sender as TextBox); if (e.Key == Key.Enter) { if (temp.Text == string.Empty) { Fourier.Cleare(5); } else { int.TryParse(temp.Text, out int v); Fourier.Draw(ffff.FourierSeries(v), -10, 10, 0.01, 5); } } }
private void NewFunction_Click(object sender, RoutedEventArgs e) { var gg = new Grid() { Background = Brushes.SkyBlue, Width = 300, Height = 200, VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center, }; gg.Children.Add(new TextBlock { Text = "please wait", VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center }); Grid.SetRow(gg, 1); MainGrid.Children.Add(gg); anbn.Children.Clear(); var f = new NewFunction(); var p = new PopUp() { Content = f, Owner = this }; p.Width = 730; p.Height = 340; p.ShowDialog(); if (UI.NewFunction.Piese == false) { if (UI.NewFunction.Type == FunctionType.normal) { var sf = new SimpleFourier(UI.NewFunction.Func, UI.NewFunction.Period, 40); ffff = sf; Fourier.Draw(sf.FourierSeries(30), -10, 10, 0.01); anbn.Children.Add(new TextBlock { Text = "a0: " + sf.a0.ToString(), VerticalAlignment = VerticalAlignment.Stretch, TextAlignment = TextAlignment.Center }); for (int i = 0; i < sf.an.Length; i++) { anbn.Children.Add(new TextBlock { Text = "a" + (i + 1).ToString() + ": " + sf.an[i].ToString() + " b" + (i + 1).ToString() + ": " + sf.bn[i].ToString(), VerticalAlignment = VerticalAlignment.Stretch, TextAlignment = TextAlignment.Center }); } Dynamics.GetValues(sf.Function, -sf.Period, sf.Period, 0.001, out KeyValuePair <double, double>[] values); Function.Draw(values); } else { var sf = new OddEvenFourier(UI.NewFunction.Func, UI.NewFunction.Period, 40, UI.NewFunction.Type); ffff = sf; Fourier.Draw(sf.FourierSeries(30), -10, 10, 0.01); anbn.Children.Add(new TextBlock { Text = "a0: " + sf.a0.ToString(), VerticalAlignment = VerticalAlignment.Stretch, TextAlignment = TextAlignment.Center }); for (int i = 0; i < sf.an.Length; i++) { anbn.Children.Add(new TextBlock { Text = "a" + (i + 1).ToString() + ": " + sf.an[i].ToString() + " b" + (i + 1).ToString() + ": " + sf.bn[i].ToString(), VerticalAlignment = VerticalAlignment.Stretch, TextAlignment = TextAlignment.Left }); } Dynamics.GetValues(sf.Function, 0, sf.Period, 0.001, out KeyValuePair <double, double>[] values); var othvals = new List <KeyValuePair <double, double> >(); if (UI.NewFunction.Type == FunctionType.even) { foreach (var item in values) { //othvals.Add(new KeyValuePair<double, double>(item.Key, item.Value)); othvals.Add(new KeyValuePair <double, double>(-item.Key, item.Value)); } } else if (UI.NewFunction.Type == FunctionType.odd) { foreach (var item in values) { //othvals.Add(new KeyValuePair<double, double>(item.Key, item.Value)); othvals.Add(new KeyValuePair <double, double>(-item.Key, -item.Value)); } } foreach (var item in values) { othvals.Add(new KeyValuePair <double, double>(item.Key, item.Value)); } Function.Draw(othvals.ToArray()); } } else { var sf = new PiecewiseFourier(40); for (int i = 0; i < UI.NewFunction.Pieses.Count; i++) { sf.AddCriterion(UI.NewFunction.Pieses[i], UI.NewFunction.Froms[i], UI.NewFunction.Tos[i]); } sf.Criterioned(); ffff = sf; var vs = new List <KeyValuePair <double, double> >(); foreach (var item in sf.Values) { vs.Add(new KeyValuePair <double, double>(item.Key, item.Value)); } Function.Draw(vs.ToArray()); Fourier.Draw(sf.FourierSeries(30), -10, 10, 0.01); anbn.Children.Add(new TextBlock { Text = "a0: " + sf.a0.ToString(), VerticalAlignment = VerticalAlignment.Stretch, TextAlignment = TextAlignment.Left }); for (int i = 0; i < sf.an.Length; i++) { anbn.Children.Add(new TextBlock { Text = "a" + (i + 1).ToString() + ": " + sf.an[i].ToString() + " b" + (i + 1).ToString() + ": " + sf.bn[i].ToString(), VerticalAlignment = VerticalAlignment.Stretch, TextAlignment = TextAlignment.Left }); } } MainGrid.Children.Remove(gg); }
private void goBtn_Click(object sender, EventArgs e) { x = 1024; y = 1024; openSource.Text = openKernel.Text = "Open"; data = Reader.readFile(image, x, y, false); //Copy data line for Fourier //data = Reader.Rotate(data); tempFourier1 = PrepareVerticalFouirier(data, line); //Print Fourier Fourier.Draw(fourierChart, tempFourier1, SeriesChartType.Spline); if (kernel != "empty") { kernelData = Reader.readHex(kernel); } double[][] result = data; pictureBefore.Image = Reader.Draw(Reader.RescaleImage(data, x, y), x, y); switch (listOperations.SelectedItem.ToString().Trim()) { case ("Knearest"): { result = Zoom.Knearest(data, 2); } break; case ("Bilinear"): { result = Zoom.Bilinear(data, 2); } break; case ("Logarithm"): { result = Zoom.Logarithm(data, 2); } break; case ("Negative"): { result = Processing.Nagative(data, 256); } break; case ("Gamma"): { //improve C after 1 for darkness, degrade after 1 for light //For xcr (need rescale + normilize) result = Processing.Gamma(data, 1, 0.7); } break; case ("Remove Border (LPF)"): { result = Border.StepFunction(result, 180, 180, 8); result = Border.RemoveBorder_LPF(result, 0.05, 16, dt); } break; case ("Remove Border (Gradient)"): { result = Border.Gradient(result); result = Border.StepFunction(result, 1, 1, 8); } break; case ("Remove Border (Laplassian)"): { result = Border.Laplassian(result); } break; case ("Recover"): { if (kernel != "empty") { result = Recover.recovery(result, kernel); } else { MessageBox.Show("no kernel uploaded"); } } break; case ("Recover with Noize"): { if (kernel != "empty") { result = Recover.recoveryWithNoize(result, kernel, 0.01); } else { MessageBox.Show("no kernel uploaded"); } } break; case ("Remove Grid"): { //Calculate grid fcuts: //среднее по массиву Фурье: double avg = Fourier.CalcAVG(tempFourier1); //среднеквадратичное отклонение (сигма) double sigma = Fourier.CalcStandardDeviation(tempFourier1); //поиск пика: double[] temp = new double[tempFourier1.Length]; for (int i = 0; i < tempFourier1.Length / 2; i++) { if (tempFourier1[i] > avg + sigma / 4) { temp[i] = i * (dt / data.Length); } } var peaks = from point in temp where point != 0 select point; double lefttmp = 0.275609756097561; double left = peaks.Min(); double right = peaks.Max(); result = Recover.removeLines(data, lefttmp, right, 64, dt); } break; case ("Dilatation"): { result = Border.StepFunction(result, 180, 180, 8); double[][] step = result; step = Copy2D(result, step); result = Processing.ApplyMaskDilatation(result, 10, 128); for (int i = 0; i < step.Length; i++) { for (int j = 0; j < step[0].Length; j++) { result[i][j] -= step[i][j]; } } } break; case ("Erosion"): { result = Border.StepFunction(result, 180, 180, 8); double[][] step = result; step = Copy2D(result, step); step = Processing.ApplyMaskErosion(step, 10, 128); for (int i = 0; i < step.Length; i++) { for (int j = 0; j < step[0].Length; j++) { result[i][j] -= step[i][j]; } } } break; default: break; } if (listOperations.SelectedItem.ToString().Trim() != "Equalize") { pictureAfter.Image = Reader.Draw(Reader.RescaleImage(result, x, y), x, y); } else { //Prepare Hist int levels = 256; DrawHist(Parser.BitmapTo2D((Bitmap)pictureBefore.Image), chartHisto, levels); //LEGACY //Draw Picture pictureBefore.Image = Parser.readFile(image); Bitmap temp = (Bitmap)pictureBefore.Image.Clone(); pictureAfter.Image = Processing.Equalizing(temp); } }
private void noizeBtn_Click(object sender, EventArgs e) { double[][] result = data; switch (listNoize.SelectedItem.ToString().Trim()) { case ("Random"): { result = Processing.randomNoize(data, 0.4); } break; case ("Impulse (Salt and Pepper)"): { result = Processing.noizeSaltAndPepper(data, 0.25); } break; case ("Both"): { result = Processing.noizeSaltAndPepper(data, 0.25); result = Processing.randomNoize(result, 0.25); } break; default: break; } noize = Copy2D(result, noize); switch (listRemoveNoize.SelectedItem.ToString().Trim()) { case ("Avg"): { result = Filters.AvgFilter(noize, 3); pictureBefore.Image = Reader.Draw(Reader.RescaleImage(noize, x, y), x, y); } break; case ("Median"): { result = Filters.MedianFilter(noize, 7); pictureBefore.Image = Reader.Draw(Reader.RescaleImage(noize, x, y), x, y); } break; case ("LPF"): { //find filter freq //prepare clear data fourier and then minus the noize fourier tempFourier2 = new double[tempFourier1.Length]; for (int i = 0; i < tempFourier1.Length; i++) { tempFourier2[i] -= tempFourier1[i]; } //Print Fourier wth Noize //tempFourier2 = PrepareVerticalFouirier(result, line); Fourier.Draw(fourierChart, tempFourier2, SeriesChartType.Spline); //LPF Filter result = Filters.LPF_y(result, filter, 64, dt); //Print Fourier after LPF //tempFourier2 = PrepareVerticalFouirier(temp, line); //Fourier.Draw(fourierChart, tempFourier2, System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline); //output noize picture pictureBefore.Image = Reader.Draw(Reader.RescaleImage(noize, x, y), x, y); } break; case ("HPF"): { double[][] temp = result; temp = Copy2D(result, temp); //Print Fourier wth Noize tempFourier2 = PrepareVerticalFouirier(temp, line); Fourier.Draw(fourierChart, tempFourier2, SeriesChartType.Spline); //HPF Filter temp = Filters.HPF_y(temp, filter, 64, dt); //Print Fourier after HPF //tempFourier2 = PrepareVerticalFouirier(temp, line); //Fourier.Draw(fourierChart, tempFourier2, System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline); //output noize picture pictureBefore.Image = Reader.Draw(Reader.RescaleImage(noize, x, y), x, y); //HPF minus noize picture for (int i = 0; i < temp.Length; i++) { for (int j = 0; j < temp[0].Length; j++) { result[i][j] -= temp[i][j]; } } } break; default: break; } pictureAfter.Image = Reader.Draw(Reader.RescaleImage(result, x, y), x, y); }