4 #include <itkImageRegionIteratorWithIndex.h> 5 #include <itkProgressAccumulator.h> 13 template <
typename TInputImage,
typename TOutputImage >
17 m_NormalizeAcrossScale =
false;
19 m_FirstSmoothingFilter = FirstGaussianFilterType::New();
20 m_FirstSmoothingFilter->SetDirection(ImageDimension - 1);
21 m_FirstSmoothingFilter->SetNormalizeAcrossScale( m_NormalizeAcrossScale );
22 m_FirstSmoothingFilter->ReleaseDataFlagOn();
24 for(
unsigned int i = 0; i<ImageDimension-1; i++ )
26 m_SmoothingFilters[i] = InternalGaussianFilterType::New();
27 m_SmoothingFilters[i]->SetNormalizeAcrossScale( m_NormalizeAcrossScale );
28 m_SmoothingFilters[i]->SetDirection(i);
29 m_SmoothingFilters[i]->ReleaseDataFlagOn();
30 m_SmoothingFilters[i]->InPlaceOn();
33 m_SmoothingFilters[0]->SetInput( m_FirstSmoothingFilter->GetOutput() );
34 for(
unsigned int i = 1; i<ImageDimension-1; i++ )
36 m_SmoothingFilters[i]->SetInput(m_SmoothingFilters[i-1]->GetOutput());
39 m_CastingFilter = CastingFilterType::New();
40 m_CastingFilter->SetInput(m_SmoothingFilters[ImageDimension-2]->GetOutput());
41 m_CastingFilter->InPlaceOn();
50 this->m_Sigma.Fill(0.0);
51 this->SetSigma( 1.0 );
55 template <
typename TInputImage,
typename TOutputImage>
60 Superclass::SetNumberOfWorkUnits( nb );
61 for(
unsigned int i = 0; i<ImageDimension-1; i++ )
63 m_SmoothingFilters[ i ]->SetNumberOfWorkUnits( nb );
65 m_FirstSmoothingFilter->SetNumberOfWorkUnits( nb );
69 template<
typename TInputImage,
typename TOutputImage >
88 return m_FirstSmoothingFilter->CanRunInPlace() || this->Superclass::CanRunInPlace();
93 template <
typename TInputImage,
typename TOutputImage>
99 this->SetSigmaArray(sigmas);
105 template <
typename TInputImage,
typename TOutputImage>
110 if (this->m_Sigma != sigma)
112 this->m_Sigma = sigma;
113 for(
unsigned int i = 0; i<ImageDimension-1; i++ )
115 m_SmoothingFilters[ i ]->SetSigma( m_Sigma[i] );
117 m_FirstSmoothingFilter->SetSigma(m_Sigma[ImageDimension - 1]);
125 template <
typename TInputImage,
typename TOutputImage>
136 template <
typename TInputImage,
typename TOutputImage>
148 template <
typename TInputImage,
typename TOutputImage>
153 m_NormalizeAcrossScale = normalize;
155 for(
unsigned int i = 0; i<ImageDimension-1; i++ )
157 m_SmoothingFilters[i]->SetNormalizeAcrossScale(normalize);
159 m_FirstSmoothingFilter->SetNormalizeAcrossScale(normalize);
164 template <
typename TInputImage,
typename TOutputImage>
171 Superclass::GenerateInputRequestedRegion();
177 image->SetRequestedRegion( this->GetInput()->GetLargestPossibleRegion() );
181 template <
typename TInputImage,
typename TOutputImage>
186 TOutputImage *out =
dynamic_cast<TOutputImage*
>(output);
190 out->SetRequestedRegion( out->GetLargestPossibleRegion() );
197 template <
typename TInputImage,
typename TOutputImage >
203 itkDebugMacro(<<
"SmoothingRecursiveYvvGaussianImageFilter generating data ");
205 const typename TInputImage::ConstPointer inputImage( this->GetInput() );
207 const typename TInputImage::RegionType region = inputImage->GetRequestedRegion();
208 const typename TInputImage::SizeType size = region.GetSize();
210 for(
unsigned int d=0; d < ImageDimension; d++)
214 itkExceptionMacro(
"The number of pixels along dimension " << d <<
" is less than 4. This filter requires a minimum of four pixels along the dimension to be processed.");
220 if (this->CanRunInPlace() && this->GetInPlace())
222 m_FirstSmoothingFilter->InPlaceOn();
227 this->AllocateOutputs();
231 m_FirstSmoothingFilter->InPlaceOff();
236 if ( m_CastingFilter->CanRunInPlace() )
238 this->GetOutput()->ReleaseData();
242 itk::ProgressAccumulator::Pointer progress = itk::ProgressAccumulator::New();
243 progress->SetMiniPipelineFilter(
this);
247 for(
unsigned int i = 0;i < ImageDimension - 1;++i)
249 progress->RegisterInternalFilter(m_SmoothingFilters[i],1.0 / (ImageDimension));
252 progress->RegisterInternalFilter(m_FirstSmoothingFilter,1.0 / (ImageDimension));
253 m_FirstSmoothingFilter->SetInput( inputImage );
256 m_CastingFilter->GraftOutput(this->GetOutput());
257 m_CastingFilter->Update();
258 this->GraftOutput(m_CastingFilter->GetOutput());
263 template <
typename TInputImage,
typename TOutputImage>
268 Superclass::PrintSelf(os,indent);
270 os <<
"NormalizeAcrossScale: " << m_NormalizeAcrossScale << std::endl;
271 os <<
"Sigma: " << m_Sigma << std::endl;
virtual bool CanRunInPlace() const ITK_OVERRIDE
void EnlargeOutputRequestedRegion(itk::DataObject *output) ITK_OVERRIDE
virtual void GenerateInputRequestedRegion() ITK_OVERRIDE
itk::FixedArray< ScalarRealType, itkGetStaticConstMacro(ImageDimension) > SigmaArrayType
void SetSigmaArray(const SigmaArrayType &sigmas)
void SetNormalizeAcrossScale(bool normalizeInScaleSpace)
TInputImage InputImageType
SigmaArrayType GetSigmaArray() const
ScalarRealType GetSigma() const
void GenerateData() ITK_OVERRIDE
SmoothingRecursiveYvvGaussianImageFilter()
void PrintSelf(std::ostream &os, itk::Indent indent) const ITK_OVERRIDE
void SetNumberOfWorkUnits(itk::ThreadIdType nb) ITK_OVERRIDE
void SetSigma(ScalarRealType sigma)
itk::NumericTraits< PixelType >::ScalarRealType ScalarRealType