34 #ifndef __INCLUDE_INTEGRAL_IMAGE_H__
35 #define __INCLUDE_INTEGRAL_IMAGE_H__
37 #ifndef __INCLUDE_MIST_H__
41 #ifndef __INCLUDE_MIST_TYPE_TRAIT_H__
45 #ifndef __INCLUDE_MIST_COLOR_H__
54 namespace __integral_image__
56 template<
class T,
bool Is_decimal,
bool Is_color >
struct integral_type {
typedef typename T::template rebind< double >::other type; };
57 template<
class T >
struct integral_type< T, false, true > {
typedef typename T::template rebind< ptrdiff_t >::other type; };
58 template<
class T >
struct integral_type< T, true, false > {
typedef double type; };
59 template<
class T >
struct integral_type< T, false, false > {
typedef ptrdiff_t type; };
77 template<
typename Array >
124 template<
typename T,
typename Allocator >
128 typedef typename __integral_image__::integral_type< T, is_float< T >::value,
is_color< T >::value >::type value_type;
148 return( integral_( begin + size ) - integral_( begin ) );
159 return( integral_( i + 1 ) );
166 value_type overall( )
const
168 return( integral_[ integral_.size( ) - 1 ] );
177 return( integral_.size( ) - 1 );
187 for(
size_type i = 1 ; i < integral_.width( ) ; i ++ )
189 integral_[ i ] = in[ i - 1 ] + integral_[ i - 1 ];
199 construct_integral_array( in );
241 template<
typename T,
typename Allocator >
245 typedef typename __integral_image__::integral_type< T, is_float< T >::value,
is_color< T >::value >::type value_type;
268 return( p2[ width] + p1[ 0 ] - p1[ width ] - p2[ 0 ] );
281 return( integral_( i + 1, j + 1 ) );
293 return( integral_( i + 1, j + 1 ) );
300 value_type overall( )
const
302 return( integral_[ integral_.size( ) - 1 ] );
311 return( integral_.width( ) - 1 );
320 return( integral_.height( ) - 1 );
347 return( width( ) * height( ) );
356 integral_.resize( in.
width( ) + 1, in.
height( ) + 1 );
359 int iw =
static_cast< int >( in.
width( ) );
360 int ih =
static_cast< int >( in.
height( ) );
363 #pragma omp parallel for firstprivate( iw, ih ) schedule( guided )
364 for(
int j = 0 ; j < ih ; j++ )
370 for(
int i = 1 ; i < iw ; i++ )
372 op[ i ] = op[ i - 1 ] + ip[ i ];
376 #pragma omp parallel for firstprivate( iw, ih, ow ) schedule( guided )
377 for(
int i = 0 ; i < iw ; i++ )
384 for(
int j = 1 ; j < ih ; j++ )
398 op[ i ] = op[ i - 1 ] + ip[ i ];
403 op += integral_.width( );
407 value_type tmp = ip[ 0 ];
408 op[ 0 ] = oop[ 0 ] + tmp;
413 op[ i ] = oop[ i ] + tmp;
418 op += integral_.width( );
429 construct_integral_array( in );
471 template<
typename T,
typename Allocator >
475 typedef typename __integral_image__::integral_type< T, is_float< T >::value,
is_color< T >::value >::type value_type;
498 return( integral_( begin_i + width, begin_j + height, begin_k + depth ) + integral_( begin_i, begin_j, begin_k + depth ) + integral_( begin_i, begin_j + height, begin_k ) + integral_( begin_i + width, begin_j, begin_k ) - integral_( begin_i, begin_j + height, begin_k + depth ) - integral_( begin_i + width, begin_j, begin_k + depth ) - integral_( begin_i + width, begin_j + height, begin_k ) - integral_( begin_i, begin_j, begin_k ) );
511 return( integral_( i + 1, j + 1, k + 1 ) );
518 value_type overall( )
const
520 return( integral_( integral_.width( ) - 1, integral_.height( ) - 1, integral_.depth( ) - 1 ) );
529 return( integral_.width( ) - 1 );
538 return( integral_.height( ) - 1 );
547 return( integral_.depth( ) - 1 );
583 return( width( ) * height( ) * depth( ) );
593 for(
size_type k = 1 ; k < integral_.depth( ) ; k ++ )
595 for(
size_type j = 1 ; j < integral_.height( ) ; j ++ )
597 for(
size_type i = 1 ; i < integral_.width( ) ; i ++ )
599 integral_( i, j, k ) = in( i - 1, j - 1, k - 1 ) + integral_( i - 1, j, k ) + integral_( i, j - 1, k ) + integral_( i, j, k - 1 ) + integral_( i - 1, j - 1, k - 1 ) - integral_( i - 1, j - 1, k ) - integral_( i - 1, j, k - 1 ) - integral_( i, j - 1, k - 1 );
611 construct_integral_array( in );
633 template <
class T,
class Allocator >
634 inline std::ostream &operator <<( std::ostream &out, const integral_image< array< T, Allocator > > &a )
637 for( i = 0 ; i < a.
size( ) ; i++ )
640 if( i != a.
size1( ) - 1 ) out <<
", ";
658 template <
class T,
class Allocator >
659 inline std::ostream &operator <<( std::ostream &out, const integral_image< array1< T, Allocator > > &a )
662 for( i = 0 ; i < a.
size( ) ; i++ )
665 if( i != a.
size1( ) - 1 ) out <<
", ";
685 template <
class T,
class Allocator >
686 inline std::ostream &operator <<( std::ostream &out, const integral_image< array2< T, Allocator > > &a )
689 for( j = 0 ; j < a.
size2( ) ; j++ )
695 for( i = 0 ; i < a.
size1( ) ; i++ )
698 if( i != a.
size1( ) - 1 ) out <<
", ";
723 template <
class T,
class Allocator >
724 inline std::ostream &operator <<( std::ostream &out, const integral_image< array3< T, Allocator > > &a )
727 for( k = 0 ; k < a.
size3( ) ; k++ )
729 for( j = 0 ; j < a.
size2( ) ; j++ )
731 for( i = 0 ; i < a.
size1( ) ; i++ )
734 if( i != a.
size1( ) - 1 ) out <<
", ";
738 if( k != a.
size3( ) - 1 )
740 out <<
"----- separator -----";
757 #endif // __INCLUDE_INTEGRAL_IMAGE_H__