ITK
4.1.0
Insight Segmentation and Registration Toolkit
|
00001 /*========================================================================= 00002 * 00003 * Copyright Insight Software Consortium 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0.txt 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 * 00017 *=========================================================================*/ 00018 #ifndef __itkBinaryThresholdProjectionImageFilter_h 00019 #define __itkBinaryThresholdProjectionImageFilter_h 00020 00021 #include "itkProjectionImageFilter.h" 00022 #include "itkConceptChecking.h" 00023 00024 namespace itk 00025 { 00049 namespace Function 00050 { 00051 template< class TInputPixel, class TOutputPixel > 00052 class BinaryThresholdAccumulator 00053 { 00054 public: 00055 BinaryThresholdAccumulator(SizeValueType) {} 00056 ~BinaryThresholdAccumulator(){} 00057 00058 inline void Initialize() 00059 { 00060 m_IsForeground = false; 00061 } 00062 00063 inline void operator()(const TInputPixel & input) 00064 { 00065 if ( input >= m_ThresholdValue ) 00066 { 00067 m_IsForeground = true; 00068 } 00069 } 00070 00071 inline TOutputPixel GetValue() 00072 { 00073 if ( m_IsForeground ) 00074 { 00075 return (TOutputPixel)m_ForegroundValue; 00076 } 00077 else 00078 { 00079 return m_BackgroundValue; 00080 } 00081 } 00082 00083 bool m_IsForeground; 00084 00085 TInputPixel m_ThresholdValue; 00086 TInputPixel m_ForegroundValue; 00087 TOutputPixel m_BackgroundValue; 00088 }; 00089 } // end namespace Function 00090 00091 template< class TInputImage, class TOutputImage > 00092 class ITK_EXPORT BinaryThresholdProjectionImageFilter: 00093 public ProjectionImageFilter< TInputImage, TOutputImage, 00094 Function::BinaryThresholdAccumulator< 00095 typename TInputImage::PixelType, 00096 typename TOutputImage::PixelType > > 00097 { 00098 public: 00099 typedef BinaryThresholdProjectionImageFilter Self; 00100 typedef ProjectionImageFilter< TInputImage, TOutputImage, 00101 Function::BinaryThresholdAccumulator< 00102 typename TInputImage::PixelType, 00103 typename TOutputImage::PixelType > > Superclass; 00104 00105 typedef SmartPointer< Self > Pointer; 00106 typedef SmartPointer< const Self > ConstPointer; 00107 00109 itkTypeMacro(BinaryThresholdProjectionImageFilter, ProjectionImageFilter); 00110 00112 itkNewMacro(Self); 00113 00115 typedef TInputImage InputImageType; 00116 typedef TOutputImage OutputImageType; 00117 00119 typedef typename InputImageType::PixelType InputPixelType; 00120 typedef typename OutputImageType::PixelType OutputPixelType; 00121 00122 typedef typename Superclass::AccumulatorType AccumulatorType; 00123 00126 itkSetMacro(ForegroundValue, InputPixelType); 00127 itkGetConstMacro(ForegroundValue, InputPixelType); 00129 00132 itkSetMacro(BackgroundValue, OutputPixelType); 00133 itkGetConstMacro(BackgroundValue, OutputPixelType); 00135 00138 itkSetMacro(ThresholdValue, InputPixelType); 00139 itkGetConstMacro(ThresholdValue, InputPixelType); 00141 00142 #ifdef ITK_USE_CONCEPT_CHECKING 00143 00144 itkConceptMacro( InputPixelTypeGreaterThanComparable, 00145 ( Concept::GreaterThanComparable< InputPixelType > ) ); 00146 itkConceptMacro( InputHasNumericTraitsCheck, 00147 ( Concept::HasNumericTraits< InputPixelType > ) ); 00148 00150 #endif 00151 protected: 00152 BinaryThresholdProjectionImageFilter() 00153 { 00154 m_ForegroundValue = NumericTraits< InputPixelType >::max(); 00155 m_BackgroundValue = NumericTraits< OutputPixelType >::NonpositiveMin(); 00156 m_ThresholdValue = NumericTraits< InputPixelType >::Zero; 00157 } 00159 00160 virtual ~BinaryThresholdProjectionImageFilter() {} 00161 00162 void PrintSelf(std::ostream & os, Indent indent) const 00163 { 00164 Superclass::PrintSelf(os, indent); 00165 00166 typedef typename NumericTraits< InputPixelType >::PrintType 00167 InputPixelPrintType; 00168 00169 os << indent << "ForegroundValue: " 00170 << static_cast< InputPixelPrintType >( m_ForegroundValue ) 00171 << std::endl; 00172 00173 typedef typename NumericTraits< OutputPixelType >::PrintType 00174 OutputPixelPrintType; 00175 00176 os << indent << "BackgroundValue: " 00177 << static_cast< OutputPixelPrintType >( m_BackgroundValue ) 00178 << std::endl; 00179 00180 os << indent << "ThresholdValue: " 00181 << static_cast< InputPixelPrintType >( m_ThresholdValue ) 00182 << std::endl; 00183 } 00184 00185 virtual AccumulatorType NewAccumulator(SizeValueType size) const 00186 { 00187 AccumulatorType accumulator(size); 00188 00189 accumulator.m_ForegroundValue = m_ForegroundValue; 00190 accumulator.m_BackgroundValue = m_BackgroundValue; 00191 accumulator.m_ThresholdValue = m_ThresholdValue; 00192 return accumulator; 00193 } 00194 00196 InputPixelType m_ForegroundValue; 00197 00199 OutputPixelType m_BackgroundValue; 00200 00202 OutputPixelType m_ThresholdValue; 00203 private: 00204 //purposely not implemented 00205 BinaryThresholdProjectionImageFilter(const Self &); 00206 void operator=(const Self &); 00207 }; // end BinaryThresholdProjectionImageFilter 00208 } //end namespace itk 00210 00211 #endif 00212