1 /*=========================================================================
3 Module: $RCSfile: bbitkBinaryThresholdImageFilter.h,v $
5 Date: $Date: 2008/11/25 11:17:15 $
6 Version: $Revision: 1.10 $
7 =========================================================================*/
9 /* ---------------------------------------------------------------------
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
14 * This software is governed by the CeCILL-B license under French law and
15 * abiding by the rules of distribution of free software. You can use,
16 * modify and/ or redistribute the software under the terms of the CeCILL-B
17 * license as circulated by CEA, CNRS and INRIA at the following URL
18 * http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
19 * or in the file LICENSE.txt.
21 * As a counterpart to the access to the source code and rights to copy,
22 * modify and redistribute granted by the license, users are provided only
23 * with a limited warranty and the software's author, the holder of the
24 * economic rights, and the successive licensors have only limited
27 * The fact that you are presently reading this means that you have had
28 * knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */
34 #include "bbtkAtomicBlackBox.h"
35 #include "itkBinaryThresholdImageFilter.h"
36 #include "bbtkItkBlackBoxMacros.h"
37 #include "bbitkImage.h"
43 class /*BBTK_EXPORT*/ BinaryThresholdImageFilter
45 public bbtk::AtomicBlackBox,
46 public itk::BinaryThresholdImageFilter<T,T>
48 BBTK_TEMPLATE_BLACK_BOX_INTERFACE(BinaryThresholdImageFilter,
49 bbtk::AtomicBlackBox,T);
50 typedef itk::BinaryThresholdImageFilter<T,T> itkParent;
51 BBTK_DECLARE_ITK_INPUT(In,const T*);
52 BBTK_DECLARE_ITK_PARAM(LowerThreshold,typename T::PixelType);
53 BBTK_DECLARE_ITK_PARAM(UpperThreshold,typename T::PixelType);
54 BBTK_DECLARE_ITK_PARAM(InsideValue,typename T::PixelType);
55 BBTK_DECLARE_ITK_PARAM(OutsideValue,typename T::PixelType);
56 BBTK_DECLARE_ITK_OUTPUT(Out,T*);
60 void bbUserConstructor() { Init(); }
61 void bbUserCopyConstructor(bbtk::BlackBox::Pointer) { Init(); }
66 BBTK_BEGIN_DESCRIBE_TEMPLATE_BLACK_BOX(BinaryThresholdImageFilter,
67 bbtk::AtomicBlackBox);
68 BBTK_NAME("BinaryThresholdImageFilter<"+bbtk::TypeName<T>()+">");
69 BBTK_AUTHOR("laurent.guigues@creatis.insa-lyon.fr");
70 BBTK_DESCRIPTION("Binarizes an image by thresholding (bbification of itk::BinaryThresholdImageFilter)");
71 BBTK_TEMPLATE_INPUT(BinaryThresholdImageFilter,In,"Input image",const T*);
72 BBTK_TEMPLATE_INPUT(BinaryThresholdImageFilter,LowerThreshold,
73 "Lower threshold",typename T::PixelType);
74 BBTK_TEMPLATE_INPUT(BinaryThresholdImageFilter,UpperThreshold,
75 "Upper threshold",typename T::PixelType);
76 BBTK_TEMPLATE_INPUT(BinaryThresholdImageFilter,InsideValue,
77 "Output value for pixels inside thresholds",
78 typename T::PixelType);
79 BBTK_TEMPLATE_INPUT(BinaryThresholdImageFilter,OutsideValue,
80 "Output value for pixels outside thresholds",
81 typename T::PixelType);
82 BBTK_TEMPLATE_OUTPUT(BinaryThresholdImageFilter,Out,"Output image",T*);
83 BBTK_END_DESCRIBE_TEMPLATE_BLACK_BOX(BinaryThresholdImageFilter);
85 //===================================================
86 // Generic "untemplatized" filter
87 //===================================================
88 class /*BBTK_EXPORT*/ BinaryThresholdImageFilterGeneric
90 public bbtk::AtomicBlackBox
92 BBTK_BLACK_BOX_INTERFACE(BinaryThresholdImageFilterGeneric,
93 bbtk::AtomicBlackBox);
94 BBTK_DECLARE_INPUT(In,anyImagePointer);
95 BBTK_DECLARE_INPUT(LowerThreshold,double);
96 BBTK_DECLARE_INPUT(UpperThreshold,double);
97 BBTK_DECLARE_INPUT(InsideValue,double);
98 BBTK_DECLARE_INPUT(OutsideValue,double);
99 BBTK_DECLARE_OUTPUT(Out,anyImagePointer);
100 BBTK_PROCESS(ProcessSwitch);
102 inline void ProcessSwitch();
103 template <class T> void Process();
104 void bbUserConstructor() { Init(); }
105 void bbUserCopyConstructor(bbtk::BlackBox::Pointer) { Init(); }
109 BBTK_BEGIN_DESCRIBE_BLACK_BOX(BinaryThresholdImageFilterGeneric,
110 bbtk::AtomicBlackBox);
111 BBTK_NAME("BinaryThresholdImageFilter");
112 BBTK_AUTHOR("laurent.guigues at creatis.insa-lyon.fr");
113 BBTK_CATEGORY("filter;image");
114 BBTK_DESCRIPTION("Binarizes an image by thresholding (generic bbification of itk::BinaryThresholdImageFilter)");
115 BBTK_INPUT(BinaryThresholdImageFilterGeneric,In,
116 "Input image. Can be any itk::Image<T,D>*",anyImagePointer,"");
117 BBTK_INPUT(BinaryThresholdImageFilterGeneric,LowerThreshold,
118 "Lower threshold",double,"");
119 BBTK_INPUT(BinaryThresholdImageFilterGeneric,UpperThreshold,
120 "Upper threshold",double,"");
121 BBTK_INPUT(BinaryThresholdImageFilterGeneric,InsideValue,
122 "Output value for pixels inside thresholds",double,"");
123 BBTK_INPUT(BinaryThresholdImageFilterGeneric,OutsideValue,
124 "Output value for pixels outside thresholds",double,"");
125 BBTK_OUTPUT(BinaryThresholdImageFilterGeneric,Out,
126 "Output image. Of the same type and dimension than the input image",
128 BBTK_END_DESCRIBE_BLACK_BOX(BinaryThresholdImageFilterGeneric);
132 void BinaryThresholdImageFilterGeneric::ProcessSwitch()
134 BBTK_TEMPLATE_ITK_IMAGE_SWITCH(bbGetInputIn().type(), this->Process);
138 void BinaryThresholdImageFilterGeneric::Process()
140 bbtkDebugMessageInc("Core",9,
141 "bbitk::BinaryThresholdImageFilterGeneric::Process<"
142 <<bbtk::TypeName<T>()<<">()"<<std::endl);
144 typedef BinaryThresholdImageFilter<T> FilterType;
145 typename FilterType::Pointer f = FilterType::New("Temp");
147 f->bbSetInputIn( this->bbGetInputIn().get < TPointer > ());
148 f->bbSetInputLowerThreshold ( (typename T::PixelType)
149 this->bbGetInputLowerThreshold() );
150 f->bbSetInputUpperThreshold ( (typename T::PixelType)
151 this->bbGetInputUpperThreshold() );
152 f->bbSetInputInsideValue ( (typename T::PixelType)
153 this->bbGetInputInsideValue() );
154 f->bbSetInputOutsideValue ( (typename T::PixelType)
155 this->bbGetInputOutsideValue() );
157 f->bbGetOutputOut()->Register();
158 this->bbSetOutputOut( f->bbGetOutputOut() );
160 bbtkDebugDecTab("Core",9);
164 void BinaryThresholdImageFilter<T>::Init()
166 bbSetInputLowerThreshold(0);
167 bbSetInputUpperThreshold(100);
168 bbSetInputInsideValue(255);
169 bbSetInputOutsideValue(0);
172 void BinaryThresholdImageFilterGeneric::Init()
174 bbSetInputLowerThreshold(0);
175 bbSetInputUpperThreshold(100);
176 bbSetInputInsideValue(255);
177 bbSetInputOutsideValue(0);