private void HistButton_Click(object sender, RoutedEventArgs e) { var val = CalcHistogram(); if (CheckIfGray()) { var values = val.Item1; var histWindow = new HistogramWindow(); WindowsFormsHost host = new WindowsFormsHost(); HistSomething.UserControl1 graph = new HistSomething.UserControl1(values); host.Child = graph; histWindow.grid.Children.Add(host); histWindow.Width = graph.Width + 2 * 20; histWindow.Height = graph.Height + 3 * 20; histWindow.Show(); } else { var values_r = val.Item1; var values_g = val.Item2; var values_b = val.Item3; var histWindow = new HistogramWindow(); WindowsFormsHost host = new WindowsFormsHost(); HistSomething.UserControl3 graph = new HistSomething.UserControl3(values_r, values_g, values_b); host.Child = graph; histWindow.grid.Children.Add(host); histWindow.Width = graph.Width + 2 * 30; histWindow.Height = graph.Height + 3 * 30; histWindow.Show(); } }
private void StrechHistButton_Click(object sender, RoutedEventArgs e) { var bitmap = BitmapFromSource((BitmapSource)Image.Source); if (CheckIfGray()) { var values = new List <int>(); for (int i = 0; i < bitmap.Width; i++) { for (int j = 0; j < bitmap.Height; j++) { values.Add(bitmap.GetPixel(i, j).R); } } var stretched = StretchFunction(values); var iter = 0; for (int i = 0; i < bitmap.Width; i++) { for (int j = 0; j < bitmap.Height; j++) { bitmap.SetPixel(i, j, System.Drawing.Color.FromArgb(stretched[iter], stretched[iter], stretched[iter])); iter++; } } Image.Source = ConvertBitmap(bitmap); var val = CalcHistogram(); var values4hist = val.Item1; values4hist[0] = 0; values4hist[255] = 0; var histWindow = new HistogramWindow(); WindowsFormsHost host = new WindowsFormsHost(); HistSomething.UserControl1 graph = new HistSomething.UserControl1(values4hist); host.Child = graph; histWindow.grid.Children.Add(host); histWindow.Width = graph.Width + 2 * 20; histWindow.Height = graph.Height + 3 * 20; histWindow.Show(); } else { var values_r = new List <int>(); var values_g = new List <int>(); var values_b = new List <int>(); for (int i = 0; i < bitmap.Width; i++) { for (int j = 0; j < bitmap.Height; j++) { values_r.Add(bitmap.GetPixel(i, j).R); values_g.Add(bitmap.GetPixel(i, j).G); values_b.Add(bitmap.GetPixel(i, j).B); } } var stretched_r = StretchFunction(values_r); var stretched_g = StretchFunction(values_g); var stretched_b = StretchFunction(values_b); var iter = 0; for (int i = 0; i < bitmap.Width; i++) { for (int j = 0; j < bitmap.Height; j++) { bitmap.SetPixel(i, j, System.Drawing.Color.FromArgb(stretched_r[iter], stretched_g[iter], stretched_b[iter])); iter++; } } Image.Source = ConvertBitmap(bitmap); var val = CalcHistogram(); var values_r4hist = val.Item1; var values_g4hist = val.Item2; var values_b4hist = val.Item3; values_r4hist[0] = 0; values_r4hist[255] = 0; values_g4hist[0] = 0; values_g4hist[255] = 0; values_b4hist[0] = 0; values_b4hist[255] = 0; var histWindow = new HistogramWindow(); WindowsFormsHost host = new WindowsFormsHost(); HistSomething.UserControl3 graph = new HistSomething.UserControl3(values_r4hist, values_g4hist, values_b4hist); host.Child = graph; histWindow.grid.Children.Add(host); histWindow.Width = graph.Width + 2 * 30; histWindow.Height = graph.Height + 3 * 30; histWindow.Show(); } }
private void EqHistButton_Click(object sender, RoutedEventArgs e) { var val = CalcHistogram(); var pixelAmount = 0; foreach (var v in val.Item1) { pixelAmount += v; } if (CheckIfGray()) { var values = val.Item1; var distribution = CalcDistribution(values, pixelAmount); var LUT_table = CalcLUTTable(distribution); var bitmap = BitmapFromSource((BitmapSource)Image.Source); for (int i = 0; i < bitmap.Width; i++) { for (int j = 0; j < bitmap.Height; j++) { var pixel = bitmap.GetPixel(i, j); bitmap.SetPixel(i, j, System.Drawing.Color.FromArgb(LUT_table[pixel.R], LUT_table[pixel.R], LUT_table[pixel.R])); } } Image.Source = ConvertBitmap(bitmap); var val4hist = CalcHistogram(); var values4hist = val4hist.Item1; var histWindow = new HistogramWindow(); WindowsFormsHost host = new WindowsFormsHost(); HistSomething.UserControl1 graph = new HistSomething.UserControl1(values4hist); host.Child = graph; histWindow.grid.Children.Add(host); histWindow.Width = graph.Width + 2 * 20; histWindow.Height = graph.Height + 3 * 20; histWindow.Show(); } else { var values_r = val.Item1; var values_g = val.Item2; var values_b = val.Item3; var distribution_r = CalcDistribution(values_r, pixelAmount); var distribution_g = CalcDistribution(values_g, pixelAmount); var distribution_b = CalcDistribution(values_b, pixelAmount); var LUT_table_r = CalcLUTTable(distribution_r); var LUT_table_g = CalcLUTTable(distribution_g); var LUT_table_b = CalcLUTTable(distribution_b); var bitmap = BitmapFromSource((BitmapSource)Image.Source); for (int i = 0; i < bitmap.Width; i++) { for (int j = 0; j < bitmap.Height; j++) { var pixel = bitmap.GetPixel(i, j); bitmap.SetPixel(i, j, System.Drawing.Color.FromArgb(LUT_table_r[pixel.R], LUT_table_g[pixel.G], LUT_table_b[pixel.B])); } } Image.Source = ConvertBitmap(bitmap); var val4hist = CalcHistogram(); var values_r4hist = val4hist.Item1; var values_g4hist = val4hist.Item2; var values_b4hist = val4hist.Item3; var histWindow = new HistogramWindow(); WindowsFormsHost host = new WindowsFormsHost(); HistSomething.UserControl3 graph = new HistSomething.UserControl3(values_r4hist, values_g4hist, values_b4hist); host.Child = graph; histWindow.grid.Children.Add(host); histWindow.Width = graph.Width + 2 * 30; histWindow.Height = graph.Height + 3 * 30; histWindow.Show(); } }