MCPcopy Create free account
hub / github.com/creatale/node-dv / cvNormalizeHist

Function cvNormalizeHist

deps/opencv/modules/imgproc/src/histogram.cpp:2289–2329  ·  view source on GitHub ↗

Normalizes histogram (make sum of the histogram bins == factor)

Source from the content-addressed store, hash-verified

2287
2288// Normalizes histogram (make sum of the histogram bins == factor)
2289CV_IMPL void
2290cvNormalizeHist( CvHistogram* hist, double factor )
2291{
2292 double sum = 0;
2293
2294 if( !CV_IS_HIST(hist) )
2295 CV_Error( CV_StsBadArg, "Invalid histogram header" );
2296
2297 if( !CV_IS_SPARSE_HIST(hist) )
2298 {
2299 CvMat mat;
2300 cvGetMat( hist->bins, &mat, 0, 1 );
2301 sum = cvSum( &mat ).val[0];
2302 if( fabs(sum) < DBL_EPSILON )
2303 sum = 1;
2304 cvScale( &mat, &mat, factor/sum, 0 );
2305 }
2306 else
2307 {
2308 CvSparseMat* mat = (CvSparseMat*)hist->bins;
2309 CvSparseMatIterator iterator;
2310 CvSparseNode *node;
2311 float scale;
2312
2313 for( node = cvInitSparseMatIterator( mat, &iterator );
2314 node != 0; node = cvGetNextSparseNode( &iterator ))
2315 {
2316 sum += *(float*)CV_NODE_VAL(mat,node);
2317 }
2318
2319 if( fabs(sum) < DBL_EPSILON )
2320 sum = 1;
2321 scale = (float)(factor/sum);
2322
2323 for( node = cvInitSparseMatIterator( mat, &iterator );
2324 node != 0; node = cvGetNextSparseNode( &iterator ))
2325 {
2326 *(float*)CV_NODE_VAL(mat,node) *= scale;
2327 }
2328 }
2329}
2330
2331
2332// Retrieves histogram global min, max and their positions

Callers 1

Calls 3

cvGetMatFunction · 0.85
cvSumFunction · 0.85
cvInitSparseMatIteratorFunction · 0.85

Tested by

no test coverage detected