// Switch channel public void SwitchChannel(int channel) { if ((channel >= 0) && (channel <= 2)) { if (!stat.IsGrayscale) { histogram.Color = colors[channel]; activeHistogram = (channel == 0) ? stat.Red : (channel == 1) ? stat.Green : stat.Blue; } } else if (channel == 3) { if (stat.IsGrayscale) { histogram.Color = colors[3]; activeHistogram = stat.Gray; } } if (activeHistogram != null) { histogram.Values = activeHistogram.Values; meanLabel.Text = activeHistogram.Mean.ToString("F2"); stdDevLabel.Text = activeHistogram.StdDev.ToString("F2"); medianLabel.Text = activeHistogram.Median.ToString(); minLabel.Text = activeHistogram.Min.ToString(); maxLabel.Text = activeHistogram.Max.ToString(); } }
private void DoRGBHistogram(AForge.Math.Histogram RedHist, AForge.Math.Histogram GreenHist, AForge.Math.Histogram BlueHist) { // Decide which set of values are placed at back, in the middle and to the front of the graph. List <double> lis = new List <double>(); lis.Add(RedHist.Mean); lis.Add(GreenHist.Mean); lis.Add(BlueHist.Mean); lis.Sort(); try { chart.Series.Add("Red"); chart.Series.Add("Green"); chart.Series.Add("Blue"); // Set SplineArea chart type chart.Series["Red"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.SplineArea; chart.Series["Green"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.SplineArea; chart.Series["Blue"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.SplineArea; // set line tension chart.Series["Red"]["LineTension"] = "0.8"; chart.Series["Green"]["LineTension"] = "0.8"; chart.Series["Blue"]["LineTension"] = "0.8"; // Set colour and transparency chart.Series["Red"].Color = Color.FromArgb(50, Color.Red); chart.Series["Green"].Color = Color.FromArgb(50, Color.Green); chart.Series["Blue"].Color = Color.FromArgb(50, Color.Blue); // Disable X & Y axis labels chart.ChartAreas["Default"].AxisX.LabelStyle.Enabled = false; chart.ChartAreas["Default"].AxisY.LabelStyle.Enabled = false; chart.ChartAreas["Default"].AxisX.MinorGrid.Enabled = false; chart.ChartAreas["Default"].AxisX.MajorGrid.Enabled = false; chart.ChartAreas["Default"].AxisY.MinorGrid.Enabled = false; chart.ChartAreas["Default"].AxisY.MajorGrid.Enabled = false; } catch (Exception) { // Throws an exception if it is already created. } chart.Series["Red"].Points.Clear(); chart.Series["Green"].Points.Clear(); chart.Series["Blue"].Points.Clear(); foreach (double value in RedHist.Values) { chart.Series["Red"].Points.AddY(value); } foreach (double value in GreenHist.Values) { chart.Series["Green"].Points.AddY(value); } foreach (double value in BlueHist.Values) { chart.Series["Blue"].Points.AddY(value); } }
/// <summary> /// Draws the Histogram on the Chart /// </summary> /// <param name="RedHist"></param> /// <param name="GreenHist"></param> /// <param name="BlueHist"></param> private void DoRGBHistogram(AForge.Math.Histogram RedHist, AForge.Math.Histogram GreenHist, AForge.Math.Histogram BlueHist) { chart.Series.Clear(); chart.Series.Add("Red"); chart.Series.Add("Green"); chart.Series.Add("Blue"); // Set SplineArea chart type SelectChartType(); // set line tension chart.Series["Red"]["LineTension"] = "0.8"; chart.Series["Green"]["LineTension"] = "0.8"; chart.Series["Blue"]["LineTension"] = "0.8"; // Set colour and transparency chart.Series["Red"].Color = Color.FromArgb(50, Color.Red); chart.Series["Green"].Color = Color.FromArgb(50, Color.Green); chart.Series["Blue"].Color = Color.FromArgb(50, Color.Blue); // Disable X & Y axis labels chart.ChartAreas["Default"].AxisX.LabelStyle.Enabled = false; chart.ChartAreas["Default"].AxisY.LabelStyle.Enabled = false; chart.ChartAreas["Default"].AxisX.MinorGrid.Enabled = false; chart.ChartAreas["Default"].AxisX.MajorGrid.Enabled = false; chart.ChartAreas["Default"].AxisY.MinorGrid.Enabled = false; chart.ChartAreas["Default"].AxisY.MajorGrid.Enabled = false; chart.Series["Red"].Points.Clear(); chart.Series["Green"].Points.Clear(); chart.Series["Blue"].Points.Clear(); foreach (double value in RedHist.Values) { chart.Series["Red"].Points.AddY(value); } foreach (double value in GreenHist.Values) { chart.Series["Green"].Points.AddY(value); } foreach (double value in BlueHist.Values) { chart.Series["Blue"].Points.AddY(value); } lblRedMin.Text = RedHist.Min.ToString("N0"); lblRedMean.Text = RedHist.Mean.ToString("N0"); lblRedMax.Text = RedHist.Max.ToString("N0"); lblGreenMin.Text = GreenHist.Min.ToString("N0"); lblGreenMean.Text = GreenHist.Mean.ToString("N0"); lblGreenMax.Text = GreenHist.Max.ToString("N0"); lblBlueMin.Text = BlueHist.Min.ToString("N0"); lblBlueMean.Text = BlueHist.Mean.ToString("N0"); lblBlueMax.Text = BlueHist.Max.ToString("N0"); }
override protected void Show(IDialogVisualizerService windowService, IVisualizerObjectProvider objectProvider) { AForge.Math.Histogram histogram = (AForge.Math.Histogram)objectProvider.GetObject( ); HistogramView histogramView = new HistogramView( ); histogramView.SetHistogram(histogram); windowService.ShowDialog(histogramView); }
private void GetHistogram() { ImageStatistics rgbStatistics = new ImageStatistics(_image); AForge.Math.Histogram h = rgbStatistics.Red; RedValues = h.Values; h = rgbStatistics.Green; GreenValues = h.Values; h = rgbStatistics.Blue; BlueValues = h.Values; }
public static int Center2QuantileValue(this AForge.Math.Histogram hist, double center) { if (center > 0.5) { return(hist.GetRange((0.5 - center) * 2).Min); } else { return(hist.GetRange((center - 0.5) * 2).Max); } }
public void TestgetHist() { ImageInfo imInf = new ImageInfo(PATH_160_120_RGB); AForge.Math.Histogram hist = imInf.getHist(); Console.WriteLine("{0} {1} {2} {3} {4} {5}\n", hist.Max, hist.Min, hist.Mean, hist.StdDev, hist.TotalCount, hist.Median); int[] histVal = hist.Values; for (int i = 0; i < histVal.Length; i++) { Console.Write("{0} ", histVal[i]); } }
public ColorFiltrationWindow() { InitializeComponent(); mf = (MainForm)checkifwinopen(typeof(MainForm)); ImageStatistics stat = new ImageStatistics((Bitmap)mf.pictureBox.Image); AForge.Math.Histogram histogram = stat.Red; redmax.Value = histogram.Max; redmin.Value = histogram.Min; histogram = stat.Green; greenmax.Value = histogram.Max; greenmin.Value = histogram.Min; histogram = stat.Blue; bluemax.Value = histogram.Max; bluemin.Value = histogram.Min; }
private void Histogram_Load(object sender, EventArgs e) { stat1 = new AForge.Imaging.ImageStatistics(citraawal); stat2 = new AForge.Imaging.ImageStatistics(citraAFCEDP); stat3 = new AForge.Imaging.ImageStatistics(citraACEDP); histogram1.Color = Color.Black; histogram2.Color = Color.Black; histogram3.Color = Color.Black; hist1 = stat1.Red; hist2 = stat2.Red; hist3 = stat3.Red; histogram1.Values = hist1.Values; histogram2.Values = hist2.Values; histogram3.Values = hist3.Values; float aspect1 = Convert.ToSingle((float)citraawal.Width / (float)citraawal.Height); float aspect2 = Convert.ToSingle((float)citraAFCEDP.Width / (float)citraAFCEDP.Height); float aspect3 = Convert.ToSingle((float)citraACEDP.Width / (float)citraACEDP.Height); lbl_awal_aspect.Text = aspect1.ToString("F3"); lbl_AFCEDP_aspec.Text = aspect2.ToString("F3"); lbl_ACEDP_aspect.Text = aspect3.ToString("F3"); lbl_awal_mean.Text = stat1.Red.Mean.ToString("F3"); lbl_AFCEDP_mean.Text = stat2.Red.Mean.ToString("F3"); lbl_ACEDP_mean.Text = stat3.Red.Mean.ToString("F3"); lbl_awal_median.Text = stat1.Red.Median.ToString(); lbl_AFCEDP_median.Text = stat2.Red.Median.ToString(); lbl_ACEDP_median.Text = stat3.Red.Median.ToString(); lbl_awal_Min.Text = stat1.Red.Min.ToString(); lbl_AFCEDP_Min.Text = stat2.Red.Min.ToString(); lbl_ACEDP_min.Text = stat3.Red.Min.ToString(); lbl_awal_max.Text = stat1.Red.Max.ToString(); lbl_AFCEDP_Max.Text = stat2.Red.Max.ToString(); lbl_ACEDP_max.Text = stat3.Red.Max.ToString(); lbl_awal_pixels.Text = stat1.Red.TotalCount.ToString(); lbl_AFCEDP_pixels.Text = stat1.Red.TotalCount.ToString(); lbl_ACEDP_pixels.Text = stat1.Red.TotalCount.ToString(); double stddev1 = AForge.Math.Statistics.StdDev(hist1.Values); double stddev2 = AForge.Math.Statistics.StdDev(hist2.Values); double stddev3 = AForge.Math.Statistics.StdDev(hist3.Values); lbl_awal_std.Text = stddev1.ToString("F3"); lbl_AFCEDP_std.Text = stddev2.ToString("F3"); lbl_ACEDP_std.Text = stddev3.ToString("F3"); }
// gr.ResetTransform(); // gr.DrawRectangle(Pens.Black, 0, 0, width - 1, height - 1); private void DrawHistogramV(Bitmap img) { Color back_color = Color.White; Invert filter = new Invert(); // apply the filter Bitmap inv = filter.Apply(img); VerticalIntensityStatistics his = new VerticalIntensityStatistics(inv); AForge.Math.Histogram histogram = his.Gray; int[] values = histogram.Values; Color[] Colors = new Color[] { Color.Red, Color.LightGreen, Color.Blue, Color.Pink, Color.Green, Color.LightBlue, Color.Orange, Color.Yellow, Color.Purple }; gr2.Clear(back_color); // Draw the histogram. using (Pen thin_pen = new Pen(Color.Black, 0)) { for (int i = 0; i < values.Length; i++) { float f2 = 420F; float fl = (float)values[i] / f2; gr2.DrawLine(thin_pen, 0, i, fl, i); } } }
private void button1_Click(object sender, EventArgs e) { var ofd = new OpenFileDialog(); if (ofd.ShowDialog(this) == DialogResult.OK) { image = System.Drawing.Image.FromFile(ofd.FileName); //pictureBox2.Height = System.Drawing.Image.FromFile(ofd.FileName).Height; // pictureBox2.Width = System.Drawing.Image.FromFile(ofd.FileName).Width; //image.set = System.Drawing.Image.FromFile(ofd.FileName).Height; } pictureBox1.Image = image; //pictureBoxBoxStart.SizeMode = PictureBoxSizeMode.StretchImage; //pictureBoxBoxEnd.SizeMode = PictureBoxSizeMode.StretchImage; // pictureBox1.Image = CalculateBarChart(image); bmp = new System.Drawing.Bitmap(ofd.FileName); // Luminance ImageStatisticsHSL hslStatistics = new ImageStatisticsHSL(bmp); int[] luminanceValues = hslStatistics.Luminance.Values; // RGB ImageStatistics rgbStatistics = new ImageStatistics(bmp); int[] redValues = rgbStatistics.Red.Values; int[] greenValues = rgbStatistics.Green.Values; int[] blueValues = rgbStatistics.Blue.Values; /* List<Vector2> l = ConvertToPointCollection(hslStatistics.Luminance.Values); * //List<Vector2> r = ConvertToPointCollection(rgbStatistics.Red.Values); * Point[] points = new Point[l.Count]; * * for (int i = 0; i < l.Count; i++) * { * float x = l.ElementAt(i).X; * float y = l.ElementAt(i).Y; * * //points[i] = new Point((int)x, (int)y); * Console.WriteLine("x " + x + " y " + y); * chart1.Series[0].Points.AddXY(x, y); * * }*/ AForge.Math.Histogram activeHistogram = null; ImageStatistics stat; // var imag = (Bitmap)image.Clone(); stat = new ImageStatistics(bmp); histogram1.Color = Color.Red; histogram2.Color = Color.Green; histogram3.Color = Color.Blue; histogram4.Color = Color.Black; activeHistogram = stat.Red; histogram1.Values = activeHistogram.Values; activeHistogram = stat.Green; histogram2.Values = activeHistogram.Values; activeHistogram = stat.Blue; histogram3.Values = activeHistogram.Values; //activeHistogram = hslStatistics.; histogram4.Values = hslStatistics.Luminance.Values; /*Graphics g = CreateGraphics(); * g.DrawPolygon(Pens.Gray, points);*/ }