protected override void ProcessImage(object sender)
        {
            try
            {
                int rGMin = int.Parse(this.RGMin);
                int rGMax = int.Parse(this.RGMax);
                int gGMin = int.Parse(this.GGMin);
                int gGMax = int.Parse(this.GGMax);
                int bGMin = int.Parse(this.BGMin);
                int bGMax = int.Parse(this.BGMax);

                if (rGMin < 0 || rGMin > 255 || rGMax < 0 || rGMax > 255 || rGMin > rGMax || gGMin < 0 || gGMin > 255 || gGMax < 0 || gGMax > 255 || gGMin > gGMax || bGMin < 0 || bGMin > 255 || bGMax < 0 || bGMax > 255 || bGMin > bGMax)
                {
                    throw new ArgumentException("Invalid input range!");
                }

                Bitmap input  = this.WorkspaceViewModel.Input;
                Bitmap output = this.WorkspaceViewModel.GetClonedInput();

                BarchartData barchartData = BarchartData.GenerateBarcharData(256, input);
                int          n            = input.Width * input.Height;

                for (int i = 0; i < output.Width; i++)
                {
                    for (int j = 0; j < output.Height; j++)
                    {
                        Color pixel = input.GetPixel(i, j);
                        output.SetPixel(i, j, Color.FromArgb(
                                            this.CalculateNewPixelValue(rGMin, rGMax, i, j, pixel.R, barchartData.Red, n),
                                            this.CalculateNewPixelValue(gGMin, gGMax, i, j, pixel.G, barchartData.Green, n),
                                            this.CalculateNewPixelValue(bGMin, bGMax, i, j, pixel.B, barchartData.Blue, n)
                                            ));
                    }
                }
                this.WorkspaceViewModel.Output = output;
            }
            catch (Exception)
            {
                Notify.Error("Invalid input value!\nGmin must be an int between 0 and 255.\nGmax must be an int between 0 and 255.\nGmin must be lower than Gmax.");
            }
        }
Esempio n. 2
0
        protected override void ProcessImage(object sender)
        {
            try
            {
                int n = int.Parse(this.N);
                if (n > 255 || n < 1)
                {
                    throw new ArgumentException("Invalid input range!");
                }
                List <string> Labels = new List <string>();

                Bitmap input = this.WorkspaceViewModel.Input;

                double range = 255.0 / n;
                double start = 0;

                for (int i = 0; i < n; i++)
                {
                    if (i != n - 1)
                    {
                        double next = start + range;
                        Labels.Add(Convert.ToInt32(start) + "-" + Convert.ToInt32(next));
                        start = next;
                    }
                    else
                    {
                        Labels.Add(Convert.ToInt32(start) + "-" + 255);
                    }
                }

                BarchartData barchartData = BarchartData.GenerateBarcharData(n, input);

                Task.Run(() =>
                {
                    Application.Current.Dispatcher.Invoke(delegate
                    {
                        SeriesCollection red = new SeriesCollection();
                        red.Add(new LineSeries {
                            Title = "R", Values = new ChartValues <int>(barchartData.Red), Fill = new SolidColorBrush(System.Windows.Media.Color.FromRgb(255, 0, 0)), PointGeometry = null
                        });

                        SeriesCollection green = new SeriesCollection();
                        green.Add(new LineSeries {
                            Title = "G", Values = new ChartValues <int>(barchartData.Green), Fill = new SolidColorBrush(System.Windows.Media.Color.FromRgb(0, 255, 0)), PointGeometry = null
                        });

                        SeriesCollection blue = new SeriesCollection();
                        blue.Add(new LineSeries {
                            Title = "B", Values = new ChartValues <int>(barchartData.Blue), Fill = new SolidColorBrush(System.Windows.Media.Color.FromRgb(0, 0, 255)), PointGeometry = null
                        });

                        Window redWindow   = new BarchartView(red, Labels);
                        Window greenWindow = new BarchartView(green, Labels);
                        Window blueWindow  = new BarchartView(blue, Labels);

                        redWindow.Show();
                        greenWindow.Show();
                        blueWindow.Show();
                    });
                });
            }
            catch (Exception)
            {
                Notify.Error("Invalid input value!\nValue must be an int between 1 and 256.");
            }
        }