public override bool Do() { try { var bReqFullUpdate = !m_isSelfClearOut || (histogramsResults.Count == 0); if (bReqFullUpdate) { histogramsResults.Clear(); } IMovingPredict movingPredict = null; MovingPredictType movingType = (MovingPredictType)EnumPropertys["MovingType"].Value; switch (movingType) { case MovingPredictType.MovingAverage: movingPredict = new MovingAverage(IntPropertys["MovingRange"].Value); break; case MovingPredictType.MovingMediana: movingPredict = new MovingMediana(IntPropertys["MovingRange"].Value); break; default: movingPredict = new MovingAverage(IntPropertys["MovingRange"].Value); break; } int listID = 0; for (int srcID = 0; srcID < Sources.Count; srcID++) { var outDatas = Sources[srcID].GetOut(); for (int dataID = 0; dataID < outDatas.Count; dataID++) { if (bReqFullUpdate) { histogramsResults.Add(RGBHistogram.GetHistograms(outDatas[dataID].Image)); } Mat copy = outDatas[dataID].Image.Clone(); RGBHistogram.DrawChannel(copy, IntPropertys["x_show"].Value, IntPropertys["y_show"].Value, FloatPropertys["scaleX"].Value, FloatPropertys["scaleY"].Value, movingPredict, histogramsResults[listID], 0, new Bgr(0, 0, 255).MCvScalar, new Bgr(50, 0, 255).MCvScalar, false); RGBHistogram.DrawChannel(copy, IntPropertys["x_show"].Value, IntPropertys["y_show"].Value, FloatPropertys["scaleX"].Value, FloatPropertys["scaleY"].Value, movingPredict, histogramsResults[listID], 1, new Bgr(255, 0, 0).MCvScalar, new Bgr(255, 0, 50).MCvScalar, false); RGBHistogram.DrawChannel(copy, IntPropertys["x_show"].Value, IntPropertys["y_show"].Value, FloatPropertys["scaleX"].Value, FloatPropertys["scaleY"].Value, movingPredict, histogramsResults[listID], 2, new Bgr(0, 255, 0).MCvScalar, new Bgr(50, 255, 50).MCvScalar, false); listID++; this.m_out.Add(new DataSrc(copy, outDatas[dataID].Info, false)); } } } catch (Exception ex) { return(false); } return(true); }
public static Bitmap Equalize(this Bitmap OriginalImage, string FileName = "") { OriginalImage.ThrowIfNull("OriginalImage"); ImageFormat FormatUsing = FileName.GetImageFormat(); Bitmap NewBitmap = new Bitmap(OriginalImage.Width, OriginalImage.Height); RGBHistogram TempHistogram = new RGBHistogram(OriginalImage); TempHistogram.Equalize(); BitmapData NewData = NewBitmap.LockImage(); BitmapData OldData = OriginalImage.LockImage(); int NewPixelSize = NewData.GetPixelSize(); int OldPixelSize = OldData.GetPixelSize(); int Width = NewBitmap.Width; int Height = NewBitmap.Height; Parallel.For(0, Width, x => { for (int y = 0; y < Height; ++y) { Color Current = OldData.GetPixel(x, y, OldPixelSize); int NewR = (int)TempHistogram.R[Current.R]; int NewG = (int)TempHistogram.G[Current.G]; int NewB = (int)TempHistogram.B[Current.B]; NewR = NewR.Clamp(255, 0); NewG = NewG.Clamp(255, 0); NewB = NewB.Clamp(255, 0); NewData.SetPixel(x, y, Color.FromArgb(NewR, NewG, NewB), NewPixelSize); } }); NewBitmap.UnlockImage(NewData); OriginalImage.UnlockImage(OldData); if (!string.IsNullOrEmpty(FileName)) NewBitmap.Save(FileName, FormatUsing); return NewBitmap; }