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 __clitkLocallyAdaptiveBinaryThresholdImageFunction_txx
19 #define __clitkLocallyAdaptiveBinaryThresholdImageFunction_txx
20 #include "clitkLocallyAdaptiveBinaryThresholdImageFunction.h"
21 #include "itkNumericTraits.h"
22 #include "itkConstNeighborhoodIterator.h"
30 template <class TInputImage, class TCoordRep>
31 LocallyAdaptiveBinaryThresholdImageFunction<TInputImage,TCoordRep>
32 ::LocallyAdaptiveBinaryThresholdImageFunction()
35 m_LowerBorderIsGiven=true;
36 m_UpperBorderIsGiven=true;
37 m_MaximumSDIsGiven=true;
46 template <class TInputImage, class TCoordRep>
48 LocallyAdaptiveBinaryThresholdImageFunction<TInputImage,TCoordRep>
49 ::PrintSelf(std::ostream& os, itk::Indent indent) const
51 this->Superclass::PrintSelf(os,indent);
53 os << indent << "Radius: " << m_Radius << std::endl;
60 template <class TInputImage, class TCoordRep>
62 LocallyAdaptiveBinaryThresholdImageFunction<TInputImage,TCoordRep>
63 ::EvaluateAtIndex(const IndexType& index) const
66 if( !this->GetInputImage() )
71 if ( !this->IsInsideBuffer( index ) )
76 // Create an N-d neighborhood kernel, using a zeroflux boundary condition
77 itk::ConstNeighborhoodIterator<InputImageType>
78 it(m_Radius, this->GetInputImage(), this->GetInputImage()->GetBufferedRegion());
80 // Set the iterator at the desired location
81 it.SetLocation(index);
82 PixelType centerValue = it.GetPixel(0);
83 PixelType currentvalue;
86 // Walk the neighborhood for the mean and SD
87 const unsigned int size = it.Size();
88 typename itk::NumericTraits<PixelType>::RealType mean=0;
89 typename itk::NumericTraits<PixelType>::RealType sd=0;
90 for (unsigned int i = 1; i < size; ++i)
92 currentvalue=it.GetPixel(i);
94 sd+=currentvalue*currentvalue;
96 mean/=( typename itk::NumericTraits<PixelType>::RealType) size-1.;
97 sd= sqrt( (sd /(typename itk::NumericTraits<PixelType>::RealType)size-1.) - (mean*mean) );
99 // Verify fixed borders
100 if (this->GetLower() > centerValue || centerValue > this->GetUpper())
103 // Verify lower adaptive borders
104 if( (m_LowerBorderIsGiven) && (centerValue < ( mean - (typename itk::NumericTraits<PixelType>::RealType) ( m_Multiplier*sd) ) ) )
107 // Verify upper adaptive border
108 if ( (m_UpperBorderIsGiven) && (centerValue > ( mean + (typename itk::NumericTraits<PixelType>::RealType) ( m_Multiplier*sd) ) ) )
112 if ( (m_MaximumSDIsGiven) && ( sd> m_MaximumSD) )
124 } // end namespace itk