ANIMA  4.0
animaNonLocalMeansTemporalImageFilter.hxx
Go to the documentation of this file.
1 #pragma once
2 
4 
6 #include <itkImageRegionIterator.h>
7 #include <itkImageRegionIteratorWithIndex.h>
8 #include <itkImageRegionConstIterator.h>
9 #include <itkImageRegionConstIteratorWithIndex.h>
10 #include <itkExtractImageFilter.h>
11 
12 namespace anima
13 {
14 
15 
16 template < class TInputImage>
17 void
18 NonLocalMeansTemporalImageFilter < TInputImage >
19 ::GenerateData()
20 {
21  typedef itk::Image<InputPixelType, InputImageDimension - 1> ImageToComputeType;
22  typedef itk::ExtractImageFilter< InputImageType, ImageToComputeType > ExtractImageFilterType;
23 
24  this->AllocateOutputs();
25 
26  unsigned int nbTemporalImage = this->GetInput()->GetLargestPossibleRegion().GetSize()[InputImageDimension - 1];
27 
28  typename InputImageType::RegionType extractRegion;
29  typename InputImageType::SizeType extractSize;
30  typename InputImageType::IndexType extractIndex;
31 
32  for (unsigned int d = 0; d < InputImageDimension - 1; ++d)
33  {
34  extractSize[d] = this->GetInput()->GetLargestPossibleRegion().GetSize()[d];
35  extractIndex[d] = 0;
36  }
37 
38  extractSize[InputImageDimension - 1] = 0;
39  extractRegion.SetSize(extractSize);
40 
41  typedef itk::ImageRegionIterator <OutputImageType> FillIteratorType;
42  FillIteratorType fillItr(this->GetOutput(), this->GetOutput()->GetLargestPossibleRegion());
43 
44  //support progress methods/callbacks
45  itk::ProgressReporter progress(this, 0, nbTemporalImage);
46 
47  for (unsigned int i = 0; i < nbTemporalImage; ++i)
48  {
49  extractIndex[InputImageDimension - 1] = i;
50  extractRegion.SetIndex(extractIndex);
51 
52  typename ExtractImageFilterType::Pointer extractFilter = ExtractImageFilterType::New();
53  extractFilter->SetInput(this->GetInput());
54 
55  extractFilter->SetExtractionRegion(extractRegion);
56  extractFilter->SetDirectionCollapseToGuess();
57  extractFilter->Update();
58 
60  typename NLMEansFilterType::Pointer nLMeansFilter = NLMEansFilterType::New();
61 
62 
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);
74 
75  nLMeansFilter->SetNumberOfWorkUnits(this->GetNumberOfWorkUnits());
76 
77  nLMeansFilter->Update();
78 
79  typedef itk::ImageRegionConstIterator <ImageToComputeType> ResIteratorType;
80  ResIteratorType resItr(nLMeansFilter->GetOutput(), nLMeansFilter->GetOutput()->GetLargestPossibleRegion());
81 
82  while (!resItr.IsAtEnd())
83  {
84  fillItr.Set(resItr.Get());
85  ++fillItr;
86  ++resItr;
87  }
88  progress.CompletedPixel();
89  }
90 
91 }
92 
93 }//end of namespace anima