Ejemplo n.º 1
0
        /// <summary>
        ///   Computes the center moments for the specified image.
        /// </summary>
        ///
        /// <param name="image">The image whose moments should be computed.</param>
        /// <param name="area">The region of interest in the image to compute moments for.</param>
        ///
        public override void Compute(float[,] image, Rectangle area)
        {
            RawMoments     raw    = new RawMoments(image, area, Order);
            CentralMoments center = new CentralMoments(raw);

            this.Compute(center);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///   Computes the Hu moments from the specified central moments.
        /// </summary>
        ///
        /// <param name="moments">The central moments to use as base of calculations.</param>
        ///
        public void Compute(CentralMoments moments)
        {
            double inv    = 1.0 / moments.Mu00;
            double inv2   = 1.0 / (moments.Mu00 * moments.Mu00);
            double inv5d2 = Math.Sqrt(inv2 * inv2 * inv);


            float n20 = (float)(moments.Mu20 * inv2);
            float n02 = (float)(moments.Mu02 * inv2);
            float n11 = (float)(moments.Mu11 * inv2);

            float n21 = (float)(moments.Mu21 * inv5d2);
            float n12 = (float)(moments.Mu12 * inv5d2);
            float n30 = (float)(moments.Mu30 * inv5d2);
            float n03 = (float)(moments.Mu03 * inv5d2);


            //   (η20 + η02)
            I1 = (n20 + n02);


            //   (η20 − η02)²              + 4    η11²
            I2 = (n20 - n02) * (n20 - n02) + 4 * (n11 * n11);


            //   (η30 − 3   η12)²
            I3 = (n30 - 3 * n12) * (n30 - 3 * n12)

                 // + (3   η21 − η03)²
                 + (3 * n21 - n03) * (3 * n21 - n03);


            //   (η30 + η12)²              + (η21 + η03)²
            I4 = (n30 + n12) * (n30 + n12) + (n21 + n03) * (n21 + n03);


            //   (η30 − 3   η12)   (η30 + η12)   [(η30 + η12)²               −3   (η21 + η03)²             ]
            I5 = (n30 - 3 * n12) * (n30 + n12) * ((n30 + n12) * (n30 + n12) - 3 * (n21 + n03) * (n21 + n03))

                 //   (3   η21 − η03)   (η21 + η03)   [3   (η30 + η12)²              − (η21 + η03)²             ]
                 + (3 * n21 - n03) * (n21 + n03) * (3 * (n30 + n12) * (n30 + n12) - (n21 + n03) * (n21 + n03));


            //   (η20 − η02)   [(η30 + η12)²              − (η21 + η03)²             ]
            I6 = (n20 - n02) * ((n30 + n12) * (n30 + n12) - (n21 + n03) * (n21 + n03))

                 //  + 4   η11   (η30 + η12)   (η21 + η03)
                 + 4 * n11 * (n30 + n12) * (n21 + n03);


            //   (3   η21 − η03)   (η30 + η12)                 [(η30 + η12)²              − 3   (η21 + η03)²             ]
            I7 = (3 * n21 - n03) * (n30 + n12) * (n30 + n12) * ((n30 + n12) * (n30 + n12) - 3 * (n21 + n03) * (n21 + n03))

                 // - (η30 − 3   η12)   (η21 + η03)   [3   (η30 + η12)²              − (η21 + η03)²             ]
                 - (n30 - 3 * n12) * (n21 + n03) * (3 * (n30 + n12) * (n30 + n12) - (n21 + n03) * (n21 + n03));
        }