39 #ifndef __INCLUDE_MIST_LABELING__
40 #define __INCLUDE_MIST_LABELING__
42 #ifndef __INCLUDE_MIST_H__
46 #ifndef __INCLUDE_MIST_LIMITS__
47 #include "../limits.h"
59 namespace __labeling_controller__
61 template <
class T >
struct default_label_num2
63 _MIST_CONST(
size_t, value, 2560 );
65 template < >
struct default_label_num2< char >
67 _MIST_CONST(
size_t, value, 127 );
69 template < >
struct default_label_num2< signed char >
71 _MIST_CONST(
size_t, value, 127 );
73 template < >
struct default_label_num2< unsigned char >
75 _MIST_CONST(
size_t, value, 255 );
78 template <
class T >
struct default_label_num3
80 _MIST_CONST(
size_t, value, 10000 );
82 template < >
struct default_label_num3< char >
84 _MIST_CONST(
size_t, value, 127 );
86 template < >
struct default_label_num3< signed char >
88 _MIST_CONST(
size_t, value, 127 );
90 template < >
struct default_label_num3< unsigned char >
92 _MIST_CONST(
size_t, value, 255 );
99 _MIST_CONST(
size_t, array_num, 13 );
101 template <
class Array,
class Vector >
102 static inline typename Array::size_type neighbor( Array &in,
const Vector &T,
typename Vector::value_type *L,
103 const typename Array::size_type i,
const typename Array::size_type j,
const typename Array::size_type k,
104 const typename Array::size_type w,
const typename Array::size_type h,
const typename Array::size_type d )
106 typedef typename Array::size_type size_type;
108 L[ 0 ] = k > 0 ? T[
static_cast< size_type
>( in( i , j , k - 1 ) ) ] : 0;
109 L[ 1 ] = j > 0 ? T[
static_cast< size_type
>( in( i , j - 1, k ) ) ] : 0;
110 L[ 2 ] = i > 0 ? T[
static_cast< size_type
>( in( i - 1, j , k ) ) ] : 0;
111 L[ 3 ] = j > 0 && k > 0 ? T[
static_cast< size_type
>( in( i , j - 1, k - 1 ) ) ] : 0;
112 L[ 4 ] = i > 0 && k > 0 ? T[
static_cast< size_type
>( in( i - 1, j , k - 1 ) ) ] : 0;
113 L[ 5 ] = i + 1 < w && k > 0 ? T[
static_cast< size_type
>( in( i + 1, j , k - 1 ) ) ] : 0;
114 L[ 6 ] = j + 1 < h && k > 0 ? T[
static_cast< size_type
>( in( i , j + 1, k - 1 ) ) ] : 0;
115 L[ 7 ] = i > 0 && j > 0 ? T[
static_cast< size_type
>( in( i - 1, j - 1, k ) ) ] : 0;
116 L[ 8 ] = i + 1 < w && j > 0 ? T[
static_cast< size_type
>( in( i + 1, j - 1, k ) ) ] : 0;
117 L[ 9 ] = i > 0 && j > 0 && k > 0 ? T[
static_cast< size_type
>( in( i - 1, j - 1, k - 1 ) ) ] : 0;
118 L[ 10 ] = i + 1 < w && j > 0 && k > 0 ? T[
static_cast< size_type
>( in( i + 1, j - 1, k - 1 ) ) ] : 0;
119 L[ 11 ] = i > 0 && j + 1 < h && k > 0 ? T[
static_cast< size_type
>( in( i - 1, j + 1, k - 1 ) ) ] : 0;
120 L[ 12 ] = i + 1 < w && j + 1 < h && k > 0 ? T[
static_cast< size_type
>( in( i + 1, j + 1, k - 1 ) ) ] : 0;
127 struct neighbors< 18 >
129 _MIST_CONST(
size_t, array_num, 9 );
131 template <
class Array,
class Vector >
132 static inline typename Array::size_type neighbor( Array &in,
const Vector &T,
typename Vector::value_type *L,
133 const typename Array::size_type i,
const typename Array::size_type j,
const typename Array::size_type k,
134 const typename Array::size_type w,
const typename Array::size_type h,
const typename Array::size_type d )
136 typedef typename Array::size_type size_type;
138 L[ 0 ] = k > 0 ? T[
static_cast< size_type
>( in( i , j , k - 1 ) ) ] : 0;
139 L[ 1 ] = j > 0 ? T[
static_cast< size_type
>( in( i , j - 1, k ) ) ] : 0;
140 L[ 2 ] = i > 0 ? T[
static_cast< size_type
>( in( i - 1, j , k ) ) ] : 0;
141 L[ 3 ] = j > 0 && k > 0 ? T[
static_cast< size_type
>( in( i , j - 1, k - 1 ) ) ] : 0;
142 L[ 4 ] = i > 0 && k > 0 ? T[
static_cast< size_type
>( in( i - 1, j , k - 1 ) ) ] : 0;
143 L[ 5 ] = i + 1 < w && k > 0 ? T[
static_cast< size_type
>( in( i + 1, j , k - 1 ) ) ] : 0;
144 L[ 6 ] = j + 1 < h && k > 0 ? T[
static_cast< size_type
>( in( i , j + 1, k - 1 ) ) ] : 0;
145 L[ 7 ] = i > 0 && j > 0 ? T[
static_cast< size_type
>( in( i - 1, j - 1, k ) ) ] : 0;
146 L[ 8 ] = i + 1 < w && j > 0 ? T[
static_cast< size_type
>( in( i + 1, j - 1, k ) ) ] : 0;
153 struct neighbors< 6 >
155 _MIST_CONST(
size_t, array_num, 3 );
157 template <
class Array,
class Vector >
158 static inline typename Array::size_type neighbor( Array &in,
const Vector &T,
typename Vector::value_type *L,
159 const typename Array::size_type i,
const typename Array::size_type j,
const typename Array::size_type k,
160 const typename Array::size_type w,
const typename Array::size_type h,
const typename Array::size_type d )
162 typedef typename Array::size_type size_type;
164 L[ 0 ] = k > 0 ? T[
static_cast< size_type
>( in( i , j , k - 1 ) ) ] : 0;
165 L[ 1 ] = j > 0 ? T[
static_cast< size_type
>( in( i , j - 1, k ) ) ] : 0;
166 L[ 2 ] = i > 0 ? T[
static_cast< size_type
>( in( i - 1, j , k ) ) ] : 0;
173 struct neighbors< 8 >
175 _MIST_CONST(
size_t, array_num, 4 );
177 template <
class Array,
class Vector >
178 static inline typename Array::size_type neighbor( Array &in,
const Vector &T,
typename Vector::value_type *L,
179 const typename Array::size_type i,
const typename Array::size_type j,
const typename Array::size_type ,
180 const typename Array::size_type w,
const typename Array::size_type ,
const typename Array::size_type )
182 typedef typename Array::size_type size_type;
184 L[ 0 ] = i > 0 && j > 0 ? T[
static_cast< size_type
>( in( i - 1, j - 1 ) ) ] : 0;
185 L[ 1 ] = j > 0 ? T[
static_cast< size_type
>( in( i , j - 1 ) ) ] : 0;
186 L[ 2 ] = i + 1 < w && j > 0 ? T[
static_cast< size_type
>( in( i + 1, j - 1 ) ) ] : 0;
187 L[ 3 ] = i > 0 ? T[
static_cast< size_type
>( in( i - 1, j ) ) ] : 0;
194 struct neighbors< 4 >
196 _MIST_CONST(
size_t, array_num, 2 );
198 template <
class Array,
class Vector >
199 static inline typename Array::size_type neighbor( Array &in,
const Vector &T,
typename Vector::value_type *L,
200 const typename Array::size_type i,
const typename Array::size_type j,
const typename Array::size_type k,
201 const typename Array::size_type w,
const typename Array::size_type h,
const typename Array::size_type d )
203 typedef typename Array::size_type size_type;
205 L[ 0 ] = j > 0 ? T[
static_cast< size_type
>( in( i , j - 1 ) ) ] : 0;
206 L[ 1 ] = i > 0 ? T[
static_cast< size_type
>( in( i - 1, j ) ) ] : 0;
213 template <
class Array,
class neighbor,
class Functor >
214 typename Array::size_type labeling( Array &in,
typename Array::size_type label_max,
const neighbor , Functor f )
216 typedef typename Array::size_type size_type;
217 typedef typename Array::difference_type difference_type;
218 typedef typename Array::value_type value_type;
222 typedef unsigned int label_value_type;
224 typedef std::vector< label_value_type >::value_type vector_label_value_type;
225 typedef std::list< label_value_type > label_list_type;
227 size_type label_num = 0;
228 size_type i, j, k, l, count;
230 std::vector< label_value_type > T;
231 std::vector< label_list_type > TBL;
232 label_value_type L[ neighbor::array_num ];
233 const size_type width = in.width( );
234 const size_type height = in.height( );
235 const size_type depth = in.depth( );
237 T.reserve( label_max );
239 TBL.push_back( label_list_type( ) );
241 const bool bprogress1 = depth == 1;
242 const bool bprogress2 = depth > 1;
244 if( is_float< value_type >::value )
246 label_max = type_limits< size_type >::maximum( );
250 label_max =
static_cast< size_type
>( type_limits< value_type >::maximum( ) );
255 for( k = 0 ; k < depth ; k++ )
257 for( j = 0 ; j < height ; j++ )
259 for( i = 0 ; i < width ; i++ )
262 if( in( i, j, k ) == 0 )
268 neighbor::neighbor( in, T, L, i, j, k, width, height, depth );
271 label_value_type L1 =
static_cast< label_value_type
>( label_max );
272 for( l = 0, count = 0 ; l < neighbor::array_num ; l++ )
291 if( label_num < label_max )
296 T.push_back( static_cast< label_value_type >( label_num ) );
299 ll.push_back( static_cast< label_value_type >( label_num ) );
302 in( i, j, k ) =
static_cast< value_type
>( label_num );
304 else if( count == 1 )
307 in( i, j, k ) =
static_cast< value_type
>( L1 );
311 in( i, j, k ) =
static_cast< value_type
>( L1 );
314 for( l = 0 ; l < neighbor::array_num ; l++ )
316 label_value_type L0 = L[ l ];
319 typename label_list_type::iterator ite = TBL[ L0 ].begin( );
320 typename label_list_type::iterator eite = TBL[ L0 ].end( );
322 for( ; ite != eite ; ++ite )
324 T[ *ite ] =
static_cast< vector_label_value_type
>( L1 );
328 TBL[ L1 ].insert( TBL[ L1 ].end( ), TBL[ L0 ].begin( ), TBL[ L0 ].end( ) );
337 f( static_cast< double >( j + 1 ) / static_cast< double >( height ) * 100.0 );
343 f( static_cast< double >( k + 1 ) / static_cast< double >( depth ) * 100.0 );
350 size_type *NT =
new size_type[ label_num + 1 ];
351 for( i = 0 ; i <= label_num ; i++ )
357 for( i = 1 ; i <= label_num ; i++ )
363 for( i = 1, count = 1 ; i <= label_num ; i++ )
372 for( i = 0 ; i < in.size( ) ; i++ )
379 size_type label = NT[ T[
static_cast< size_type
>( in[ i ] ) ] ];
380 in[ i ] =
static_cast< value_type
>( label );
381 if( label_num < label )
425 template <
class T1,
class T2,
class Allocator1,
class Allocator2,
class Functor >
447 for( size_type i = 0 ; i < in.
size( ) ; i++ )
449 out[ i ] =
static_cast< value_type
>( in[ i ] > 0 ? 1 : 0 );
451 return( __labeling_controller__::labeling( out, max_label, __labeling_controller__::neighbors< 4 >( ), f ) );
472 template <
class T1,
class T2,
class Allocator1,
class Allocator2 >
497 template <
class T1,
class T2,
class Allocator1,
class Allocator2,
class Functor >
519 for( size_type i = 0 ; i < in.
size( ) ; i++ )
521 out[ i ] =
static_cast< value_type
>( in[ i ] > 0 ? 1 : 0 );
523 return( __labeling_controller__::labeling( out, max_label, __labeling_controller__::neighbors< 8 >( ), f ) );
544 template <
class T1,
class T2,
class Allocator1,
class Allocator2 >
569 template <
class T1,
class T2,
class Allocator1,
class Allocator2,
class Functor >
592 for( size_type i = 0 ; i < in.
size( ) ; i++ )
594 out[ i ] =
static_cast< value_type
>( in[ i ] > 0 ? 1 : 0 );
596 return( __labeling_controller__::labeling( out, max_label, __labeling_controller__::neighbors< 6 >( ), f ) );
616 template <
class T1,
class T2,
class Allocator1,
class Allocator2 >
641 template <
class T1,
class T2,
class Allocator1,
class Allocator2,
class Functor >
664 for( size_type i = 0 ; i < in.
size( ) ; i++ )
666 out[ i ] =
static_cast< value_type
>( in[ i ] > 0 ? 1 : 0 );
668 return( __labeling_controller__::labeling( out, max_label, __labeling_controller__::neighbors< 18 >( ), f ) );
688 template <
class T1,
class T2,
class Allocator1,
class Allocator2 >
713 template <
class T1,
class T2,
class Allocator1,
class Allocator2,
class Functor >
736 for( size_type i = 0 ; i < in.
size( ) ; i++ )
738 out[ i ] =
static_cast< value_type
>( in[ i ] > 0 ? 1 : 0 );
740 return( __labeling_controller__::labeling( out, max_label, __labeling_controller__::neighbors< 26 >( ), f ) );
759 template <
class T1,
class T2,
class Allocator1,
class Allocator2 >
782 template <
class T1,
class T2,
class Allocator1,
class Allocator2 >
802 sx = sx < 0 ? 0 : sx;
803 sy = sy < 0 ? 0 : sy;
807 ex = ex < 0 ? 0 : ex;
808 ey = ey < 0 ? 0 : ey;
812 size_type *menseki =
new size_type[ label_num + 1 ];
813 for( i = 0 ; i <= label_num ; i++ )
818 for( j = sy ; j <= ey ; j++ )
820 for( i = sx ; i <= ex ; i++ )
822 menseki[ tmp( i, j ) ]++;
827 for( i = 2 ; i <= label_num ; i++ )
829 max_label = menseki[ i ] > menseki[ max_label ] ? i : max_label;
837 for( i = 0 ; i < out.
size( ) ; i++ )
839 out[ i ] = tmp[ i ] == max_label ? 1 : 0;
856 template <
class T1,
class T2,
class Allocator1,
class Allocator2 >
882 template <
class T1,
class T2,
class Allocator1,
class Allocator2 >
904 sx = sx < 0 ? 0 : sx;
905 sy = sy < 0 ? 0 : sy;
906 sz = sz < 0 ? 0 : sz;
911 ex = ex < 0 ? 0 : ex;
912 ey = ey < 0 ? 0 : ey;
913 ez = ez < 0 ? 0 : ez;
918 size_type *menseki =
new size_type[ label_num + 1 ];
919 for( i = 0 ; i <= label_num ; i++ )
924 for( k = sz ; k <= ez ; k++ )
926 for( j = sy ; j <= ey ; j++ )
928 for( i = sx ; i <= ex ; i++ )
930 menseki[ tmp( i, j, k ) ]++;
936 for( i = 2 ; i <= label_num ; i++ )
938 max_label = menseki[ i ] > menseki[ max_label ] ? i : max_label;
947 for( i = 0 ; i < out.
size( ) ; i++ )
966 template <
class T1,
class T2,
class Allocator1,
class Allocator2 >
986 template <
class T1,
class T2,
class Allocator1,
class Allocator2 >
1000 for( i = 0 ; i < tmp.
size( ) ; i++ )
1002 tmp[ i ] = in[ i ] == 0;
1007 if ( include_corner_labels )
1009 size_type *L =
new size_type[ label_num + 1 ];
1011 for( size_type i = 0 ; i <= label_num ; i++ )
1013 L[ i ] =
static_cast< size_type
>( i );
1016 L[ tmp( 0, 0 ) ] = 1;
1017 L[ tmp( tmp.
width() - 1, 0 ) ] = 1;
1018 L[ tmp( 0, tmp.
height() - 1 ) ] = 1;
1019 L[ tmp( tmp.
width() - 1, tmp.
height() - 1 ) ] = 1;
1021 for( size_type i = 0 ; i < tmp.
size( ) ; i++ )
1023 tmp[ i ] = L[ tmp[ i ] ];
1030 size_type *menseki =
new size_type[ label_num + 1 ];
1031 for( i = 0 ; i <= label_num ; i++ )
1036 for( i = 0 ; i < tmp.
size( ) ; i++ )
1038 menseki[ tmp[ i ] ]++;
1042 for( i = 2 ; i <= label_num ; i++ )
1044 max_label = menseki[ i ] > menseki[ max_label ] ? i : max_label;
1053 for( i = 0 ; i < out.
size( ) ; i++ )
1055 out[ i ] = tmp[ i ] == max_label ? 0 : 1;
1070 template <
class T1,
class T2,
class Allocator1,
class Allocator2 >
1088 template <
class T1,
class T2,
class Allocator1,
class Allocator2 >
1103 for( i = 0 ; i < tmp.
size( ) ; i++ )
1105 tmp[ i ] = in[ i ] == 0;
1110 if ( include_corner_labels )
1112 size_type *L =
new size_type[ label_num + 1 ];
1114 for( size_type i = 0 ; i <= label_num ; i++ )
1116 L[ i ] =
static_cast< size_type
>( i );
1119 L[ tmp( 0, 0, 0 ) ] = 1;
1120 L[ tmp( tmp.
width() - 1, 0, 0 ) ] = 1;
1121 L[ tmp( 0, tmp.
height() - 1, 0 ) ] = 1;
1122 L[ tmp( 0, 0, tmp.
depth() - 1 ) ] = 1;
1123 L[ tmp( tmp.
width() - 1, tmp.
height() - 1, 0 ) ] = 1;
1124 L[ tmp( 0, tmp.
height() - 1, tmp.
depth() - 1 ) ] = 1;
1125 L[ tmp( tmp.
width() - 1, 0, tmp.
depth() - 1 ) ] = 1;
1128 for( size_type i = 0 ; i < tmp.
size( ) ; i++ )
1130 tmp[ i ] = L[ tmp[ i ] ];
1137 size_type *menseki =
new size_type[ label_num + 1 ];
1138 for( i = 0 ; i <= label_num ; i++ )
1143 for( i = 0 ; i < tmp.
size( ) ; i++ )
1145 menseki[ tmp[ i ] ]++;
1149 for( i = 2 ; i <= label_num ; i++ )
1151 max_label = menseki[ i ] > menseki[ max_label ] ? i : max_label;
1161 for( i = 0 ; i < out.
size( ) ; i++ )
1163 out[ i ] = tmp[ i ] == max_label ? 0 : 1;
1177 template <
class T1,
class T2,
class Allocator1,
class Allocator2 >
1189 typedef typename array< L >::value_type label_type;
1195 table_type( ) : label( 0 ), next( NULL ), tail( NULL ){}
1198 template<
class L,
class Allocator >
1199 inline void resolve(
const typename array< L, Allocator >::value_type::label_type u,
const typename array< L, Allocator >::value_type::label_type v, array< table_type< L >, Allocator > &table )
1201 typedef typename array< L, Allocator >::value_type table_type;
1202 typedef typename table_type::label_type label_type;
1203 if( table[ u ].label != table[ v ].label )
1207 if( table[ u ].label < table[ v ].label )
1209 pu = &table[ table[ u ].label ];
1210 pv = &table[ table[ v ].label ];
1214 pu = &table[ table[ v ].label ];
1215 pv = &table[ table[ u ].label ];
1217 pu->tail->next = pv;
1218 pu->tail = pv->tail;
1221 pv->label = pu->label;
1227 template<
class L,
class Allocator >
1228 inline void update(
typename array< L, Allocator >::value_type::label_type &m, array< table_type< L >, Allocator > &table )
1230 table[ m ].label = m;
1231 table[ m ].tail = &table[ m ];
1255 template<
typename T1,
class Allocator1,
typename T2,
class Allocator2 >
1256 inline typename array2< T2, Allocator2 >::size_type
labeling8(
const array2< T1, Allocator1 > &b, array2< T2, Allocator2 > &v )
1258 typedef typename array2< T1, Allocator1 >::size_type size_type;
1259 typedef typename array2< T1, Allocator1 >::difference_type difference_type;
1260 typedef typename array2< T1, Allocator1 >::value_type value_type;
1261 typedef typename array2< T2, Allocator2 >::value_type label_type;
1262 typedef typename array2< T1, Allocator1 >::const_pointer ipointer;
1263 typedef typename array2< T2, Allocator2 >::pointer opointer;
1265 typedef typename __he__::table_type< label_type > table_type;
1267 const size_type size = ( ( b.width( ) + 1 ) / 2 ) * ( ( b.height( ) + 1 ) / 2 );
1268 array< table_type > table( size );
1271 v.resize( b.width( ), b.height( ) );
1273 ipointer ip = &b( 0, 0 );
1274 opointer op1 = &v( 0, 0 );
1279 __he__::update( m, table );
1286 for( size_type i = 1 ; i < b.width( ) ; i++ )
1290 if( op1[ i - 1 ] != 0 )
1292 op1[ i ] = op1[ i - 1 ];
1297 __he__::update( m, table );
1313 for( size_type j = 1 ; j < b.height( ) ; j++ )
1319 op1[ 0 ] = op0[ 0 ];
1321 else if( op0[ 1 ] != 0 )
1323 op1[ 0 ] = op0[ 1 ];
1328 __he__::update( m, table );
1337 for( ; i < b.width( ) - 1 ; i++ )
1343 op1[ i ] = op0[ i ];
1345 else if( op1[ i - 1 ] != 0 )
1347 op1[ i ] = op1[ i - 1 ];
1348 if( op0[ i + 1 ] != 0 )
1350 __he__::resolve( op1[ i - 1 ], op0[ i + 1 ], table );
1353 else if( op0[ i - 1 ] != 0 )
1355 op1[ i ] = op0[ i - 1 ];
1356 if( op0[ i + 1 ] != 0 )
1358 __he__::resolve( op0[ i - 1 ], op0[ i + 1 ], table );
1361 else if( op0[ i + 1 ] != 0 )
1363 op1[ i ] = op0[ i + 1 ];
1368 __he__::update( m, table );
1381 op1[ i ] = op0[ i ];
1383 else if( op1[ i - 1 ] != 0 )
1385 op1[ i ] = op1[ i - 1 ];
1387 else if( op0[ i - 1 ] != 0 )
1389 op1[ i ] = op0[ i - 1 ];
1394 __he__::update( m, table );
1407 array< label_type > l_table( m );
1409 for( size_type i = 1 ; i < m ; i++ )
1411 if( l_table[ table[ i ].label ] == 0 )
1414 l_table[ table[ i ].label ] = l;
1418 for(
size_t i = 0 ; i < v.size( ) ; i++ )
1420 v[ i ] = l_table[ table[ v[ i ] ].label ];
1423 return( static_cast< size_type >( l ) );
1442 template<
typename T1,
class Allocator1,
typename T2,
class Allocator2 >
1443 inline typename array3< T2, Allocator2 >::value_type
labeling26(
const array3< T1, Allocator1 > &b, array3< T2, Allocator2 > &l )
1445 typedef typename array3< T1, Allocator1 >::size_type size_type;
1446 typedef typename array3< T1, Allocator1 >::difference_type difference_type;
1447 typedef typename array3< T1, Allocator1 >::value_type value_type;
1448 typedef typename array3< T2, Allocator2 >::value_type label_type;
1449 typedef typename array3< T1, Allocator1 >::const_pointer ipointer;
1450 typedef typename array3< T2, Allocator2 >::pointer opointer;
1452 typedef typename __he__::table_type< label_type > table_type;
1454 const size_type size = ( ( b.width( ) + 1 ) / 2 ) * ( ( b.height( ) + 1 ) / 2 ) * ( ( b.depth( ) + 1 ) / 2 );
1455 array< table_type > table( size );
1456 l.resize( b.width( ), b.height( ), b.depth( ) );
1457 label_type label = 1;
1464 if( b( i, j, k ) != 0 )
1466 l( i, j, k ) = label;
1467 __he__::update( label, table );
1474 for(
size_t i = 1 ; i != b.width( ) ; ++ i )
1476 const label_type &l1 = l( i - 1, j , k );
1477 if( b( i, j, k ) != 0 )
1485 l( i, j, k ) = label;
1486 __he__::update( label, table );
1495 for(
size_t j = 1 ; j != b.height( ) ; ++ j )
1499 const label_type &l3 = l( i, j - 1, k );
1500 const label_type &l4 = l( i + 1, j - 1, k );
1501 if( b( i, j, k ) != 0 )
1513 l( i, j, k ) = label;
1514 __he__::update( label, table );
1522 for(
size_t i = 1 ; i != b.width( ) - 1 ; ++ i )
1524 const label_type &l1 = l( i - 1, j , k );
1525 const label_type &l2 = l( i - 1, j - 1, k );
1526 const label_type &l3 = l( i, j - 1, k );
1527 const label_type &l4 = l( i + 1, j - 1, k );
1528 if( b( i, j, k ) != 0 )
1539 __he__::resolve( l1, l4, table );
1547 __he__::resolve( l2, l4, table );
1556 l( i, j, k ) = label;
1557 __he__::update( label, table );
1566 const size_t i = b.width( ) - 1;
1567 const label_type &l1 = l( i - 1, j, k );
1568 const label_type &l2 = l( i - 1, j - 1, k );
1569 const label_type &l3 = l( i, j - 1, k );
1570 if( b( i, j, k ) != 0 )
1586 l( i, j, k ) = label;
1587 __he__::update( label, table );
1597 for(
size_t k = 1 ; k != b.depth( ) ; ++ k )
1603 const label_type &l9 = l( i, j, k - 1 );
1604 const label_type &l10 = l( i + 1, j, k - 1 );
1605 const label_type &l12 = l( i, j + 1, k - 1 );
1606 const label_type &l13 = l( i + 1, j + 1, k - 1 );
1607 if( b( i, j, k ) != 0 )
1627 l( i, j, k ) = label;
1628 __he__::update( label, table );
1636 for(
size_t i = 1 ; i != b.width( ) - 1 ; ++ i )
1638 const label_type &l1 = l( i - 1, j , k );
1639 const label_type &l8 = l( i - 1, j, k - 1 );
1640 const label_type &l9 = l( i, j, k - 1 );
1641 const label_type &l10 = l( i + 1, j, k - 1 );
1642 const label_type &l11 = l( i - 1, j + 1, k - 1 );
1643 const label_type &l12 = l( i, j + 1, k - 1 );
1644 const label_type &l13 = l( i + 1, j + 1, k - 1 );
1645 if( b( i, j, k ) != 0 )
1654 if( l10 != 0 && l12 == 0 )
1656 __he__::resolve( l1, l10, table );
1658 else if( l13 != 0 && l12 == 0 )
1660 __he__::resolve( l1, l13, table );
1666 if( l10 != 0 && l12 == 0 )
1668 __he__::resolve( l8, l10, table );
1670 else if( l13 != 0 && l12 == 0 )
1672 __he__::resolve( l8, l13, table );
1678 if( l11 != 0 && l12 == 0 )
1680 __he__::resolve( l10, l11, table );
1692 __he__::resolve( l11, l13, table );
1701 l( i, j, k ) = label;
1702 __he__::update( label, table );
1711 const size_t i = b.width( ) - 1;
1712 const label_type &l1 = l( i - 1, j , k );
1713 const label_type &l8 = l( i - 1, j, k - 1 );
1714 const label_type &l9 = l( i, j, k - 1 );
1715 const label_type &l11 = l( i - 1, j + 1, k - 1 );
1716 const label_type &l12 = l( i, j + 1, k - 1 );
1717 if( b( i, j, k ) != 0 )
1741 l( i, j, k ) = label;
1742 __he__::update( label, table );
1751 for(
size_t j = 1 ; j != b.height( ) - 1 ; ++ j )
1755 const label_type &l3 = l( i, j - 1, k );
1756 const label_type &l4 = l( i + 1, j - 1, k );
1757 const label_type &l6 = l( i, j - 1, k - 1 );
1758 const label_type &l7 = l( i + 1, j - 1, k - 1 );
1759 const label_type &l9 = l( i, j, k - 1 );
1760 const label_type &l10 = l( i + 1, j, k - 1 );
1761 const label_type &l12 = l( i, j + 1, k - 1 );
1762 const label_type &l13 = l( i + 1, j + 1, k - 1 );
1763 if( b( i, j, k ) != 0 )
1772 if( l12 != 0 && l10 == 0 )
1774 __he__::resolve( l3, l12, table );
1778 if( l13 != 0 && l10 == 0 )
1780 __he__::resolve( l3, l13, table );
1787 if( l12 != 0 && l10 == 0 )
1789 __he__::resolve( l6, l12, table );
1793 if( l13 != 0 && l10 == 0 )
1795 __he__::resolve( l6, l13, table );
1808 __he__::resolve( l12, l4, table );
1812 __he__::resolve( l12, l7, table );
1820 __he__::resolve( l4, l13, table );
1828 __he__::resolve( l7, l13, table );
1837 l( i, j, k ) = label;
1838 __he__::update( label, table );
1846 for(
size_t i = 1 ; i != b.width( ) - 1 ; ++ i )
1848 const label_type &l1 = l( i - 1, j , k );
1849 const label_type &l2 = l( i - 1, j - 1, k );
1850 const label_type &l3 = l( i, j - 1, k );
1851 const label_type &l4 = l( i + 1, j - 1, k );
1852 const label_type &l5 = l( i - 1, j - 1, k - 1 );
1853 const label_type &l6 = l( i, j - 1, k - 1 );
1854 const label_type &l7 = l( i + 1, j - 1, k - 1 );
1855 const label_type &l8 = l( i - 1, j, k - 1 );
1856 const label_type &l9 = l( i, j, k - 1 );
1857 const label_type &l10 = l( i + 1, j, k - 1 );
1858 const label_type &l11 = l( i - 1, j + 1, k - 1 );
1859 const label_type &l12 = l( i, j + 1, k - 1 );
1860 const label_type &l13 = l( i + 1, j + 1, k - 1 );
1861 if( b( i, j, k ) != 0 )
1870 if( l12 != 0 && l8 == 0 && l10 == 0 )
1872 __he__::resolve( l3, l12, table );
1876 if( l11 != 0 && l8 == 0 )
1878 __he__::resolve( l3, l11, table );
1880 if( l13 != 0 && l10 == 0 )
1882 __he__::resolve( l3, l13, table );
1889 if( l12 != 0 && l8 == 0 && l10 == 0 )
1891 __he__::resolve( l6, l12, table );
1895 if( l11 != 0 && l8 == 0 )
1897 __he__::resolve( l6, l11, table );
1899 if( l13 != 0 && l10 == 0 )
1901 __he__::resolve( l6, l13, table );
1908 if( l10 != 0 && l12 == 0 )
1910 __he__::resolve( l1, l10, table );
1914 __he__::resolve( l1, l7, table );
1917 __he__::resolve( l1, l13, table );
1922 __he__::resolve( l1, l4, table );
1925 __he__::resolve( l1, l13, table );
1928 else if( l13 != 0 && l12 == 0 )
1930 __he__::resolve( l1, l13, table );
1936 if( l10 != 0 && l12 == 0 )
1938 __he__::resolve( l8, l10, table );
1942 __he__::resolve( l8, l7, table );
1945 __he__::resolve( l8, l13, table );
1950 __he__::resolve( l8, l4, table );
1953 __he__::resolve( l8, l13, table );
1956 else if( l13 != 0 && l12 == 0 )
1958 __he__::resolve( l8, l13, table );
1964 if( l11 != 0 && l12 == 0 )
1966 __he__::resolve( l10, l11, table );
1970 __he__::resolve( l10, l5, table );
1974 __he__::resolve( l10, l2, table );
1982 __he__::resolve( l12, l4, table );
1986 __he__::resolve( l12, l7, table );
1990 __he__::resolve( l12, l2, table );
1994 __he__::resolve( l12, l5, table );
2002 __he__::resolve( l5, l4, table );
2006 __he__::resolve( l5, l7, table );
2010 __he__::resolve( l5, l11, table );
2014 __he__::resolve( l5, l13, table );
2022 __he__::resolve( l2, l4, table );
2026 __he__::resolve( l2, l7, table );
2030 __he__::resolve( l2, l11, table );
2034 __he__::resolve( l2, l13, table );
2042 __he__::resolve( l4, l11, table );
2046 __he__::resolve( l4, l13, table );
2054 __he__::resolve( l7, l11, table );
2058 __he__::resolve( l7, l13, table );
2066 __he__::resolve( l11, l13, table );
2075 l( i, j, k ) = label;
2076 __he__::update( label, table );
2085 const size_t i = b.width( ) - 1;
2086 const label_type &l1 = l( i - 1, j , k );
2087 const label_type &l2 = l( i - 1, j - 1, k );
2088 const label_type &l3 = l( i, j - 1, k );
2089 const label_type &l5 = l( i - 1, j - 1, k - 1 );
2090 const label_type &l6 = l( i, j - 1, k - 1 );
2091 const label_type &l8 = l( i - 1, j, k - 1 );
2092 const label_type &l9 = l( i, j, k - 1 );
2093 const label_type &l11 = l( i - 1, j + 1, k - 1 );
2094 const label_type &l12 = l( i, j + 1, k - 1 );
2095 if( b( i, j, k ) != 0 )
2104 if( l12 != 0 && l8 == 0 )
2106 __he__::resolve( l3, l12, table );
2110 if( l11 != 0 && l8 == 0 )
2112 __he__::resolve( l3, l11, table );
2119 if( l12 != 0 && l8 == 0 )
2121 __he__::resolve( l6, l12, table );
2125 if( l11 != 0 && l8 == 0 )
2127 __he__::resolve( l6, l11, table );
2144 __he__::resolve( l12, l2, table );
2148 __he__::resolve( l12, l5, table );
2156 __he__::resolve( l5, l11, table );
2164 __he__::resolve( l2, l11, table );
2173 l( i, j, k ) = label;
2174 __he__::update( label, table );
2184 const size_t j = b.height( ) - 1;
2187 const label_type &l3 = l( i, j - 1, k );
2188 const label_type &l4 = l( i + 1, j - 1, k );
2189 const label_type &l6 = l( i, j - 1, k - 1 );
2190 const label_type &l7 = l( i + 1, j - 1, k - 1 );
2191 const label_type &l9 = l( i, j, k - 1 );
2192 const label_type &l10 = l( i + 1, j, k - 1 );
2193 if( b( i, j, k ) != 0 )
2221 l( i, j, k ) = label;
2222 __he__::update( label, table );
2230 for(
size_t i = 1 ; i != b.width( ) - 1 ; ++ i )
2232 const label_type &l1 = l( i - 1, j , k );
2233 const label_type &l2 = l( i - 1, j - 1, k );
2234 const label_type &l3 = l( i, j - 1, k );
2235 const label_type &l4 = l( i + 1, j - 1, k );
2236 const label_type &l5 = l( i - 1, j - 1, k - 1 );
2237 const label_type &l6 = l( i, j - 1, k - 1 );
2238 const label_type &l7 = l( i + 1, j - 1, k - 1 );
2239 const label_type &l8 = l( i - 1, j, k - 1 );
2240 const label_type &l9 = l( i, j, k - 1 );
2241 const label_type &l10 = l( i + 1, j, k - 1 );
2242 if( b( i, j, k ) != 0 )
2261 __he__::resolve( l1, l10, table );
2265 __he__::resolve( l1, l7, table );
2269 __he__::resolve( l1, l4, table );
2277 __he__::resolve( l8, l10, table );
2281 __he__::resolve( l8, l7, table );
2285 __he__::resolve( l8, l4, table );
2293 __he__::resolve( l10, l5, table );
2297 __he__::resolve( l10, l2, table );
2305 __he__::resolve( l5, l4, table );
2309 __he__::resolve( l5, l7, table );
2317 __he__::resolve( l2, l4, table );
2321 __he__::resolve( l2, l7, table );
2334 l( i, j, k ) = label;
2335 __he__::update( label, table );
2344 const size_t i = b.width( ) - 1;
2345 const label_type &l1 = l( i - 1, j , k );
2346 const label_type &l2 = l( i - 1, j - 1, k );
2347 const label_type &l3 = l( i, j - 1, k );
2348 const label_type &l5 = l( i - 1, j - 1, k - 1 );
2349 const label_type &l6 = l( i, j - 1, k - 1 );
2350 const label_type &l8 = l( i - 1, j, k - 1 );
2351 const label_type &l9 = l( i, j, k - 1 );
2352 if( b( i, j, k ) != 0 )
2384 l( i, j, k ) = label;
2385 __he__::update( label, table );
2397 for(
size_t i = 1 ; i != label ; ++ i )
2399 if( l_table[ table[ i ].label ] == 0 )
2402 l_table[ table[ i ].label ] = ret;
2405 for(
size_t i = 0 ; i != l.size( ) ; ++ i )
2407 l[ i ] = l_table[ table[ l[ i ] ].label ];
2422 #endif // __INCLUDE_MIST_LABELING__