37 #ifndef AIMS_UTILITY_THRESHOLD_H 38 #define AIMS_UTILITY_THRESHOLD_H 93 template <
class T,
class U>
130 template <
class T,
class U>
158 template <
class T,
class U>
inline 165 template <
class T,
class U>
inline 175 template <
typename LEFT,
typename OP>
176 struct thresh1:
public std::unary_function<LEFT, LEFT>
179 :
std::unary_function<LEFT, LEFT>(), threshold( threshold ),
180 background( background )
186 return OP()( x, threshold ) ? x : background;
194 template <
typename T>
197 bool operator() (
const T & x,
const T & y,
const T & z)
const 199 return x >= y && x <= z;
204 template <
typename T>
207 bool operator() (
const T & x,
const T & y,
const T & z)
const 209 return x > y && x <= z;
214 template <
typename T>
217 bool operator() (
const T & x,
const T & y,
const T & z)
const 219 return x >= y && x < z;
224 template <
typename T>
227 bool operator() (
const T & x,
const T & y,
const T & z)
const 229 return x > y && x < z;
234 template <
typename T>
237 bool operator() (
const T & x,
const T & y,
const T & z)
const 239 return x <= y || x >= z;
244 template <
typename T>
247 bool operator() (
const T & x,
const T & y,
const T & z)
const 249 return x < y || x >= z;
254 template <
typename T>
257 bool operator() (
const T & x,
const T & y,
const T & z)
const 259 return x <= y || x > z;
264 template <
typename T>
267 bool operator() (
const T & x,
const T & y,
const T & z)
const 269 return x < y || x > z;
274 template <
typename LEFT,
typename OP>
275 struct thresh2:
public std::unary_function<LEFT, LEFT>
277 thresh2( LEFT threshold1, LEFT threshold2, LEFT background )
278 :
std::unary_function<LEFT, LEFT>(), threshold1( threshold1 ),
279 threshold2( threshold2), background( background )
285 return OP()( x, threshold1, threshold2 ) ? x : background;
295 template <
class T,
class U>
inline 301 res.setSizeY(sqv.
sizeY());
302 res.setSizeZ(sqv.
sizeZ());
303 res.setSizeT(sqv.
sizeT());
313 *sqv.
volume(), *res.volume(),
318 *sqv.
volume(), *res.volume(),
324 *sqv.
volume(), *res.volume(),
330 *sqv.
volume(), *res.volume(),
336 *sqv.
volume(), *res.volume(),
342 *sqv.
volume(), *res.volume(),
348 *sqv.
volume(), *res.volume(),
354 *sqv.
volume(), *res.volume(),
360 *sqv.
volume(), *res.volume(),
366 *sqv.
volume(), *res.volume(),
372 *sqv.
volume(), *res.volume(),
378 *sqv.
volume(), *res.volume(),
384 *sqv.
volume(), *res.volume(),
390 *sqv.
volume(), *res.volume(),
410 template <
typename LEFT,
typename OP>
411 struct clip1:
public std::unary_function<LEFT, LEFT>
414 :
std::unary_function<LEFT, LEFT>(), threshold( threshold )
420 return OP()( x, threshold ) ? x : threshold;
427 template <
typename T>
434 return x <= z ? 0 : 1;
439 template <
typename T>
446 return x <= z ? 0 : 1;
451 template <
typename T>
458 return x < z ? 0 : 1;
463 template <
typename T>
470 return x < z ? 0 : 1;
475 template <
typename LEFT,
typename OP>
476 struct clip2:
public std::unary_function<LEFT, LEFT>
478 clip2( LEFT threshold1, LEFT threshold2 )
479 :
std::unary_function<LEFT, LEFT>(), threshold1( threshold1 ),
480 threshold2( threshold2)
486 switch( OP()( x, threshold1, threshold2 ) )
504 template <
class T,
class U>
inline 510 res.setSizeY(sqv.
sizeY());
511 res.setSizeZ(sqv.
sizeZ());
512 res.setSizeT(sqv.
sizeT());
522 *sqv.
volume(), *res.volume(),
527 *sqv.
volume(), *res.volume(),
532 *sqv.
volume(), *res.volume(),
537 *sqv.
volume(), *res.volume(),
542 *sqv.
volume(), *res.volume(),
548 *sqv.
volume(), *res.volume(),
554 *sqv.
volume(), *res.volume(),
560 *sqv.
volume(), *res.volume(),
572 std::cerr <<
"Warning: AimsThreshold cannot use clipping with this mode, " 573 "using standard clipping instead." << std::endl;
588 template <
class T,
class U>
inline 592 unsigned i, n = sqv.
nItem(), t , tm = sqv.size();
597 for (t = 0; t < tm ; ++t)
598 for (i = 0; i < n ; ++i)
603 for (t = 0; t < tm ; ++t)
604 for (i = 0; i < n ; ++i)
609 for (t = 0; t < tm ; ++t)
610 for (i = 0; i < n ; ++i)
615 for (t = 0; t < tm ; ++t)
616 for (i = 0; i < n ; ++i)
621 for (t = 0; t < tm ; ++t)
622 for (i = 0; i < n ; ++i)
627 for (t = 0; t < tm ; ++t)
628 for (i = 0; i < n ; ++i)
633 for (t = 0; t < tm ; ++t)
634 for (i = 0; i < n ; ++i)
639 for (t = 0; t < tm ; ++t)
640 for (i = 0; i < n ; ++i)
645 for (t = 0; t < tm ; ++t)
646 for (i = 0; i < n ; ++i)
651 for (t = 0; t < tm ; ++t)
652 for (i = 0; i < n ; ++i)
657 for (t = 0; t < tm ; ++t)
658 for (i = 0; i < n ; ++i)
663 for (t = 0; t < tm ; ++t)
664 for (i = 0; i < n ; ++i)
669 for (t = 0; t < tm ; ++t)
670 for (i = 0; i < n ; ++i)
675 for (t = 0; t < tm ; ++t)
676 for (i = 0; i < n ; ++i)
699 template <
typename LEFT,
typename RIGHT,
typename OP>
703 :
std::unary_function<LEFT, RIGHT>(), threshold( threshold ),
704 foreground( foreground )
710 return OP()( x, threshold ) ? foreground : 0;
718 template <
typename LEFT,
typename RIGHT,
typename OP>
722 :
std::unary_function<LEFT, RIGHT>(), threshold1( threshold1 ),
723 threshold2( threshold2 ), foreground( foreground )
729 return OP()( x, threshold1, threshold2 ) ? foreground : 0;
739 template <
class T,
class U>
inline 745 res.setSizeY(sqv.
sizeY());
746 res.setSizeZ(sqv.
sizeZ());
747 res.setSizeT(sqv.
sizeT());
759 *sqv.
volume(), *res.volume(),
765 *sqv.
volume(), *res.volume(),
771 *sqv.
volume(), *res.volume(),
777 *sqv.
volume(), *res.volume(),
783 *sqv.
volume(), *res.volume(),
789 *sqv.
volume(), *res.volume(),
795 *sqv.
volume(), *res.volume(),
801 *sqv.
volume(), *res.volume(),
807 *sqv.
volume(), *res.volume(),
813 *sqv.
volume(), *res.volume(),
819 *sqv.
volume(), *res.volume(),
825 *sqv.
volume(), *res.volume(),
831 *sqv.
volume(), *res.volume(),
837 *sqv.
volume(), *res.volume(),
854 template <
class T,
class U>
inline 857 unsigned i, n = sqv.
nItem(), t , tm = sqv.size();
863 for (t = 0; t < tm ; ++t)
864 for (i = 0; i < n ; ++i)
865 if ( temp[t].item( i ) <
_level)
872 for (t = 0; t < tm ; ++t)
873 for (i = 0; i < n ; ++i)
874 if ( temp[t].item( i ) <=
_level)
880 for (t = 0; t < tm ; ++t)
881 for (i = 0; i < n ; ++i)
882 if ( temp[t].item( i ) >
_level)
888 for (t = 0; t < tm ; ++t)
889 for (i = 0; i < n ; ++i)
890 if ( temp[t].item( i ) >=
_level)
896 for (t = 0; t < tm ; ++t)
897 for (i = 0; i < n ; ++i)
898 if ( temp[t].item( i ) ==
_level)
904 for (t = 0; t < tm ; ++t)
905 for (i = 0; i < n ; ++i)
906 if ( temp[t].item( i ) !=
_level)
912 for (t = 0; t < tm ; ++t)
913 for (i = 0; i < n ; ++i)
914 if ( temp[t].item( i ) >=
_level 915 && temp[t].item( i ) <=
_level2 )
921 for (t = 0; t < tm ; ++t)
922 for (i = 0; i < n ; ++i)
923 if ( temp[t].item( i ) >
_level 924 && temp[t].item( i ) <=
_level2 )
930 for (t = 0; t < tm ; ++t)
931 for (i = 0; i < n ; ++i)
932 if ( temp[t].item( i ) >=
_level 933 && temp[t].item( i ) <
_level2 )
939 for (t = 0; t < tm ; ++t)
940 for (i = 0; i < n ; ++i)
941 if ( temp[t].item( i ) >
_level 942 && temp[t].item( i ) <
_level2 )
948 for (t = 0; t < tm ; ++t)
949 for (i = 0; i < n ; ++i)
950 if ( temp[t].item( i ) <
_level 951 && temp[t].item( i ) >
_level2 )
957 for (t = 0; t < tm ; ++t)
958 for (i = 0; i < n ; ++i)
959 if ( temp[t].item( i ) <=
_level 960 && temp[t].item( i ) >
_level2 )
966 for (t = 0; t < tm ; ++t)
967 for (i = 0; i < n ; ++i)
968 if ( temp[t].item( i ) <
_level 969 && temp[t].item( i ) >=
_level2 )
975 for (t = 0; t < tm ; ++t)
976 for (i = 0; i < n ; ++i)
977 if ( temp[t].item( i ) <=
_level 978 && temp[t].item( i ) >=
_level2 )
const T * const_iterator
basic constant iterator
void push_back(const T &item)
T _level
Lower level or unique level.
T * iterator
basic iterator
AimsThreshold(threshold_t type, T level, T level2=0, T backgd=0, U foregd=(U)(!std::numeric_limits< U >::is_specialized||(std::numeric_limits< U >::max() >=32767) ? 32767 :std::numeric_limits< U >::max()))
Volume thresholding.
clip2(LEFT threshold1, LEFT threshold2)
threshold_t _type
Threshold type.
thresh1(LEFT threshold, LEFT background)
void setSizeX(float sizex)
virtual bool removeProperty(const std::string &)
TimeTexture< T > operator()(const TimeTexture< T > &sqv)
Return the multi-level thresholded texture.
T _level
Lower level or unique level.
const T & item(int n) const
AimsData< T > clip(const AimsData< T > &sqv)
Return the multi-level thresholded image with clipped values (backgd ignored)
thresh2(LEFT threshold1, LEFT threshold2, LEFT background)
thresh2_bin(LEFT threshold1, LEFT threshold2, RIGHT foreground)
threshold_t _type
Threshold type.
AimsData< U > bin(const AimsData< T > &sqv)
Return the binary thresholded image.
const aims::Header * header() const
The template class to make thresholds.
carto::rc_ptr< carto::Volume< T > > volume()
AimsData< T > operator()(const AimsData< T > &sqv)
Return the multi-level thresholded image.
virtual ~AimsTexThreshold()
Volume< OUTP > & applyTowards(const Volume< T > &vol, Volume< OUTP > &dst, UnaryFunction func)
AimsTexThreshold(threshold_t type, T level, T level2=0, T backgd=0)
Texture thresholding.
virtual bool hasProperty(const std::string &) const
thresh1_bin(LEFT threshold, RIGHT foreground)
TimeTexture< U > bin(const TimeTexture< T > &sqv)
Return the binary thresholded texture.
int borderWidth() const
Usefull offsets for A.I.M.S.