public Histogram(int min, int max, HistogramType state) : this(VisionLabPINVOKE.new_Histogram__SWIG_1(min, max, (int)state), true) { if (VisionLabPINVOKE.SWIGPendingException.Pending) { throw VisionLabPINVOKE.SWIGPendingException.Retrieve(); } }
public static async void StretchHistogram(this Brush brush, int[] lut, HistogramType type) { Bh.Initialize(brush); for (var i = 0; i < Bh.Length; i += 4) { var r = Bh.Pixels[i + 2]; var g = Bh.Pixels[i + 1]; var b = Bh.Pixels[i]; switch (type) { default: case HistogramType.Red: Bh.Pixels[i + 2] = (byte)lut[r]; break; case HistogramType.Green: Bh.Pixels[i + 1] = (byte)lut[g]; break; case HistogramType.Blue: Bh.Pixels[i] = (byte)lut[b]; break; case HistogramType.Average: Bh.Pixels[i + 2] = (byte)lut[r]; Bh.Pixels[i + 1] = (byte)lut[g]; Bh.Pixels[i] = (byte)lut[b]; break; } } await Bh.UpdateBrush(); }
public void Reset(HistogramType state) { VisionLabPINVOKE.Histogram_Reset__SWIG_0(swigCPtr, (int)state); if (VisionLabPINVOKE.SWIGPendingException.Pending) { throw VisionLabPINVOKE.SWIGPendingException.Retrieve(); } }
public HistogramType State() { HistogramType ret = (HistogramType)VisionLabPINVOKE.Histogram_State(swigCPtr); if (VisionLabPINVOKE.SWIGPendingException.Pending) { throw VisionLabPINVOKE.SWIGPendingException.Retrieve(); } return(ret); }
public static int ToInt(this HistogramType e) { switch (e) { case HistogramType.OVERFLOW: return(-1); case HistogramType.UNDERFLOW: return(-2); default: throw new ArgumentOutOfRangeException("HistogramType"); } }
/// <summary> /// Initializes a new instance of the <see cref="Histogram"/> class with the /// specified size. /// </summary> /// <param name="dims">Number of histogram dimensions.</param> /// <param name="sizes">Array of the histogram dimension sizes.</param> /// <param name="type">Histogram representation format.</param> /// <param name="ranges">Array of ranges for the histogram bins.</param> /// <param name="uniform"> /// If <b>true</b> the histogram has evenly spaced bins and for each dimension, <paramref name="ranges"/> /// contains its lower and upper boundaries which are then used to split the dimension into equally sized bins. /// Otherwise, <paramref name="ranges"/> specifies for each dimension the edges of each bin. /// </param> public Histogram(int dims, int[] sizes, HistogramType type, float[][] ranges = null, bool uniform = true) : base(true) { ConvertRanges(ranges, pRanges => { var pHist = NativeMethods.cvCreateHist(dims, sizes, type, pRanges, uniform ? 1 : 0); SetHandle(pHist); }); CreateBins(type); }
public SingleHistogram(ReportNode rp) : base(rp) { AddMenuItem("Statistics", "Histogram w/normal dist.", delegate { histType = HistogramType.WithNormalDist; Plot(); }); AddMenuItem("Statistics", "Histogram", delegate { histType = HistogramType.Normal; Plot(); }); }
void CreateBins(HistogramType type) { unsafe { switch (type) { case HistogramType.Array: bins = new MatND(((_CvHistogram *)handle.ToPointer())->bins, false); break; case HistogramType.Sparse: bins = new SparseMat(((_CvHistogram *)handle.ToPointer())->bins, false); break; } } }
public Form1() { InitializeComponent(); chart = new Chart(); chart.GetToolTipText += chart_GetToolTipText; chart.Dock = DockStyle.Fill; GetData(false); treeView1.Nodes.Add("1", "Volume Chart"); treeView1.Nodes.Add("2", "Power Chart"); treeView1.Nodes.Add("3", "Active Days Chart"); treeView1.Nodes.Add("4", "Sessions Chart"); treeView1.Nodes.Add("5", "Erg Chart"); treeView1.Nodes.Add("6", "Heart Rate"); CurrentChart = HistogramType.Volume; Font = new Font("Microsoft Sans Serif", 12.0f, FontStyle.Bold); }
private void UpdateControls() { TreeNode selectedNode = treeView1.SelectedNode; if (selectedNode.Text.Equals("Volume Chart")) { UpdateHistogramChartDisplay(); UpdateHistogramChartData(HistogramType.Volume); //UpdateVolumeChartData(); CurrentChart = HistogramType.Volume; } else if (selectedNode.Text.Equals("Power Chart")) { UpdatePowerChartDisplay(); UpdatePowerChartData(); } else if (selectedNode.Text.Equals("Active Days Chart")) { UpdateHistogramChartDisplay(); UpdateHistogramChartData(HistogramType.ActiveDays); //UpdateActiveDaysChartData(); CurrentChart = HistogramType.ActiveDays; } else if (selectedNode.Text.Equals("Sessions Chart")) { UpdateHistogramChartDisplay(); UpdateHistogramChartData(HistogramType.Sessions); //UpdateActiveDaysChartData(); CurrentChart = HistogramType.Sessions; } else if (selectedNode.Text.Equals("Erg Chart")) { UpdateErgChartDisplay(); UpdateErgChartData(); } else if (selectedNode.Text.Equals("Heart Rate")) { UpdateHRChartDisplay(); UpdateHRChartData(); } SetChartFont(); }
/// <summary> /// Массив значенией для построения гистограммы. /// </summary> /// <returns></returns> public int[] GetHistogramm(HistogramType type) { int[] result = new int[256]; int max = 0; if (type != HistogramType.RGB) { for (i = 0; i < PixelsCount; i++) { if (type == HistogramType.R) { someIntValue = PixelsBuffer[2]; } if (type == HistogramType.G) { someIntValue = PixelsBuffer[1]; } if (type == HistogramType.B) { someIntValue = PixelsBuffer[0]; } if (type == HistogramType.Brightness) { someIntValue = (PixelsBuffer[0] + PixelsBuffer[1] + PixelsBuffer[2]) / 3; } if (someIntValue > 255) { someIntValue = 255; } if (max < ++result[someIntValue]) { max = result[someIntValue]; } PixelsBuffer += Channels; } PixelsBuffer -= PixelsCountWithChannels; } return(result); }
/// <summary> /// Handles the SelectedIndexChanged event of HistogramTypeComboBox object. /// </summary> private void histogramTypeComboBox_SelectedIndexChanged(object sender, EventArgs e) { HistogramType histogramType = HistogramType.Luminosity; switch (histogramTypeComboBox.SelectedIndex) { case 1: histogramType = HistogramType.Red; break; case 2: histogramType = HistogramType.Green; break; case 3: histogramType = HistogramType.Blue; break; } // if histogram type is changed if (_histogramType != histogramType) { _histogramType = histogramType; VintasoftImage oldHistogramImage = _histogramImage; // update histogram image _histogramImage = GetHistogramImage(_image, _imageRegion, _histogramType); histogramImagePictureBox.Image = _histogramImage.GetAsBitmap(); if (oldHistogramImage != null) { oldHistogramImage.Dispose(); oldHistogramImage = null; } Invalidate(); } }
private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { var combobox = (ComboBox)sender; var selectedItem = (ComboBoxItem)combobox.SelectedItem; if (selectedItem == null || HistogramPolygon == null) { return; } switch (selectedItem.Content.ToString()) { default: case "Czerwony": HistogramPolygon.Points = HistogramHelper.ConvertToPointCollection(_histogram.HistogramR); HistogramPolygon.Fill = new SolidColorBrush(Colors.Red); HistogramType = HistogramType.Red; break; case "Zielony": HistogramPolygon.Points = HistogramHelper.ConvertToPointCollection(_histogram.HistogramG); HistogramPolygon.Fill = new SolidColorBrush(Colors.Green); HistogramType = HistogramType.Green; break; case "Niebieski": HistogramPolygon.Points = HistogramHelper.ConvertToPointCollection(_histogram.HistogramB); HistogramPolygon.Fill = new SolidColorBrush(Colors.Blue); HistogramType = HistogramType.Blue; break; case "Uśredniony": HistogramPolygon.Points = HistogramHelper.ConvertToPointCollection(_histogram.HistogramAv); HistogramPolygon.Fill = new SolidColorBrush(Colors.Gray); HistogramType = HistogramType.Average; break; } }
public Histogram(int min, int max, HistogramType state) : this(VisionLabPINVOKE.new_Histogram__SWIG_1(min, max, (int)state), true) { if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve(); }
/// <summary> /// Returns an image with histogram. /// </summary> /// <param name="image">Source image.</param> /// <param name="imageRegion">An image region, which should be processed.</param> /// <param name="histogramType">Histogram type.</param> /// <returns>Image with histogram.</returns> private VintasoftImage GetHistogramImage( VintasoftImage image, Rectangle imageRegion, HistogramType histogramType) { // get histogram data GetHistogramCommand command = new GetHistogramCommand(histogramType); command.RegionOfInterest = new RegionOfInterest(imageRegion); command.ExpandSupportedPixelFormats = _expandSupportedPixelFormats; command.Results = new ProcessingCommandResults(); command.ExecuteInPlace(image); GetHistogramCommandResult getHistogramCommandResult = (GetHistogramCommandResult)command.Results[0]; _histogramData = getHistogramCommandResult.HistogramData; // get the maximum value of histogram int histogramMaxValue = 0; for (int i = 0; i < HISTOGRAM_DATA_SIZE; i++) { if (histogramMaxValue < _histogramData[i]) { histogramMaxValue = _histogramData[i]; } } // create an image with histogram VintasoftImage histogramImage = new VintasoftImage(HISTOGRAM_IMAGE_WIDTH, HISTOGRAM_IMAGE_HEIGHT, PixelFormat.Bgr24); int histogramSizeX = HISTOGRAM_IMAGE_WIDTH - 2 * HISTOGRAM_IMAGE_QUIET_ZONE_SIZE; int histogramSizeY = HISTOGRAM_IMAGE_HEIGHT - 2 * HISTOGRAM_IMAGE_QUIET_ZONE_SIZE; float histogramPenWidth = (float)histogramSizeX / HISTOGRAM_DATA_SIZE; Pen histogramPen = new Pen(_histogramColor, histogramPenWidth); Brush backgroundBrush = new SolidBrush(_histogramBackground); Graphics graphics = histogramImage.OpenGraphics(); graphics.FillRectangle(backgroundBrush, 0, 0, HISTOGRAM_IMAGE_WIDTH, HISTOGRAM_IMAGE_HEIGHT); float x1, y1, x2, y2; for (int i = 0; i < HISTOGRAM_DATA_SIZE; i++) { int v = _histogramData[i]; x1 = HISTOGRAM_IMAGE_QUIET_ZONE_SIZE + histogramPenWidth * i + histogramPenWidth / 2; y1 = HISTOGRAM_IMAGE_HEIGHT - HISTOGRAM_IMAGE_QUIET_ZONE_SIZE; x2 = x1; y2 = y1 - v * ((float)histogramSizeY / histogramMaxValue); if (y2 == y1) { y2 = y1 - 1; } graphics.DrawLine(histogramPen, x1, y1, x2, y2); } histogramImage.CloseGraphics(); // return the image with histogram return(histogramImage); }
public Histogram(HistogramType type) { Type = type; this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true); }
internal static extern IntPtr cvCreateHist(int dims, int[] sizes, HistogramType type, IntPtr[] ranges, int uniform);
public void Reset(HistogramType state) { VisionLabPINVOKE.Histogram_Reset__SWIG_0(swigCPtr, (int)state); if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve(); }
public static string HistogramTypeToStr(HistogramType t) { string ret = VisionLabPINVOKE.HistogramTypeToStr((int)t); if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve(); return ret; }
//private void UpdateVolumeChartData() //{ // splitContainer2.Panel2.Controls.Clear(); // splitContainer2.Panel2.Controls.Add(chart); // chart.ChartAreas.Clear(); // chart.Series.Clear(); // ChartArea area = new ChartArea("1"); // area.AxisX.LabelStyle.Format = "MM/dd/yyyy"; // area.AxisX.LabelStyle.Angle = -90; // area.AxisX.IntervalType = DateTimeIntervalType.Months; // chart.ChartAreas.Add(area); // TextBox textBoxBins = (TextBox)splitContainer2.Panel1.Controls[1]; // int binCount = Int32.Parse(textBoxBins.Text); // DateTime minDate = GetMinDate(); // DateTime maxDate = GetMaxDate(); // int totDays = GetTotDays(); // int binDiff = totDays / binCount; // int[] bins = new int[binCount]; // for (int i = 0; i < bins.Length; i++) // { // bins[i] = 0; // } // foreach (Activity a in Data) // { // int currentDay = a.Date.Subtract(minDate).Days; // if (currentDay == 0) // bins[0] = bins[0] + 1; // else // { // double i = ((double)currentDay / totDays) * binCount; // int bin = (int)Math.Ceiling(i) - 1; // bins[bin] = bins[bin] + 1; // } // } // Series ser = new Series(); // ser.ChartType = SeriesChartType.Column; // ser.ChartArea = "1"; // ser.XValueType = ChartValueType.DateTime; // for (int i = 0; i < bins.Length; i++) // { // DateTime center = minDate.AddDays((binDiff * (i)) + binDiff / 2); // DataPoint pt = new DataPoint(); // pt.SetValueXY(center, bins[i]); // pt.ToolTip = minDate.AddDays((binDiff * (i))).ToString() + "\n" + minDate.AddDays((binDiff * (i)) + binDiff).ToString(); // ser.Points.Add(pt); // } // //int width = (int)chart.ChartAreas[0].Position.Width; // int pixelWidth = 1;// (int)Math.Floor((double)width / binCount); // ser["PointWidth"] = pixelWidth.ToString(); // ser.BorderColor = Color.Black; // ser.BorderWidth = 1; // chart.Series.Add(ser); //} //private void UpdateActiveDaysChartData() //{ // splitContainer2.Panel2.Controls.Clear(); // splitContainer2.Panel2.Controls.Add(chart); // chart.ChartAreas.Clear(); // chart.Series.Clear(); // ChartArea area = new ChartArea("1"); // area.AxisX.LabelStyle.Format = "MM/dd/yyyy"; // area.AxisX.LabelStyle.Angle = -90; // area.AxisX.IntervalType = DateTimeIntervalType.Months; // chart.ChartAreas.Add(area); // TextBox textBoxBins = (TextBox)splitContainer2.Panel1.Controls[1]; // DateTime minDate = GetMinDate(); // DateTime maxDate = GetMaxDate(); // int totDays = GetTotDays(); // int binDiff = 7; // int binCount = (int)Math.Ceiling((double)totDays / binDiff); // int[] bins = new int[binCount]; // for (int i = 0; i < bins.Length; i++) // { // bins[i] = 0; // } // List<DateTime> dates = new List<DateTime>(); // foreach (Activity a in Data) // { // if (!dates.Contains(a.Date)) // { // dates.Add(a.Date); // int currentDay = a.Date.Subtract(minDate).Days; // if (currentDay == 0) // bins[0] = bins[0] + 1; // else // { // int i = (int)Math.Floor((double)currentDay / binDiff); // bins[i] = bins[i] + 1; // } // } // } // Series ser = new Series(); // ser.ChartType = SeriesChartType.Column; // ser.ChartArea = "1"; // ser.XValueType = ChartValueType.DateTime; // for (int i = 0; i < bins.Length; i++) // { // DateTime center = minDate.AddDays((binDiff * (i)) + binDiff / 2); // DataPoint pt = new DataPoint(); // pt.SetValueXY(center, bins[i]); // pt.ToolTip = minDate.AddDays((binDiff * (i))).ToString() + "\n" + minDate.AddDays((binDiff * (i)) + binDiff).ToString(); // ser.Points.Add(pt); // } // //int width = (int)chart.ChartAreas[0].Position.Width; // int pixelWidth = 1;// (int)Math.Floor((double)width / binCount); // ser["PointWidth"] = pixelWidth.ToString(); // ser.BorderColor = Color.Black; // ser.BorderWidth = 1; // chart.Series.Add(ser); //} #endregion private void UpdateHistogramChartData(HistogramType histogramType) { splitContainer2.Panel2.Controls.Clear(); splitContainer2.Panel2.Controls.Add(chart); chart.ChartAreas.Clear(); chart.Series.Clear(); ChartArea area = new ChartArea("1"); area.AxisX.LabelStyle.Format = "MM/dd/yyyy"; area.AxisX.LabelStyle.Angle = -90; area.AxisX.IntervalType = DateTimeIntervalType.Months; chart.ChartAreas.Add(area); TextBox textBoxDays = (TextBox)splitContainer2.Panel1.Controls[1]; int binDays = Int16.Parse(textBoxDays.Text); DateTime minDate = GetMinDate(); DateTime maxDate = DateTime.Now; int totDays = maxDate.Subtract(minDate).Days; int binCount = (int)Math.Ceiling((double)totDays / binDays); int remDays; Math.DivRem(totDays, binDays, out remDays); int[] bins = new int[binCount + 1]; for (int i = 0; i < bins.Length; i++) { bins[i] = 0; } List <DateTime> workoutDays = new List <DateTime>(); Data = Data.OrderBy(a => a.Date).ToList(); foreach (Activity a in Data) { int currentDay = a.Date.Subtract(minDate).Days; int bin; if (currentDay < remDays) { bin = 0; } else { bin = (int)Math.Floor((currentDay - remDays - .001) / (double)binDays) + 1; if (bin == bins.Length) { bin = bin - 1; } } if (histogramType == HistogramType.ActiveDays) { if (!workoutDays.Contains(a.Date)) { bins[bin] = bins[bin] + 1; } workoutDays.Add(a.Date); } if (histogramType == HistogramType.Sessions) { bins[bin] = bins[bin] + 1; } if (histogramType == HistogramType.Volume) { bins[bin] = bins[bin] + a.WorkPerformed; } } Series ser = new Series(); ser.ChartType = SeriesChartType.Column; ser.ChartArea = "1"; ser.XValueType = ChartValueType.DateTime; for (int i = 0; i < bins.Length; i++) { DateTime center; double start; double end; if (i == 0) { start = 0; center = minDate.AddDays(remDays / 2); end = remDays; } else { start = (i - 1) * binDays + remDays; center = minDate.AddDays(start + (double)binDays / 2); end = start + binDays; } DataPoint pt = new DataPoint(); pt.SetValueXY(center, bins[i]); pt.ToolTip = GetDate(minDate.AddDays(start)) + "\n" + GetDate(minDate.AddDays(end)) + "\n" + String.Format("{0:n0}", bins[i]); ser.Points.Add(pt); } //int width = (int)chart.ChartAreas[0].Position.Width; int pixelWidth = 1;// (int)Math.Floor((double)width / binCount); ser["PointWidth"] = pixelWidth.ToString(); ser.BorderColor = Color.Black; ser.BorderWidth = 1; chart.Series.Add(ser); if (histogramType == HistogramType.ActiveDays) { chart.ChartAreas[0].AxisY.Title = "Active Days"; } if (histogramType == HistogramType.Sessions) { chart.ChartAreas[0].AxisY.Title = "Total Sessions"; } if (histogramType == HistogramType.Volume) { chart.ChartAreas[0].AxisY.Title = "Total Volume (ft-lbs)"; } chart.ChartAreas[0].AxisX.ScaleView.Zoomable = true; chart.MouseWheel += chart_MouseWheel; }
public static Histogram CalcHistogram(Int32Image image, Int32Image roi, HistogramType t) { Histogram ret = new Histogram(VisionLabPINVOKE.CalcHistogram__SWIG_18(Int32Image.getCPtr(image), Int32Image.getCPtr(roi), (int)t), true); if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve(); return ret; }
public static async Task <ImageBrush> StretchHistogram(ImageBrush origin, int[] lut, HistogramType type) { var wb = (WriteableBitmap)origin.ImageSource; var data = wb.PixelBuffer.ToArray(); for (var i = 0; i < data.Length; i += 4) { var r = data[i + 2]; var g = data[i + 1]; var b = data[i]; switch (type) { default: case HistogramType.Red: data[i + 2] = (byte)lut[r]; break; case HistogramType.Green: data[i + 1] = (byte)lut[g]; break; case HistogramType.Blue: data[i] = (byte)lut[b]; break; case HistogramType.Average: data[i + 2] = (byte)lut[r]; data[i + 1] = (byte)lut[g]; data[i] = (byte)lut[b]; break; } } var newWb = new WriteableBitmap(wb.PixelWidth, wb.PixelHeight); using (var stream = newWb.PixelBuffer.AsStream()) { await stream.WriteAsync(data, 0, data.Length); } var newImage = new ImageBrush(); newImage.ImageSource = newWb; return(newImage); }