]> Creatis software - clitk.git/blob - itk/clitkLocallyAdaptiveThresholdConnectedImageFilter.txx
With ITK 5, add itkReadRawBytesAfterSwappingMacro and itkWriteRawBytesAfterSwappingMacro
[clitk.git] / itk / clitkLocallyAdaptiveThresholdConnectedImageFilter.txx
1 /*=========================================================================
2   Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
3
4   Authors belong to: 
5   - University of LYON              http://www.universite-lyon.fr/
6   - Léon Bérard cancer center       http://www.centreleonberard.fr
7   - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
8
9   This software is distributed WITHOUT ANY WARRANTY; without even
10   the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11   PURPOSE.  See the copyright notices for more information.
12
13   It is distributed under dual licence
14
15   - BSD        See included LICENSE.txt file
16   - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ===========================================================================**/
18 #ifndef __clitkLocallyAdaptiveThresholdConnectedImageFilter_txx
19 #define __clitkLocallyAdaptiveThresholdConnectedImageFilter_txx
20 #include "clitkLocallyAdaptiveThresholdConnectedImageFilter.h"
21 #include "clitkLocallyAdaptiveBinaryThresholdImageFunction.h"
22 #include "itkFloodFilledImageFunctionConditionalIterator.h"
23 #include "itkProgressReporter.h"
24
25 namespace clitk
26 {
27
28 /**
29  * Constructor
30  */
31 template <class TInputImage, class TOutputImage>
32 LocallyAdaptiveThresholdConnectedImageFilter<TInputImage, TOutputImage>
33 ::LocallyAdaptiveThresholdConnectedImageFilter()
34 {
35   m_Lower = itk::NumericTraits<InputImagePixelType>::NonpositiveMin();
36   m_Upper = itk::NumericTraits<InputImagePixelType>::max();
37   m_LowerBorderIsGiven=true;
38   m_UpperBorderIsGiven=true;
39   m_MaximumSDIsGiven=true;
40   m_Multiplier=1.0;
41   m_ReplaceValue = itk::NumericTraits<OutputImagePixelType>::One;
42   m_Radius.Fill(1);
43   m_MaximumSD=100.0;
44 }
45
46 template <class TInputImage, class TOutputImage>
47 void
48 LocallyAdaptiveThresholdConnectedImageFilter<TInputImage, TOutputImage>
49 ::ClearSeeds()
50 {
51   if( this->m_Seeds.size() > 0 )
52     {
53     this->m_Seeds.clear();
54     this->Modified();
55     }
56 }
57
58 template <class TInputImage, class TOutputImage>
59 void
60 LocallyAdaptiveThresholdConnectedImageFilter<TInputImage, TOutputImage>
61 ::SetSeed(const IndexType & seed)
62 {
63   this->ClearSeeds();
64   this->AddSeed ( seed );
65 }
66
67 template <class TInputImage, class TOutputImage>
68 void
69 LocallyAdaptiveThresholdConnectedImageFilter<TInputImage, TOutputImage>
70 ::AddSeed ( const IndexType & seed )
71 {
72   this->m_Seeds.push_back ( seed );
73   this->Modified();
74 }
75
76 /**
77  * Standard PrintSelf method.
78  */
79 template <class TInputImage, class TOutputImage>
80 void
81 LocallyAdaptiveThresholdConnectedImageFilter<TInputImage, TOutputImage>
82 ::PrintSelf(std::ostream& os, itk::Indent indent) const
83 {
84   this->Superclass::PrintSelf(os, indent);
85   os << indent << "Upper: "
86      << static_cast<typename itk::NumericTraits<InputImagePixelType>::PrintType>(m_UpperBorderIsGiven)
87      << std::endl;
88   os << indent << "Lower: "
89      << static_cast<typename itk::NumericTraits<InputImagePixelType>::PrintType>(m_LowerBorderIsGiven)
90      << std::endl;
91   os << indent << "ReplaceValue: "
92      << static_cast<double>(m_Multiplier)
93      << std::endl;
94   os << indent << "ReplaceValue: "
95      << static_cast<typename itk::NumericTraits<OutputImagePixelType>::PrintType>(m_ReplaceValue)
96      << std::endl;
97   os << indent << "Radius: " << m_Radius << std::endl;
98 }
99
100 template <class TInputImage, class TOutputImage>
101 void 
102 LocallyAdaptiveThresholdConnectedImageFilter<TInputImage,TOutputImage>
103 ::GenerateInputRequestedRegion()
104 {
105   Superclass::GenerateInputRequestedRegion();
106   if ( this->GetInput() )
107     {
108     InputImagePointer image =
109       const_cast< InputImageType * >( this->GetInput() );
110     image->SetRequestedRegionToLargestPossibleRegion();
111     }
112 }
113
114 template <class TInputImage, class TOutputImage>
115 void 
116 LocallyAdaptiveThresholdConnectedImageFilter<TInputImage,TOutputImage>
117 ::EnlargeOutputRequestedRegion(itk::DataObject *output)
118 {
119   Superclass::EnlargeOutputRequestedRegion(output);
120   output->SetRequestedRegionToLargestPossibleRegion();
121 }
122
123 template <class TInputImage, class TOutputImage>
124 void 
125 LocallyAdaptiveThresholdConnectedImageFilter<TInputImage,TOutputImage>
126 ::GenerateData()
127 {
128   typename Superclass::InputImageConstPointer inputImage  = this->GetInput();
129   typename Superclass::OutputImagePointer     outputImage = this->GetOutput();
130
131   // Zero the output
132   outputImage->SetBufferedRegion( outputImage->GetRequestedRegion() );
133   outputImage->Allocate();
134   outputImage->FillBuffer ( itk::NumericTraits<OutputImagePixelType>::Zero );
135   
136   typedef LocallyAdaptiveBinaryThresholdImageFunction<InputImageType> FunctionType;
137   typedef itk::FloodFilledImageFunctionConditionalIterator<OutputImageType, FunctionType> IteratorType;
138
139   typename FunctionType::Pointer function = FunctionType::New();
140   function->SetInputImage ( inputImage );
141   function->SetLowerBorderIsGiven ( m_LowerBorderIsGiven );
142   function->SetUpperBorderIsGiven ( m_UpperBorderIsGiven );
143   function->SetMaximumSDIsGiven ( m_MaximumSDIsGiven );
144   function->ThresholdBetween ( m_Lower, m_Upper );
145   function->SetMultiplier ( m_Multiplier );
146   function->SetMaximumSD ( m_MaximumSD );
147   function->SetRadius (m_Radius);
148  
149   IteratorType it = IteratorType ( outputImage, function, m_Seeds );
150     itk::ProgressReporter progress( this, 0, outputImage->GetRequestedRegion().GetNumberOfPixels());
151   
152   while( !it.IsAtEnd())
153     {
154     it.Set(m_ReplaceValue);
155     ++it;
156     progress.CompletedPixel();
157     }
158 }
159
160
161 } // end namespace clitk
162
163 #endif