📄 cxmeansdv.cpp
字号:
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// Intel License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000, Intel Corporation, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of Intel Corporation may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#include "_cxcore.h"
/****************************************************************************************\
* Mean and StdDev calculation *
\****************************************************************************************/
#define ICV_MEAN_SDV_COI_CASE( worktype, sqsumtype, \
sqr_macro, len, cn ) \
for( ; x <= (len) - 4*(cn); x += 4*(cn))\
{ \
worktype t0 = src[x]; \
worktype t1 = src[x + (cn)]; \
\
s0 += t0 + t1; \
sq0 += (sqsumtype)(sqr_macro(t0)) + \
(sqsumtype)(sqr_macro(t1)); \
\
t0 = src[x + 2*(cn)]; \
t1 = src[x + 3*(cn)]; \
\
s0 += t0 + t1; \
sq0 += (sqsumtype)(sqr_macro(t0)) + \
(sqsumtype)(sqr_macro(t1)); \
} \
\
for( ; x < (len); x += (cn) ) \
{ \
worktype t0 = src[x]; \
\
s0 += t0; \
sq0 += (sqsumtype)(sqr_macro(t0)); \
}
#define ICV_MEAN_SDV_CASE_C1( worktype, sqsumtype, sqr_macro, len ) \
ICV_MEAN_SDV_COI_CASE( worktype, sqsumtype, sqr_macro, len, 1 )
#define ICV_MEAN_SDV_CASE_C2( worktype, sqsumtype, \
sqr_macro, len ) \
for( ; x < (len); x += 2 ) \
{ \
worktype t0 = (src)[x]; \
worktype t1 = (src)[x + 1]; \
\
s0 += t0; \
sq0 += (sqsumtype)(sqr_macro(t0)); \
s1 += t1; \
sq1 += (sqsumtype)(sqr_macro(t1)); \
}
#define ICV_MEAN_SDV_CASE_C3( worktype, sqsumtype, \
sqr_macro, len ) \
for( ; x < (len); x += 3 ) \
{ \
worktype t0 = (src)[x]; \
worktype t1 = (src)[x + 1]; \
worktype t2 = (src)[x + 2]; \
\
s0 += t0; \
sq0 += (sqsumtype)(sqr_macro(t0)); \
s1 += t1; \
sq1 += (sqsumtype)(sqr_macro(t1)); \
s2 += t2; \
sq2 += (sqsumtype)(sqr_macro(t2)); \
}
#define ICV_MEAN_SDV_CASE_C4( worktype, sqsumtype, \
sqr_macro, len ) \
for( ; x < (len); x += 4 ) \
{ \
worktype t0 = (src)[x]; \
worktype t1 = (src)[x + 1]; \
\
s0 += t0; \
sq0 += (sqsumtype)(sqr_macro(t0)); \
s1 += t1; \
sq1 += (sqsumtype)(sqr_macro(t1)); \
\
t0 = (src)[x + 2]; \
t1 = (src)[x + 3]; \
\
s2 += t0; \
sq2 += (sqsumtype)(sqr_macro(t0)); \
s3 += t1; \
sq3 += (sqsumtype)(sqr_macro(t1)); \
}
#define ICV_MEAN_SDV_MASK_COI_CASE( worktype, sqsumtype, \
sqr_macro, len, cn ) \
for( ; x <= (len) - 4; x += 4 ) \
{ \
worktype t0; \
if( mask[x] ) \
{ \
t0 = src[x*(cn)]; pix++; \
s0 += t0; \
sq0 += sqsumtype(sqr_macro(t0)); \
} \
\
if( mask[x+1] ) \
{ \
t0 = src[(x+1)*(cn)]; pix++; \
s0 += t0; \
sq0 += sqsumtype(sqr_macro(t0)); \
} \
\
if( mask[x+2] ) \
{ \
t0 = src[(x+2)*(cn)]; pix++; \
s0 += t0; \
sq0 += sqsumtype(sqr_macro(t0)); \
} \
\
if( mask[x+3] ) \
{ \
t0 = src[(x+3)*(cn)]; pix++; \
s0 += t0; \
sq0 += sqsumtype(sqr_macro(t0)); \
} \
} \
\
for( ; x < (len); x++ ) \
{ \
if( mask[x] ) \
{ \
worktype t0 = src[x*(cn)]; pix++; \
s0 += t0; \
sq0 += sqsumtype(sqr_macro(t0)); \
} \
}
#define ICV_MEAN_SDV_MASK_CASE_C1( worktype, sqsumtype, sqr_macro, len ) \
ICV_MEAN_SDV_MASK_COI_CASE( worktype, sqsumtype, sqr_macro, len, 1 )
#define ICV_MEAN_SDV_MASK_CASE_C2( worktype, sqsumtype,\
sqr_macro, len ) \
for( ; x < (len); x++ ) \
{ \
if( mask[x] ) \
{ \
worktype t0 = src[x*2]; \
worktype t1 = src[x*2+1]; \
pix++; \
s0 += t0; \
sq0 += sqsumtype(sqr_macro(t0)); \
s1 += t1; \
sq1 += sqsumtype(sqr_macro(t1)); \
} \
}
#define ICV_MEAN_SDV_MASK_CASE_C3( worktype, sqsumtype,\
sqr_macro, len ) \
for( ; x < (len); x++ ) \
{ \
if( mask[x] ) \
{ \
worktype t0 = src[x*3]; \
worktype t1 = src[x*3+1]; \
worktype t2 = src[x*3+2]; \
pix++; \
s0 += t0; \
sq0 += sqsumtype(sqr_macro(t0)); \
s1 += t1; \
sq1 += sqsumtype(sqr_macro(t1)); \
s2 += t2; \
sq2 += sqsumtype(sqr_macro(t2)); \
} \
}
#define ICV_MEAN_SDV_MASK_CASE_C4( worktype, sqsumtype,\
sqr_macro, len ) \
for( ; x < (len); x++ ) \
{ \
if( mask[x] ) \
{ \
worktype t0 = src[x*4]; \
worktype t1 = src[x*4+1]; \
pix++; \
s0 += t0; \
sq0 += sqsumtype(sqr_macro(t0)); \
s1 += t1; \
sq1 += sqsumtype(sqr_macro(t1)); \
t0 = src[x*4+2]; \
t1 = src[x*4+3]; \
s2 += t0; \
sq2 += sqsumtype(sqr_macro(t0)); \
s3 += t1; \
sq3 += sqsumtype(sqr_macro(t1)); \
} \
}
////////////////////////////////////// entry macros //////////////////////////////////////
#define ICV_MEAN_SDV_ENTRY_COMMON() \
int pix; \
double scale, tmp; \
step /= sizeof(src[0])
#define ICV_MEAN_SDV_ENTRY_C1( sumtype, sqsumtype ) \
sumtype s0 = 0; \
sqsumtype sq0 = 0; \
ICV_MEAN_SDV_ENTRY_COMMON()
#define ICV_MEAN_SDV_ENTRY_C2( sumtype, sqsumtype ) \
sumtype s0 = 0, s1 = 0; \
sqsumtype sq0 = 0, sq1 = 0; \
ICV_MEAN_SDV_ENTRY_COMMON()
#define ICV_MEAN_SDV_ENTRY_C3( sumtype, sqsumtype ) \
sumtype s0 = 0, s1 = 0, s2 = 0; \
sqsumtype sq0 = 0, sq1 = 0, sq2 = 0; \
ICV_MEAN_SDV_ENTRY_COMMON()
#define ICV_MEAN_SDV_ENTRY_C4( sumtype, sqsumtype ) \
sumtype s0 = 0, s1 = 0, s2 = 0, s3 = 0; \
sqsumtype sq0 = 0, sq1 = 0, sq2 = 0, sq3 = 0; \
ICV_MEAN_SDV_ENTRY_COMMON()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -