3 #include "bbtkAtomicBlackBox.h"
4 #include "itkBinaryThresholdImageFilter.h"
5 #include "bbitkImage.h"
11 class /*BBTK_EXPORT*/ BinaryThresholdImageFilter
13 public bbtk::AtomicBlackBox,
14 public itk::BinaryThresholdImageFilter<T,T>
16 BBTK_USER_BLACK_BOX_INTERFACE(BinaryThresholdImageFilter,
17 bbtk::AtomicBlackBox);
18 typedef itk::BinaryThresholdImageFilter<T,T> itkParent;
19 BBTK_DECLARE_ITK_INPUT(itkParent,In,const T*);
20 BBTK_DECLARE_ITK_PARAM(itkParent,LowerThreshold,typename T::PixelType);
21 BBTK_DECLARE_ITK_PARAM(itkParent,UpperThreshold,typename T::PixelType);
22 BBTK_DECLARE_ITK_PARAM(itkParent,InsideValue,typename T::PixelType);
23 BBTK_DECLARE_ITK_PARAM(itkParent,OutsideValue,typename T::PixelType);
24 BBTK_DECLARE_ITK_OUTPUT(itkParent,Out,T*);
25 BBTK_PROCESS(itkParent::Update);
26 void bbDelete() { itkParent::UnRegister(); }
28 void bbUserConstructor() { Init(); }
29 void bbUserCopyConstructor() { Init(); }
34 BBTK_BEGIN_DESCRIBE_TEMPLATE_BLACK_BOX(BinaryThresholdImageFilter);
35 BBTK_NAME("BinaryThresholdImageFilter<"+bbtk::TypeName<T>()+">");
36 BBTK_AUTHOR("laurent.guigues@creatis.insa-lyon.fr");
37 BBTK_DESCRIPTION("Binarizes an image by thresholding (bbification of itk::BinaryThresholdImageFilter)");
38 BBTK_TEMPLATE_INPUT(BinaryThresholdImageFilter,In,"Input image",const T*);
39 BBTK_TEMPLATE_INPUT(BinaryThresholdImageFilter,LowerThreshold,
40 "Lower threshold",typename T::PixelType);
41 BBTK_TEMPLATE_INPUT(BinaryThresholdImageFilter,UpperThreshold,
42 "Upper threshold",typename T::PixelType);
43 BBTK_TEMPLATE_INPUT(BinaryThresholdImageFilter,InsideValue,
44 "Output value for pixels inside thresholds",
45 typename T::PixelType);
46 BBTK_TEMPLATE_INPUT(BinaryThresholdImageFilter,OutsideValue,
47 "Output value for pixels outside thresholds",
48 typename T::PixelType);
49 BBTK_TEMPLATE_OUTPUT(BinaryThresholdImageFilter,Out,"Output image",T*);
50 BBTK_END_DESCRIBE_TEMPLATE_BLACK_BOX(BinaryThresholdImageFilter);
52 //===================================================
53 // Generic "untemplatized" filter
54 //===================================================
55 class /*BBTK_EXPORT*/ BinaryThresholdImageFilterGeneric
57 public bbtk::AtomicBlackBox
59 BBTK_USER_BLACK_BOX_INTERFACE(BinaryThresholdImageFilterGeneric,
60 bbtk::AtomicBlackBox);
61 BBTK_DECLARE_INPUT(In,anyImagePointer);
62 BBTK_DECLARE_INPUT(LowerThreshold,double);
63 BBTK_DECLARE_INPUT(UpperThreshold,double);
64 BBTK_DECLARE_INPUT(InsideValue,double);
65 BBTK_DECLARE_INPUT(OutsideValue,double);
66 BBTK_DECLARE_OUTPUT(Out,anyImagePointer);
67 BBTK_PROCESS(ProcessSwitch);
69 inline void ProcessSwitch();
70 template <class T> void Process();
71 void bbUserConstructor() { Init(); }
72 void bbUserCopyConstructor() { Init(); }
76 BBTK_BEGIN_DESCRIBE_BLACK_BOX(BinaryThresholdImageFilterGeneric,
77 bbtk::AtomicBlackBox);
78 BBTK_NAME("BinaryThresholdImageFilter");
79 BBTK_AUTHOR("laurent.guigues at creatis.insa-lyon.fr");
80 BBTK_CATEGORY("filter;image");
81 BBTK_DESCRIPTION("Binarizes an image by thresholding (generic bbification of itk::BinaryThresholdImageFilter)");
82 BBTK_INPUT(BinaryThresholdImageFilterGeneric,In,
83 "Input image. Can be any itk::Image<T,D>*",anyImagePointer);
84 BBTK_INPUT(BinaryThresholdImageFilterGeneric,LowerThreshold,
85 "Lower threshold",double);
86 BBTK_INPUT(BinaryThresholdImageFilterGeneric,UpperThreshold,
87 "Upper threshold",double);
88 BBTK_INPUT(BinaryThresholdImageFilterGeneric,InsideValue,
89 "Output value for pixels inside thresholds",double);
90 BBTK_INPUT(BinaryThresholdImageFilterGeneric,OutsideValue,
91 "Output value for pixels outside thresholds",double);
92 BBTK_OUTPUT(BinaryThresholdImageFilterGeneric,Out,
93 "Output image. Of the same type and dimension than the input image",
95 BBTK_END_DESCRIBE_BLACK_BOX(BinaryThresholdImageFilterGeneric);
99 void BinaryThresholdImageFilterGeneric::ProcessSwitch()
101 BBTK_TEMPLATE_ITK_IMAGE_SWITCH(bbGetInputIn().type(), this->Process);
105 void BinaryThresholdImageFilterGeneric::Process()
107 bbtkDebugMessageInc("Core",9,
108 "bbitk::BinaryThresholdImageFilterGeneric::Process<"
109 <<bbtk::TypeName<T>()<<">()"<<std::endl);
111 typedef BinaryThresholdImageFilter<T> FilterType;
112 FilterType* f = FilterType::bbNew("Temp");
113 f->bbSetInputIn( this->bbGetInputIn().get<T*>());
114 f->bbSetInputLowerThreshold ( (typename T::PixelType)
115 this->bbGetInputLowerThreshold() );
116 f->bbSetInputUpperThreshold ( (typename T::PixelType)
117 this->bbGetInputUpperThreshold() );
118 f->bbSetInputInsideValue ( (typename T::PixelType)
119 this->bbGetInputInsideValue() );
120 f->bbSetInputOutsideValue ( (typename T::PixelType)
121 this->bbGetInputOutsideValue() );
123 f->bbGetOutputOut()->Register();
124 this->bbSetOutputOut( f->bbGetOutputOut() );
126 bbtkDebugDecTab("Core",9);
130 void BinaryThresholdImageFilter<T>::Init()
132 bbSetInputLowerThreshold(0);
133 bbSetInputUpperThreshold(100);
134 bbSetInputInsideValue(255);
135 bbSetInputOutsideValue(0);
138 void BinaryThresholdImageFilterGeneric::Init()
140 bbSetInputLowerThreshold(0);
141 bbSetInputUpperThreshold(100);
142 bbSetInputInsideValue(255);
143 bbSetInputOutsideValue(0);