private static Rectangle process(Gray<byte>[,] probabilityMap, Rectangle roi, TermCriteria termCriteria, out CentralMoments centralMoments) { Rectangle imageArea = new Rectangle(0, 0, probabilityMap.Width(), probabilityMap.Height()); Rectangle searchWindow = roi; RawMoments moments = new RawMoments(order: 1); // Mean shift with fixed number of iterations int i = 0; double shift = Byte.MaxValue; while (termCriteria.ShouldTerminate(i, shift) == false && !searchWindow.IsEmptyArea()) { // Locate first order moments moments.Compute(probabilityMap, searchWindow); int shiftX = (int)(moments.CenterX - searchWindow.Width / 2f); int shiftY = (int)(moments.CenterY - searchWindow.Height / 2f); // Shift the mean (centroid) searchWindow.X += shiftX; searchWindow.Y += shiftY; // Keep the search window inside the image searchWindow.Intersect(imageArea); shift = System.Math.Abs((double)shiftX) + System.Math.Abs((double)shiftY); //for term criteria only i++; } if (searchWindow.IsEmptyArea() == false) { // Locate second order moments and perform final shift moments.Order = 2; moments.Compute(probabilityMap, searchWindow); searchWindow.X += (int)(moments.CenterX - searchWindow.Width / 2f); searchWindow.Y += (int)(moments.CenterY - searchWindow.Height / 2f); // Keep the search window inside the image searchWindow.Intersect(imageArea); } centralMoments = new CentralMoments(moments); // moments to be used by camshift return searchWindow; }
internal override void Compute(IImage image) { RawMoments rawMoments = new RawMoments(Order); rawMoments.Compute(image); this.Compute(rawMoments); }
/// <summary> /// Computes moments for the provided image. /// </summary> /// <param name="image">Image.</param> /// <param name="area">Area</param> public void Compute(Gray <float>[,] image, Rectangle area) { RawMoments rawMoments = new RawMoments(Order); rawMoments.Compute(image, area); this.Compute(rawMoments); }
/// <summary> /// Computes moments for the provided image. /// </summary> /// <param name="image">Image.</param> /// <param name="area">Area</param> public void Compute(Gray <float>[,] image, Rectangle area) { RawMoments raw = new RawMoments(Order); raw.Compute(image, area); CentralMoments center = new CentralMoments(raw); this.Compute(center); }
/// <summary> /// Computes the center moments from the specified raw moments. /// </summary> /// /// <param name="moments">The raw moments to use as base of calculations.</param> /// public void Compute(RawMoments moments) { float x = moments.CenterX; float y = moments.CenterY; Mu00 = moments.M00; Mu01 = Mu10 = 0; Mu11 = moments.M11 - moments.M01 * x; Mu20 = moments.M20 - moments.M10 * x; Mu02 = moments.M02 - moments.M01 * y; Mu21 = moments.M21 - 2 * x * moments.M11 - y * moments.M20 + 2 * x * x * moments.M01; Mu12 = moments.M12 - 2 * y * moments.M11 - x * moments.M02 + 2 * y * y * moments.M10; Mu30 = moments.M30 - 3 * x * moments.M20 + 2 * x * x * moments.M10; Mu03 = moments.M03 - 3 * y * moments.M02 + 2 * y * y * moments.M01; invM00 = moments.InvM00; }
/// <summary> /// Initializes a new instance of the <see cref="CentralMoments"/> class. /// </summary> /// /// <param name="moments">The raw moments to construct central moments.</param> /// public CentralMoments(RawMoments moments) : base(moments.Order) { Compute(moments); }
/// <summary> /// Computes moments for the provided image. /// </summary> /// <param name="image">Image.</param> /// <param name="area">Area</param> public void Compute(Gray<float>[,] image, Rectangle area) { RawMoments raw = new RawMoments(Order); raw.Compute(image, area); CentralMoments center = new CentralMoments(raw); this.Compute(center); }
/// <summary> /// Computes moments for the provided image. /// </summary> /// <param name="image">Image.</param> /// <param name="area">Area</param> public void Compute(Gray<float>[,] image, Rectangle area) { RawMoments rawMoments = new RawMoments(Order); rawMoments.Compute(image, area); this.Compute(rawMoments); }