Accord.Imaging.Moments.CentralMoments.GetSize C# (CSharp) Method

GetSize() public method

Gets the size of the ellipse containing the image.
public GetSize ( ) : SizeF
return System.Drawing.SizeF
        public SizeF GetSize()
        {
            // Compute the covariance matrix
            //
            double a = Mu20 * invM00; //                | a    b |
            double b = Mu11 * invM00; //  Cov[I(x,y)] = |        |
            double c = Mu02 * invM00; //                | b    c |

            double d = a + c, e = a - c;
            double s = Math.Sqrt((4.0 * b * b) + (e * e));

            // Compute size
            return new SizeF((float)Math.Sqrt((d - s) * 0.5) * 4,
                             (float)Math.Sqrt((d + s) * 0.5) * 4);
        }

Usage Example

        public void ComputeTest()
        {
            Bitmap image = Resources.hu;

            CentralMoments target = new CentralMoments(image, order: 3);

            Assert.AreEqual(86424.0 / target.Mu00, 1);
            Assert.AreEqual(0, target.Mu01);
            Assert.AreEqual(0, target.Mu10);
            Assert.AreEqual(5.868206472635379E8 / target.Mu02, 1, 1e-2);

            Assert.AreEqual(6348920.945848465 / target.Mu11, 1, 1e-2);
            Assert.AreEqual(9.084235762166061E8 / target.Mu20, 1, 1e-3);

            Assert.AreEqual(-2.155191E9 / target.Mu12, 1, 1e-5);
            Assert.AreEqual(7.125893E8 / target.Mu21, 1, 1e-3);

            Assert.AreEqual(-1.26244547E10 / target.Mu30, 1, 1e-8);
            Assert.AreEqual(1.71818829E9 / target.Mu03, 1, 1e-8);

            SizeF size = target.GetSize();
            float angle = target.GetOrientation();

            Assert.AreEqual(410.207916f, size.Height);
            Assert.AreEqual(329.534637f, size.Width);
            Assert.AreEqual(0.0196384024f, angle);
        }