📄 cxnorm.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"
/****************************************************************************************\
* N o r m *
\****************************************************************************************/
#define ICV_NORM_CASE( _op_, \
_update_op_, worktype, len ) \
\
for( ; x <= (len) - 4; x += 4 ) \
{ \
worktype t0 = (src)[x]; \
worktype t1 = (src)[x+1]; \
t0 = _op_(t0); \
t1 = _op_(t1); \
norm = _update_op_( norm, t0 ); \
norm = _update_op_( norm, t1 ); \
\
t0 = (src)[x+2]; \
t1 = (src)[x+3]; \
t0 = _op_(t0); \
t1 = _op_(t1); \
norm = _update_op_( norm, t0 ); \
norm = _update_op_( norm, t1 ); \
} \
\
for( ; x < (len); x++ ) \
{ \
worktype t0 = (src)[x]; \
t0 = (worktype)_op_(t0); \
norm = _update_op_( norm, t0 ); \
}
#define ICV_NORM_COI_CASE( _op_, \
_update_op_, worktype, len, cn ) \
\
for( ; x < (len); x++ ) \
{ \
worktype t0 = (src)[x*(cn)]; \
t0 = (worktype)_op_(t0); \
norm = _update_op_( norm, t0 ); \
}
#define ICV_NORM_DIFF_CASE( _op_, \
_update_op_, worktype, len ) \
\
for( ; x <= (len) - 4; x += 4 ) \
{ \
worktype t0 = (src1)[x] - (src2)[x];\
worktype t1 = (src1)[x+1]-(src2)[x+1];\
\
t0 = _op_(t0); \
t1 = _op_(t1); \
\
norm = _update_op_( norm, t0 ); \
norm = _update_op_( norm, t1 ); \
\
t0 = (src1)[x+2] - (src2)[x+2]; \
t1 = (src1)[x+3] - (src2)[x+3]; \
\
t0 = _op_(t0); \
t1 = _op_(t1); \
\
norm = _update_op_( norm, t0 ); \
norm = _update_op_( norm, t1 ); \
} \
\
for( ; x < (len); x++ ) \
{ \
worktype t0 = (src1)[x] - (src2)[x];\
t0 = (worktype)_op_(t0); \
norm = _update_op_( norm, t0 ); \
}
#define ICV_NORM_DIFF_COI_CASE( _op_, _update_op_, worktype, len, cn ) \
for( ; x < (len); x++ ) \
{ \
worktype t0 = (src1)[x*(cn)] - (src2)[x*(cn)]; \
t0 = (worktype)_op_(t0); \
norm = _update_op_( norm, t0 ); \
}
/*
The algorithm and its multiple variations below
below accumulates the norm by blocks of size "block_size".
Each block may span across multiple lines and it is
not necessary aligned by row boundaries. Within a block
the norm is accumulated to intermediate light-weight
type (worktype). It really makes sense for 8u, 16s, 16u types
and L1 & L2 norms, where worktype==int and normtype==int64.
In other cases a simpler algorithm is used
*/
#define ICV_DEF_NORM_NOHINT_BLOCK_FUNC_2D( name, _op_, _update_op_, \
post_func, arrtype, normtype, worktype, block_size ) \
IPCVAPI_IMPL( CvStatus, name, ( const arrtype* src, int step, \
CvSize size, double* _norm ), (src, step, size, _norm) ) \
{ \
int remaining = block_size; \
normtype total_norm = 0; \
worktype norm = 0; \
step /= sizeof(src[0]); \
\
for( ; size.height--; src += step ) \
{ \
int x = 0; \
while( x < size.width ) \
{ \
int limit = MIN( remaining, size.width - x ); \
remaining -= limit; \
limit += x; \
ICV_NORM_CASE( _op_, _update_op_, worktype, limit );\
if( remaining == 0 ) \
{ \
remaining = block_size; \
total_norm += (normtype)norm; \
norm = 0; \
} \
} \
} \
\
total_norm += (normtype)norm; \
*_norm = post_func((double)total_norm); \
return CV_OK; \
}
#define ICV_DEF_NORM_NOHINT_FUNC_2D( name, _op_, _update_op_, \
post_func, arrtype, normtype, worktype, block_size ) \
IPCVAPI_IMPL( CvStatus, name, ( const arrtype* src, int step, \
CvSize size, double* _norm ), (src, step, size, _norm) ) \
{ \
normtype norm = 0; \
step /= sizeof(src[0]); \
\
for( ; size.height--; src += step ) \
{ \
int x = 0; \
ICV_NORM_CASE(_op_, _update_op_, worktype, size.width); \
} \
\
*_norm = post_func((double)norm); \
return CV_OK; \
}
/*
In IPP only 32f flavors of norm functions are with hint.
For float worktype==normtype==double, thus the block algorithm,
described above, is not necessary.
*/
#define ICV_DEF_NORM_HINT_FUNC_2D( name, _op_, _update_op_, \
post_func, arrtype, normtype, worktype, block_size ) \
IPCVAPI_IMPL( CvStatus, name, ( const arrtype* src, int step, \
CvSize size, double* _norm, CvHintAlgorithm /*hint*/ ), \
(src, step, size, _norm, cvAlgHintAccurate) ) \
{ \
normtype norm = 0; \
step /= sizeof(src[0]); \
\
for( ; size.height--; src += step ) \
{ \
int x = 0; \
ICV_NORM_CASE(_op_, _update_op_, worktype, size.width); \
} \
\
*_norm = post_func((double)norm); \
return CV_OK; \
}
#define ICV_DEF_NORM_NOHINT_BLOCK_FUNC_2D_COI( name, _op_, \
_update_op_, post_func, arrtype, \
normtype, worktype, block_size ) \
static CvStatus CV_STDCALL name( const arrtype* src, int step, \
CvSize size, int cn, int coi, double* _norm ) \
{ \
int remaining = block_size; \
normtype total_norm = 0; \
worktype norm = 0; \
step /= sizeof(src[0]); \
src += coi - 1; \
\
for( ; size.height--; src += step ) \
{ \
int x = 0; \
while( x < size.width ) \
{ \
int limit = MIN( remaining, size.width - x ); \
remaining -= limit; \
limit += x; \
ICV_NORM_COI_CASE( _op_, _update_op_, \
worktype, limit, cn ); \
if( remaining == 0 ) \
{ \
remaining = block_size; \
total_norm += (normtype)norm; \
norm = 0; \
} \
} \
} \
\
total_norm += (normtype)norm; \
*_norm = post_func((double)total_norm); \
return CV_OK; \
}
#define ICV_DEF_NORM_NOHINT_FUNC_2D_COI( name, _op_, \
_update_op_, post_func, \
arrtype, normtype, worktype, block_size ) \
static CvStatus CV_STDCALL name( const arrtype* src, int step, \
CvSize size, int cn, int coi, double* _norm ) \
{ \
normtype norm = 0; \
step /= sizeof(src[0]); \
src += coi - 1; \
\
for( ; size.height--; src += step ) \
{ \
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -