1 /*=========================================================================
2 Program: vv http://www.creatis.insa-lyon.fr/rio/vv
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
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.
13 It is distributed under dual licence
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"
31 template <class TInputImage, class TOutputImage>
32 LocallyAdaptiveThresholdConnectedImageFilter<TInputImage, TOutputImage>
33 ::LocallyAdaptiveThresholdConnectedImageFilter()
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;
41 m_ReplaceValue = itk::NumericTraits<OutputImagePixelType>::One;
46 template <class TInputImage, class TOutputImage>
48 LocallyAdaptiveThresholdConnectedImageFilter<TInputImage, TOutputImage>
51 if( this->m_Seeds.size() > 0 )
53 this->m_Seeds.clear();
58 template <class TInputImage, class TOutputImage>
60 LocallyAdaptiveThresholdConnectedImageFilter<TInputImage, TOutputImage>
61 ::SetSeed(const IndexType & seed)
64 this->AddSeed ( seed );
67 template <class TInputImage, class TOutputImage>
69 LocallyAdaptiveThresholdConnectedImageFilter<TInputImage, TOutputImage>
70 ::AddSeed ( const IndexType & seed )
72 this->m_Seeds.push_back ( seed );
77 * Standard PrintSelf method.
79 template <class TInputImage, class TOutputImage>
81 LocallyAdaptiveThresholdConnectedImageFilter<TInputImage, TOutputImage>
82 ::PrintSelf(std::ostream& os, itk::Indent indent) const
84 this->Superclass::PrintSelf(os, indent);
85 os << indent << "Upper: "
86 << static_cast<typename itk::NumericTraits<InputImagePixelType>::PrintType>(m_UpperBorderIsGiven)
88 os << indent << "Lower: "
89 << static_cast<typename itk::NumericTraits<InputImagePixelType>::PrintType>(m_LowerBorderIsGiven)
91 os << indent << "ReplaceValue: "
92 << static_cast<double>(m_Multiplier)
94 os << indent << "ReplaceValue: "
95 << static_cast<typename itk::NumericTraits<OutputImagePixelType>::PrintType>(m_ReplaceValue)
97 os << indent << "Radius: " << m_Radius << std::endl;
100 template <class TInputImage, class TOutputImage>
102 LocallyAdaptiveThresholdConnectedImageFilter<TInputImage,TOutputImage>
103 ::GenerateInputRequestedRegion()
105 Superclass::GenerateInputRequestedRegion();
106 if ( this->GetInput() )
108 InputImagePointer image =
109 const_cast< InputImageType * >( this->GetInput() );
110 image->SetRequestedRegionToLargestPossibleRegion();
114 template <class TInputImage, class TOutputImage>
116 LocallyAdaptiveThresholdConnectedImageFilter<TInputImage,TOutputImage>
117 ::EnlargeOutputRequestedRegion(itk::DataObject *output)
119 Superclass::EnlargeOutputRequestedRegion(output);
120 output->SetRequestedRegionToLargestPossibleRegion();
123 template <class TInputImage, class TOutputImage>
125 LocallyAdaptiveThresholdConnectedImageFilter<TInputImage,TOutputImage>
128 typename Superclass::InputImageConstPointer inputImage = this->GetInput();
129 typename Superclass::OutputImagePointer outputImage = this->GetOutput();
132 outputImage->SetBufferedRegion( outputImage->GetRequestedRegion() );
133 outputImage->Allocate();
134 outputImage->FillBuffer ( itk::NumericTraits<OutputImagePixelType>::Zero );
136 typedef LocallyAdaptiveBinaryThresholdImageFunction<InputImageType> FunctionType;
137 typedef itk::FloodFilledImageFunctionConditionalIterator<OutputImageType, FunctionType> IteratorType;
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);
149 IteratorType it = IteratorType ( outputImage, function, m_Seeds );
150 itk::ProgressReporter progress( this, 0, outputImage->GetRequestedRegion().GetNumberOfPixels());
152 while( !it.IsAtEnd())
154 it.Set(m_ReplaceValue);
156 progress.CompletedPixel();
161 } // end namespace clitk