6 #include <itkImageRegionIterator.h> 7 #include <itkImageRegionIteratorWithIndex.h> 8 #include <itkImageRegionConstIterator.h> 9 #include <itkImageRegionConstIteratorWithIndex.h> 10 #include <itkExtractImageFilter.h> 16 template <
class TInputImage>
18 NonLocalMeansTemporalImageFilter < TInputImage >
21 typedef itk::Image<
InputPixelType, InputImageDimension - 1> ImageToComputeType;
22 typedef itk::ExtractImageFilter< InputImageType, ImageToComputeType > ExtractImageFilterType;
24 this->AllocateOutputs();
26 unsigned int nbTemporalImage = this->GetInput()->GetLargestPossibleRegion().GetSize()[InputImageDimension - 1];
28 typename InputImageType::RegionType extractRegion;
29 typename InputImageType::SizeType extractSize;
30 typename InputImageType::IndexType extractIndex;
32 for (
unsigned int d = 0; d < InputImageDimension - 1; ++d)
34 extractSize[d] = this->GetInput()->GetLargestPossibleRegion().GetSize()[d];
38 extractSize[InputImageDimension - 1] = 0;
39 extractRegion.SetSize(extractSize);
41 typedef itk::ImageRegionIterator <OutputImageType> FillIteratorType;
42 FillIteratorType fillItr(this->GetOutput(), this->GetOutput()->GetLargestPossibleRegion());
45 itk::ProgressReporter progress(
this, 0, nbTemporalImage);
47 for (
unsigned int i = 0; i < nbTemporalImage; ++i)
49 extractIndex[InputImageDimension - 1] = i;
50 extractRegion.SetIndex(extractIndex);
52 typename ExtractImageFilterType::Pointer extractFilter = ExtractImageFilterType::New();
53 extractFilter->SetInput(this->GetInput());
55 extractFilter->SetExtractionRegion(extractRegion);
56 extractFilter->SetDirectionCollapseToGuess();
57 extractFilter->Update();
60 typename NLMEansFilterType::Pointer nLMeansFilter = NLMEansFilterType::New();
63 nLMeansFilter->SetInput(extractFilter->GetOutput());
64 nLMeansFilter->SetWeightThreshold(m_WeightThreshold);
65 nLMeansFilter->SetPatchHalfSize(m_PatchHalfSize);
66 nLMeansFilter->SetSearchStepSize(m_SearchStepSize);
67 nLMeansFilter->SetSearchNeighborhood(m_SearchNeighborhood);
68 nLMeansFilter->SetBetaParameter(m_BetaParameter);
69 nLMeansFilter->SetMeanMinThreshold(m_MeanMinThreshold);
70 nLMeansFilter->SetVarMinThreshold(m_VarMinThreshold);
71 if (m_WeightMethod == EXP)
72 nLMeansFilter->SetWeightMethod(NLMEansFilterType::EXP);
73 else nLMeansFilter->SetWeightMethod(NLMEansFilterType::RICIAN);
75 nLMeansFilter->SetNumberOfWorkUnits(this->GetNumberOfWorkUnits());
77 nLMeansFilter->Update();
79 typedef itk::ImageRegionConstIterator <ImageToComputeType> ResIteratorType;
80 ResIteratorType resItr(nLMeansFilter->GetOutput(), nLMeansFilter->GetOutput()->GetLargestPossibleRegion());
82 while (!resItr.IsAtEnd())
84 fillItr.Set(resItr.Get());
88 progress.CompletedPixel();
TInputImage::PixelType InputPixelType