/// <summary> /// Build a bitmap from an error historgram /// </summary> /// <param name="data">the error histogram</param> /// <param name="height">the heigh of the bitmap to be created</param> /// <returns></returns> internal static Bitmap getBmpFromErrHist(float[] data, int height) { Bitmap bmp = new Bitmap(1, 1); if (data != null) { bmp = new Bitmap(data.Length, height); Graphics grp = Graphics.FromImage(bmp); grp.FillRectangle(Brushes.Black, 0, 0, bmp.Width, bmp.Height); data[0] = 0; // reset 0 as it does not count for the error float [] minmax = IPUtil.GetBounds(data); Pen dpen = new Pen(Color.FromArgb(200, 100, 200, 0)); for (int j = 0; j < data.Length; j++) { int nbc = (int)(height * data[j] / minmax[1]); if (nbc == 0 && data[j] != 0) { nbc = 1; } grp.DrawLine(dpen, j, height, j, height - nbc); } // draw % max of pixels in error grp.DrawString((100 * minmax[1]).ToString(), new Font("arial", 8.0f), new SolidBrush(Color.FromArgb(200, 255, 255, 0)), 10, 10); grp.Dispose(); } return(bmp); }
/// <summary> /// Build an histogram based on a multidimentinal array (2 or 3) /// </summary> /// <param name="tval">the multidimentional array containing the data</param> /// <returns>an array of float representing the histogram</returns> internal static float[] getFHistogram(object tval) { float[] hist = new float[256]; float [,] data = tval as float[, ]; if (data != null) { int w = data.GetUpperBound(0); int h = data.GetUpperBound(1); float [] bd = IPUtil.GetBounds(data); Console.WriteLine("miinimaxx " + bd[0] + " " + bd[1]); bd[1] = 2000; bd[1] -= bd[0]; for (int i = 0; i < w; i++) { for (int j = 0; j < h; j++) { int idx = (int)(255.0 * (data[i, j] - bd[0]) / bd[1]); if (idx > 255) { idx = 255; } if (idx < 0) { idx = 9; } hist[idx] += 1.0f; } } float nbp = w * h; for (int j = 0; j < hist.Length; j++) { hist[j] /= nbp; } } float [,,] ddata = tval as float[, , ]; if (ddata != null) { int w = ddata.GetUpperBound(1); int h = ddata.GetUpperBound(2); float [] bd = IPUtil.GetBounds(ddata); for (int i = 0; i < w; i++) { for (int j = 0; j < h; j++) { float val = RGBfloat2Yfloat(ddata[0, i, j], ddata[1, i, j], ddata[2, i, j]); int idx = (int)(255.0 * (val - bd[0]) / bd[1]); if (idx > 255) { idx = 255; } if (idx < 0) { idx = 9; } hist[idx] += 1.0f; } } float nbp = w * h; for (int j = 0; j < hist.Length; j++) { hist[j] /= nbp; } } mHist.Add(hist); return(hist); }