1 /*M///////////////////////////////////////////////////////////////////////////////////////
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
5 // By downloading, copying, installing or using the software you agree to this license.
6 // If you do not agree to this license, do not download, install,
7 // copy or use the software.
10 // Intel License Agreement
11 // For Open Source Computer Vision Library
13 // Copyright (C) 2000, Intel Corporation, all rights reserved.
14 // Third party copyrights are property of their respective owners.
16 // Redistribution and use in source and binary forms, with or without modification,
17 // are permitted provided that the following conditions are met:
19 // * Redistribution's of source code must retain the above copyright notice,
20 // this list of conditions and the following disclaimer.
22 // * Redistribution's in binary form must reproduce the above copyright notice,
23 // this list of conditions and the following disclaimer in the documentation
24 // and/or other materials provided with the distribution.
26 // * The name of Intel Corporation may not be used to endorse or promote products
27 // derived from this software without specific prior written permission.
29 // This software is provided by the copyright holders and contributors "as is" and
30 // any express or implied warranties, including, but not limited to, the implied
31 // warranties of merchantability and fitness for a particular purpose are disclaimed.
32 // In no event shall the Intel Corporation or contributors be liable for any direct,
33 // indirect, incidental, special, exemplary, or consequential damages
34 // (including, but not limited to, procurement of substitute goods or services;
35 // loss of use, data, or profits; or business interruption) however caused
36 // and on any theory of liability, whether in contract, strict liability,
37 // or tort (including negligence or otherwise) arising in any way out of
38 // the use of this software, even if advised of the possibility of such damage.
41 #include "precomp.hpp"
42 #include "opencl_kernels.hpp"
47 // The function calculates center of gravity and the central second order moments
48 static void completeMomentState( Moments* moments )
50 double cx = 0, cy = 0;
51 double mu20, mu11, mu02;
53 assert( moments != 0 );
55 if( fabs(moments->m00) > DBL_EPSILON )
57 inv_m00 = 1. / moments->m00;
58 cx = moments->m10 * inv_m00;
59 cy = moments->m01 * inv_m00;
62 // mu20 = m20 - m10*cx
63 mu20 = moments->m20 - moments->m10 * cx;
64 // mu11 = m11 - m10*cy
65 mu11 = moments->m11 - moments->m10 * cy;
66 // mu02 = m02 - m01*cy
67 mu02 = moments->m02 - moments->m01 * cy;
73 // mu30 = m30 - cx*(3*mu20 + cx*m10)
74 moments->mu30 = moments->m30 - cx * (3 * mu20 + cx * moments->m10);
76 // mu21 = m21 - cx*(2*mu11 + cx*m01) - cy*mu20
77 moments->mu21 = moments->m21 - cx * (mu11 + cx * moments->m01) - cy * mu20;
78 // mu12 = m12 - cy*(2*mu11 + cy*m10) - cx*mu02
79 moments->mu12 = moments->m12 - cy * (mu11 + cy * moments->m10) - cx * mu02;
80 // mu03 = m03 - cy*(3*mu02 + cy*m01)
81 moments->mu03 = moments->m03 - cy * (3 * mu02 + cy * moments->m01);
84 double inv_sqrt_m00 = std::sqrt(std::abs(inv_m00));
85 double s2 = inv_m00*inv_m00, s3 = s2*inv_sqrt_m00;
87 moments->nu20 = moments->mu20*s2; moments->nu11 = moments->mu11*s2; moments->nu02 = moments->mu02*s2;
88 moments->nu30 = moments->mu30*s3; moments->nu21 = moments->mu21*s3; moments->nu12 = moments->mu12*s3; moments->nu03 = moments->mu03*s3;
93 static Moments contourMoments( const Mat& contour )
96 int lpt = contour.checkVector(2);
97 int is_float = contour.depth() == CV_32F;
98 const Point* ptsi = (const Point*)contour.data;
99 const Point2f* ptsf = (const Point2f*)contour.data;
101 CV_Assert( contour.depth() == CV_32S || contour.depth() == CV_32F );
106 double a00 = 0, a10 = 0, a01 = 0, a20 = 0, a11 = 0, a02 = 0, a30 = 0, a21 = 0, a12 = 0, a03 = 0;
107 double xi, yi, xi2, yi2, xi_1, yi_1, xi_12, yi_12, dxy, xii_1, yii_1;
111 xi_1 = ptsi[lpt-1].x;
112 yi_1 = ptsi[lpt-1].y;
116 xi_1 = ptsf[lpt-1].x;
117 yi_1 = ptsf[lpt-1].y;
123 for( int i = 0; i < lpt; i++ )
138 dxy = xi_1 * yi - xi * yi_1;
145 a20 += dxy * (xi_1 * xii_1 + xi2);
146 a11 += dxy * (xi_1 * (yii_1 + yi_1) + xi * (yii_1 + yi));
147 a02 += dxy * (yi_1 * yii_1 + yi2);
148 a30 += dxy * xii_1 * (xi_12 + xi2);
149 a03 += dxy * yii_1 * (yi_12 + yi2);
150 a21 += dxy * (xi_12 * (3 * yi_1 + yi) + 2 * xi * xi_1 * yii_1 +
151 xi2 * (yi_1 + 3 * yi));
152 a12 += dxy * (yi_12 * (3 * xi_1 + xi) + 2 * yi * yi_1 * xii_1 +
153 yi2 * (xi_1 + 3 * xi));
160 if( fabs(a00) > FLT_EPSILON )
162 double db1_2, db1_6, db1_12, db1_24, db1_20, db1_60;
167 db1_6 = 0.16666666666666666666666666666667;
168 db1_12 = 0.083333333333333333333333333333333;
169 db1_24 = 0.041666666666666666666666666666667;
171 db1_60 = 0.016666666666666666666666666666667;
176 db1_6 = -0.16666666666666666666666666666667;
177 db1_12 = -0.083333333333333333333333333333333;
178 db1_24 = -0.041666666666666666666666666666667;
180 db1_60 = -0.016666666666666666666666666666667;
187 m.m20 = a20 * db1_12;
188 m.m11 = a11 * db1_24;
189 m.m02 = a02 * db1_12;
190 m.m30 = a30 * db1_20;
191 m.m21 = a21 * db1_60;
192 m.m12 = a12 * db1_60;
193 m.m03 = a03 * db1_20;
195 completeMomentState( &m );
201 /****************************************************************************************\
202 * Spatial Raster Moments *
203 \****************************************************************************************/
205 template<typename T, typename WT, typename MT>
206 #if defined __GNUC__ && __GNUC__ == 4 && __GNUC_MINOR__ >= 5 && __GNUC_MINOR__ < 9
207 // Workaround for http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60196
208 __attribute__((optimize("no-tree-vectorize")))
210 static void momentsInTile( const Mat& img, double* moments )
212 Size size = img.size();
214 MT mom[10] = {0,0,0,0,0,0,0,0,0,0};
216 for( y = 0; y < size.height; y++ )
218 const T* ptr = (const T*)(img.data + y*img.step);
219 WT x0 = 0, x1 = 0, x2 = 0;
222 for( x = 0; x < size.width; x++ )
234 WT py = y * x0, sy = y*y;
236 mom[9] += ((MT)py) * sy; // m03
237 mom[8] += ((MT)x1) * sy; // m12
238 mom[7] += ((MT)x2) * y; // m21
240 mom[5] += x0 * sy; // m02
241 mom[4] += x1 * y; // m11
248 for( x = 0; x < 10; x++ )
249 moments[x] = (double)mom[x];
255 template<> void momentsInTile<uchar, int, int>( const cv::Mat& img, double* moments )
260 Size size = img.size();
262 MT mom[10] = {0,0,0,0,0,0,0,0,0,0};
263 bool useSIMD = checkHardwareSupport(CV_CPU_SSE2);
265 for( y = 0; y < size.height; y++ )
267 const T* ptr = img.ptr<T>(y);
268 int x0 = 0, x1 = 0, x2 = 0, x3 = 0, x = 0;
272 __m128i qx_init = _mm_setr_epi16(0, 1, 2, 3, 4, 5, 6, 7);
273 __m128i dx = _mm_set1_epi16(8);
274 __m128i z = _mm_setzero_si128(), qx0 = z, qx1 = z, qx2 = z, qx3 = z, qx = qx_init;
276 for( ; x <= size.width - 8; x += 8 )
278 __m128i p = _mm_unpacklo_epi8(_mm_loadl_epi64((const __m128i*)(ptr + x)), z);
279 qx0 = _mm_add_epi32(qx0, _mm_sad_epu8(p, z));
280 __m128i px = _mm_mullo_epi16(p, qx);
281 __m128i sx = _mm_mullo_epi16(qx, qx);
282 qx1 = _mm_add_epi32(qx1, _mm_madd_epi16(p, qx));
283 qx2 = _mm_add_epi32(qx2, _mm_madd_epi16(p, sx));
284 qx3 = _mm_add_epi32(qx3, _mm_madd_epi16(px, sx));
286 qx = _mm_add_epi16(qx, dx);
288 int CV_DECL_ALIGNED(16) buf[4];
289 _mm_store_si128((__m128i*)buf, qx0);
290 x0 = buf[0] + buf[1] + buf[2] + buf[3];
291 _mm_store_si128((__m128i*)buf, qx1);
292 x1 = buf[0] + buf[1] + buf[2] + buf[3];
293 _mm_store_si128((__m128i*)buf, qx2);
294 x2 = buf[0] + buf[1] + buf[2] + buf[3];
295 _mm_store_si128((__m128i*)buf, qx3);
296 x3 = buf[0] + buf[1] + buf[2] + buf[3];
299 for( ; x < size.width; x++ )
311 WT py = y * x0, sy = y*y;
313 mom[9] += ((MT)py) * sy; // m03
314 mom[8] += ((MT)x1) * sy; // m12
315 mom[7] += ((MT)x2) * y; // m21
317 mom[5] += x0 * sy; // m02
318 mom[4] += x1 * y; // m11
325 for(int x = 0; x < 10; x++ )
326 moments[x] = (double)mom[x];
331 typedef void (*MomentsInTileFunc)(const Mat& img, double* moments);
335 m00 = m10 = m01 = m20 = m11 = m02 = m30 = m21 = m12 = m03 =
336 mu20 = mu11 = mu02 = mu30 = mu21 = mu12 = mu03 =
337 nu20 = nu11 = nu02 = nu30 = nu21 = nu12 = nu03 = 0.;
340 Moments::Moments( double _m00, double _m10, double _m01, double _m20, double _m11,
341 double _m02, double _m30, double _m21, double _m12, double _m03 )
343 m00 = _m00; m10 = _m10; m01 = _m01;
344 m20 = _m20; m11 = _m11; m02 = _m02;
345 m30 = _m30; m21 = _m21; m12 = _m12; m03 = _m03;
347 double cx = 0, cy = 0, inv_m00 = 0;
348 if( std::abs(m00) > DBL_EPSILON )
351 cx = m10*inv_m00; cy = m01*inv_m00;
358 mu30 = m30 - cx*(3*mu20 + cx*m10);
359 mu21 = m21 - cx*(2*mu11 + cx*m01) - cy*mu20;
360 mu12 = m12 - cy*(2*mu11 + cy*m10) - cx*mu02;
361 mu03 = m03 - cy*(3*mu02 + cy*m01);
363 double inv_sqrt_m00 = std::sqrt(std::abs(inv_m00));
364 double s2 = inv_m00*inv_m00, s3 = s2*inv_sqrt_m00;
366 nu20 = mu20*s2; nu11 = mu11*s2; nu02 = mu02*s2;
367 nu30 = mu30*s3; nu21 = mu21*s3; nu12 = mu12*s3; nu03 = mu03*s3;
372 static bool ocl_moments( InputArray _src, Moments& m, bool binary)
374 const int TILE_SIZE = 32;
377 ocl::Kernel k = ocl::Kernel("moments", ocl::imgproc::moments_oclsrc,
378 format("-D TILE_SIZE=%d%s",
380 binary ? " -D OP_MOMENTS_BINARY" : ""));
385 UMat src = _src.getUMat();
386 Size sz = src.size();
387 int xtiles = (sz.width + TILE_SIZE-1)/TILE_SIZE;
388 int ytiles = (sz.height + TILE_SIZE-1)/TILE_SIZE;
389 int ntiles = xtiles*ytiles;
390 UMat umbuf(1, ntiles*K, CV_32S);
392 size_t globalsize[] = {xtiles, sz.height}, localsize[] = {1, TILE_SIZE};
393 bool ok = k.args(ocl::KernelArg::ReadOnly(src),
394 ocl::KernelArg::PtrWriteOnly(umbuf),
395 xtiles).run(2, globalsize, localsize, true);
398 Mat mbuf = umbuf.getMat(ACCESS_READ);
399 for( int i = 0; i < ntiles; i++ )
401 double x = (i % xtiles)*TILE_SIZE, y = (i / xtiles)*TILE_SIZE;
402 const int* mom = mbuf.ptr<int>() + i*K;
403 double xm = x * mom[0], ym = y * mom[0];
405 // accumulate moments computed in each tile
410 // + m10 ( = m10' + x*m00' )
411 m.m10 += mom[1] + xm;
413 // + m01 ( = m01' + y*m00' )
414 m.m01 += mom[2] + ym;
416 // + m20 ( = m20' + 2*x*m10' + x*x*m00' )
417 m.m20 += mom[3] + x * (mom[1] * 2 + xm);
419 // + m11 ( = m11' + x*m01' + y*m10' + x*y*m00' )
420 m.m11 += mom[4] + x * (mom[2] + ym) + y * mom[1];
422 // + m02 ( = m02' + 2*y*m01' + y*y*m00' )
423 m.m02 += mom[5] + y * (mom[2] * 2 + ym);
425 // + m30 ( = m30' + 3*x*m20' + 3*x*x*m10' + x*x*x*m00' )
426 m.m30 += mom[6] + x * (3. * mom[3] + x * (3. * mom[1] + xm));
428 // + m21 ( = m21' + x*(2*m11' + 2*y*m10' + x*m01' + x*y*m00') + y*m20')
429 m.m21 += mom[7] + x * (2 * (mom[4] + y * mom[1]) + x * (mom[2] + ym)) + y * mom[3];
431 // + m12 ( = m12' + y*(2*m11' + 2*x*m01' + y*m10' + x*y*m00') + x*m02')
432 m.m12 += mom[8] + y * (2 * (mom[4] + x * mom[2]) + y * (mom[1] + xm)) + x * mom[5];
434 // + m03 ( = m03' + 3*y*m02' + 3*y*y*m01' + y*y*y*m00' )
435 m.m03 += mom[9] + y * (3. * mom[5] + y * (3. * mom[2] + ym));
446 cv::Moments cv::moments( InputArray _src, bool binary )
448 const int TILE_SIZE = 32;
449 MomentsInTileFunc func = 0;
450 uchar nzbuf[TILE_SIZE*TILE_SIZE];
452 int type = _src.type(), depth = CV_MAT_DEPTH(type), cn = CV_MAT_CN(type);
453 Size size = _src.size();
455 if( size.width <= 0 || size.height <= 0 )
459 if( !(ocl::useOpenCL() && type == CV_8UC1 &&
460 _src.isUMat() && ocl_moments(_src, m, binary)) )
463 Mat mat = _src.getMat();
464 if( mat.checkVector(2) >= 0 && (depth == CV_32F || depth == CV_32S))
465 return contourMoments(mat);
468 CV_Error( CV_StsBadArg, "Invalid image type (must be single-channel)" );
470 #if IPP_VERSION_X100 >= 801 && 0
473 IppiSize roi = { mat.cols, mat.rows };
474 IppiMomentState_64f * moment = NULL;
475 // ippiMomentInitAlloc_64f, ippiMomentFree_64f are deprecated in 8.1, but there are not another way
476 // to initialize IppiMomentState_64f. When GetStateSize and Init functions will appear we have to
478 CV_SUPPRESS_DEPRECATED_START
479 if (ippiMomentInitAlloc_64f(&moment, ippAlgHintAccurate) >= 0)
481 typedef IppStatus (CV_STDCALL * ippiMoments)(const void * pSrc, int srcStep, IppiSize roiSize, IppiMomentState_64f* pCtx);
482 ippiMoments ippFunc =
483 type == CV_8UC1 ? (ippiMoments)ippiMoments64f_8u_C1R :
484 type == CV_16UC1 ? (ippiMoments)ippiMoments64f_16u_C1R :
485 type == CV_32FC1? (ippiMoments)ippiMoments64f_32f_C1R : 0;
489 if (ippFunc(mat.data, (int)mat.step, roi, moment) >= 0)
491 IppiPoint point = { 0, 0 };
492 ippiGetSpatialMoment_64f(moment, 0, 0, 0, point, &m.m00);
493 ippiGetSpatialMoment_64f(moment, 1, 0, 0, point, &m.m10);
494 ippiGetSpatialMoment_64f(moment, 0, 1, 0, point, &m.m01);
496 ippiGetSpatialMoment_64f(moment, 2, 0, 0, point, &m.m20);
497 ippiGetSpatialMoment_64f(moment, 1, 1, 0, point, &m.m11);
498 ippiGetSpatialMoment_64f(moment, 0, 2, 0, point, &m.m02);
500 ippiGetSpatialMoment_64f(moment, 3, 0, 0, point, &m.m30);
501 ippiGetSpatialMoment_64f(moment, 2, 1, 0, point, &m.m21);
502 ippiGetSpatialMoment_64f(moment, 1, 2, 0, point, &m.m12);
503 ippiGetSpatialMoment_64f(moment, 0, 3, 0, point, &m.m03);
504 ippiGetCentralMoment_64f(moment, 2, 0, 0, &m.mu20);
505 ippiGetCentralMoment_64f(moment, 1, 1, 0, &m.mu11);
506 ippiGetCentralMoment_64f(moment, 0, 2, 0, &m.mu02);
507 ippiGetCentralMoment_64f(moment, 3, 0, 0, &m.mu30);
508 ippiGetCentralMoment_64f(moment, 2, 1, 0, &m.mu21);
509 ippiGetCentralMoment_64f(moment, 1, 2, 0, &m.mu12);
510 ippiGetCentralMoment_64f(moment, 0, 3, 0, &m.mu03);
511 ippiGetNormalizedCentralMoment_64f(moment, 2, 0, 0, &m.nu20);
512 ippiGetNormalizedCentralMoment_64f(moment, 1, 1, 0, &m.nu11);
513 ippiGetNormalizedCentralMoment_64f(moment, 0, 2, 0, &m.nu02);
514 ippiGetNormalizedCentralMoment_64f(moment, 3, 0, 0, &m.nu30);
515 ippiGetNormalizedCentralMoment_64f(moment, 2, 1, 0, &m.nu21);
516 ippiGetNormalizedCentralMoment_64f(moment, 1, 2, 0, &m.nu12);
517 ippiGetNormalizedCentralMoment_64f(moment, 0, 3, 0, &m.nu03);
519 ippiMomentFree_64f(moment);
524 ippiMomentFree_64f(moment);
528 CV_SUPPRESS_DEPRECATED_END
532 if( binary || depth == CV_8U )
533 func = momentsInTile<uchar, int, int>;
534 else if( depth == CV_16U )
535 func = momentsInTile<ushort, int, int64>;
536 else if( depth == CV_16S )
537 func = momentsInTile<short, int, int64>;
538 else if( depth == CV_32F )
539 func = momentsInTile<float, double, double>;
540 else if( depth == CV_64F )
541 func = momentsInTile<double, double, double>;
543 CV_Error( CV_StsUnsupportedFormat, "" );
547 for( int y = 0; y < size.height; y += TILE_SIZE )
550 tileSize.height = std::min(TILE_SIZE, size.height - y);
552 for( int x = 0; x < size.width; x += TILE_SIZE )
554 tileSize.width = std::min(TILE_SIZE, size.width - x);
555 Mat src(src0, cv::Rect(x, y, tileSize.width, tileSize.height));
559 cv::Mat tmp(tileSize, CV_8U, nzbuf);
560 cv::compare( src, 0, tmp, CV_CMP_NE );
570 for( int k = 0; k < 10; k++ )
574 double xm = x * mom[0], ym = y * mom[0];
576 // accumulate moments computed in each tile
581 // + m10 ( = m10' + x*m00' )
582 m.m10 += mom[1] + xm;
584 // + m01 ( = m01' + y*m00' )
585 m.m01 += mom[2] + ym;
587 // + m20 ( = m20' + 2*x*m10' + x*x*m00' )
588 m.m20 += mom[3] + x * (mom[1] * 2 + xm);
590 // + m11 ( = m11' + x*m01' + y*m10' + x*y*m00' )
591 m.m11 += mom[4] + x * (mom[2] + ym) + y * mom[1];
593 // + m02 ( = m02' + 2*y*m01' + y*y*m00' )
594 m.m02 += mom[5] + y * (mom[2] * 2 + ym);
596 // + m30 ( = m30' + 3*x*m20' + 3*x*x*m10' + x*x*x*m00' )
597 m.m30 += mom[6] + x * (3. * mom[3] + x * (3. * mom[1] + xm));
599 // + m21 ( = m21' + x*(2*m11' + 2*y*m10' + x*m01' + x*y*m00') + y*m20')
600 m.m21 += mom[7] + x * (2 * (mom[4] + y * mom[1]) + x * (mom[2] + ym)) + y * mom[3];
602 // + m12 ( = m12' + y*(2*m11' + 2*x*m01' + y*m10' + x*y*m00') + x*m02')
603 m.m12 += mom[8] + y * (2 * (mom[4] + x * mom[2]) + y * (mom[1] + xm)) + x * mom[5];
605 // + m03 ( = m03' + 3*y*m02' + 3*y*y*m01' + y*y*y*m00' )
606 m.m03 += mom[9] + y * (3. * mom[5] + y * (3. * mom[2] + ym));
611 completeMomentState( &m );
616 void cv::HuMoments( const Moments& m, double hu[7] )
618 double t0 = m.nu30 + m.nu12;
619 double t1 = m.nu21 + m.nu03;
621 double q0 = t0 * t0, q1 = t1 * t1;
623 double n4 = 4 * m.nu11;
624 double s = m.nu20 + m.nu02;
625 double d = m.nu20 - m.nu02;
628 hu[1] = d * d + n4 * m.nu11;
630 hu[5] = d * (q0 - q1) + n4 * t0 * t1;
635 q0 = m.nu30 - 3 * m.nu12;
636 q1 = 3 * m.nu21 - m.nu03;
638 hu[2] = q0 * q0 + q1 * q1;
639 hu[4] = q0 * t0 + q1 * t1;
640 hu[6] = q1 * t0 - q0 * t1;
643 void cv::HuMoments( const Moments& m, OutputArray _hu )
645 _hu.create(7, 1, CV_64F);
646 Mat hu = _hu.getMat();
647 CV_Assert( hu.isContinuous() );
648 HuMoments(m, (double*)hu.data);
652 CV_IMPL void cvMoments( const CvArr* arr, CvMoments* moments, int binary )
654 const IplImage* img = (const IplImage*)arr;
656 if( CV_IS_IMAGE(arr) && img->roi && img->roi->coi > 0 )
657 cv::extractImageCOI(arr, src, img->roi->coi-1);
659 src = cv::cvarrToMat(arr);
660 cv::Moments m = cv::moments(src, binary != 0);
661 CV_Assert( moments != 0 );
666 CV_IMPL double cvGetSpatialMoment( CvMoments * moments, int x_order, int y_order )
668 int order = x_order + y_order;
671 CV_Error( CV_StsNullPtr, "" );
672 if( (x_order | y_order) < 0 || order > 3 )
673 CV_Error( CV_StsOutOfRange, "" );
675 return (&(moments->m00))[order + (order >> 1) + (order > 2) * 2 + y_order];
679 CV_IMPL double cvGetCentralMoment( CvMoments * moments, int x_order, int y_order )
681 int order = x_order + y_order;
684 CV_Error( CV_StsNullPtr, "" );
685 if( (x_order | y_order) < 0 || order > 3 )
686 CV_Error( CV_StsOutOfRange, "" );
688 return order >= 2 ? (&(moments->m00))[4 + order * 3 + y_order] :
689 order == 0 ? moments->m00 : 0;
693 CV_IMPL double cvGetNormalizedCentralMoment( CvMoments * moments, int x_order, int y_order )
695 int order = x_order + y_order;
697 double mu = cvGetCentralMoment( moments, x_order, y_order );
698 double m00s = moments->inv_sqrt_m00;
700 while( --order >= 0 )
702 return mu * m00s * m00s;
706 CV_IMPL void cvGetHuMoments( CvMoments * mState, CvHuMoments * HuState )
708 if( !mState || !HuState )
709 CV_Error( CV_StsNullPtr, "" );
711 double m00s = mState->inv_sqrt_m00, m00 = m00s * m00s, s2 = m00 * m00, s3 = s2 * m00s;
713 double nu20 = mState->mu20 * s2,
714 nu11 = mState->mu11 * s2,
715 nu02 = mState->mu02 * s2,
716 nu30 = mState->mu30 * s3,
717 nu21 = mState->mu21 * s3, nu12 = mState->mu12 * s3, nu03 = mState->mu03 * s3;
719 double t0 = nu30 + nu12;
720 double t1 = nu21 + nu03;
722 double q0 = t0 * t0, q1 = t1 * t1;
724 double n4 = 4 * nu11;
725 double s = nu20 + nu02;
726 double d = nu20 - nu02;
729 HuState->hu2 = d * d + n4 * nu11;
730 HuState->hu4 = q0 + q1;
731 HuState->hu6 = d * (q0 - q1) + n4 * t0 * t1;
736 q0 = nu30 - 3 * nu12;
737 q1 = 3 * nu21 - nu03;
739 HuState->hu3 = q0 * q0 + q1 * q1;
740 HuState->hu5 = q0 * t0 + q1 * t1;
741 HuState->hu7 = q1 * t0 - q0 * t1;