string historgram(int[,] Y, int[] histogram, int[] integration, bool plateHisto, Bitmap bmp, HistogramBounds bounds, out HistoResults results) { int xStart; int xEnd; int yStart; int yEnd; results = new HistoResults(); xStart = bounds.leftEdge; xEnd = bounds.rightEdge; yStart = bounds.topEdge; yEnd = bounds.bottomEdge; int x = 0; int y = 0; int ave = 0; int aveCnt = 0; int sum = 0; for (x = xStart; x < xEnd; x++) { for (y = yStart; y < yEnd; y++) { int val = Y[x, y]; histogram[val]++; ave += val; aveCnt++; } } int area = ave; ave = ave / aveCnt; for (int i = 0; i < histogram.Length; i++) { sum += histogram[i]; integration[i] = sum; } // find where the integration hits 10% of the max area area = integration[integration.Length - 1]; results.darkEnergyThreshold = 0; for (int i = 0; i < histogram.Length; i++) { if ( integration[i] > ( (35 * area) / 100)) { results.darkEnergyThreshold = i; break; } } // get dark moment results.darkPeakCount = 0; int darkMoment = 0; for (int i = 0; i < ave; i++) { if (histogram[i] > results.darkPeakCount) { results.darkPeakCount = histogram[i]; darkMoment = i; } } // get light moment results.lightPeakCount = 0; int lightMoment = 0; for (int i = ave; i < histogram.Count(); i++) { if (histogram[i] > results.lightPeakCount) { results.lightPeakCount = histogram[i]; lightMoment = i; } } // get standard deviation from the median int median = (darkMoment + lightMoment) / 2; float stddev = 0; for (int i = 0; i < histogram.Count(); i++) { stddev += histogram[i] * Math.Abs((ave - i)); } if (area == 0) area = 1; stddev /= area; stddev = stddev * 256; string histString ="stddev = "+stddev.ToString()+ "ave = " + ave.ToString() + ", dark mnt = " + darkMoment.ToString() + ", light mnt = " + lightMoment.ToString(); ; results.ave = ave; results.lightMoment = lightMoment; results.darkMoment = darkMoment; results.stdDev = (int) stddev; Color cl; cl = Color.FromKnownColor(KnownColor.Yellow); plotCurve( bmp, histogram, bmp.Height, 0); plotCurve( bmp, integration, bmp.Height, 0); // draw a line at 1/2 mark plotLine( bmp, bmp.Width / 2, bmp.Width / 2, 0, bmp.Height, cl); plotLine( bmp, bmp.Width / 2 + 1, bmp.Width / 2 + 1, 0, bmp.Height, cl); plotLine( bmp, bmp.Width / 2 + 2, bmp.Width / 2 + 2, 0, bmp.Height, cl); // draw a line at ave int aveX = ave; cl = Color.FromKnownColor(KnownColor.Green); plotLine( bmp, aveX, aveX, 0, bmp.Height - 1, cl); plotLine( bmp, aveX + 1, aveX + 1, 0, bmp.Height - 1, cl); plotLine(bmp, aveX + 2, aveX + 2, 0, bmp.Height - 1, cl); // draw a line at darkEnergyThreshold aveX = results.darkEnergyThreshold; cl = Color.FromKnownColor(KnownColor.Azure); plotLine(bmp, aveX, aveX, 0, bmp.Height - 1, cl); plotLine(bmp, aveX + 1, aveX + 1, 0, bmp.Height - 1, cl); plotLine(bmp, aveX + 2, aveX + 2, 0, bmp.Height - 1, cl); return (histString); }
string historgram(int[,] Y, int[] histogram, int[] integration, bool plateHisto, Bitmap bmp, HistogramBounds bounds, out HistoResults results) { int xStart; int xEnd; int yStart; int yEnd; results = new HistoResults(); xStart = bounds.leftEdge; xEnd = bounds.rightEdge; yStart = bounds.topEdge; yEnd = bounds.bottomEdge; int x = 0; int y = 0; int ave = 0; int aveCnt = 0; int sum = 0; for (x = xStart; x < xEnd; x++) { for (y = yStart; y < yEnd; y++) { int val = Y[x, y]; histogram[val]++; ave += val; aveCnt++; } } int area = ave; ave = ave / aveCnt; for (int i = 0; i < histogram.Length; i++) { sum += histogram[i]; integration[i] = sum; } // find where the integration hits 10% of the max area area = integration[integration.Length - 1]; results.darkEnergyThreshold = 0; for (int i = 0; i < histogram.Length; i++) { if (integration[i] > ((35 * area) / 100)) { results.darkEnergyThreshold = i; break; } } // get dark moment results.darkPeakCount = 0; int darkMoment = 0; for (int i = 0; i < ave; i++) { if (histogram[i] > results.darkPeakCount) { results.darkPeakCount = histogram[i]; darkMoment = i; } } // get light moment results.lightPeakCount = 0; int lightMoment = 0; for (int i = ave; i < histogram.Count(); i++) { if (histogram[i] > results.lightPeakCount) { results.lightPeakCount = histogram[i]; lightMoment = i; } } // get standard deviation from the median int median = (darkMoment + lightMoment) / 2; float stddev = 0; for (int i = 0; i < histogram.Count(); i++) { stddev += histogram[i] * Math.Abs((ave - i)); } if (area == 0) { area = 1; } stddev /= area; stddev = stddev * 256; string histString = "stddev = " + stddev.ToString() + "ave = " + ave.ToString() + ", dark mnt = " + darkMoment.ToString() + ", light mnt = " + lightMoment.ToString();; results.ave = ave; results.lightMoment = lightMoment; results.darkMoment = darkMoment; results.stdDev = (int)stddev; Color cl; cl = Color.FromKnownColor(KnownColor.Yellow); plotCurve(bmp, histogram, bmp.Height, 0); plotCurve(bmp, integration, bmp.Height, 0); // draw a line at 1/2 mark plotLine(bmp, bmp.Width / 2, bmp.Width / 2, 0, bmp.Height, cl); plotLine(bmp, bmp.Width / 2 + 1, bmp.Width / 2 + 1, 0, bmp.Height, cl); plotLine(bmp, bmp.Width / 2 + 2, bmp.Width / 2 + 2, 0, bmp.Height, cl); // draw a line at ave int aveX = ave; cl = Color.FromKnownColor(KnownColor.Green); plotLine(bmp, aveX, aveX, 0, bmp.Height - 1, cl); plotLine(bmp, aveX + 1, aveX + 1, 0, bmp.Height - 1, cl); plotLine(bmp, aveX + 2, aveX + 2, 0, bmp.Height - 1, cl); // draw a line at darkEnergyThreshold aveX = results.darkEnergyThreshold; cl = Color.FromKnownColor(KnownColor.Azure); plotLine(bmp, aveX, aveX, 0, bmp.Height - 1, cl); plotLine(bmp, aveX + 1, aveX + 1, 0, bmp.Height - 1, cl); plotLine(bmp, aveX + 2, aveX + 2, 0, bmp.Height - 1, cl); return(histString); }