Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
itkMultiHistogramFilter.cpp
Go to the documentation of this file.
1 #ifndef itkMultiHistogramFilter_cpp
2 #define itkMultiHistogramFilter_cpp
3 
5 
6 #include <itkNeighborhoodIterator.h>
7 #include <itkImageIterator.h>
8 
9 template< class TInputImageType, class TOuputImageType>
11  m_Offset(-3.0), m_Delta(0.6)
12 {
13  this->SetNumberOfRequiredOutputs(11);
14  this->SetNumberOfRequiredInputs(0);
15 
16  for (int i = 0; i < 11; ++i)
17  {
18  this->SetNthOutput( i, this->MakeOutput(i) );
19  }
20 }
21 
22 template< class TInputImageType, class TOuputImageType>
23 void
25 {
26  double offset = m_Offset;// -3.0;
27  double delta = m_Delta;// 0.6;
28 
29  typedef itk::NeighborhoodIterator<TInputImageType> IteratorType;
30  typedef itk::ConstNeighborhoodIterator<TInputImageType> ConstIteratorType;
31 
32  InputImagePointer input = this->GetInput(0);
33  CreateOutputImage(input, this->GetOutput(0));
34  CreateOutputImage(input, this->GetOutput(1));
35  CreateOutputImage(input, this->GetOutput(2));
36  CreateOutputImage(input, this->GetOutput(3));
37  CreateOutputImage(input, this->GetOutput(4));
38  CreateOutputImage(input, this->GetOutput(5));
39  CreateOutputImage(input, this->GetOutput(6));
40  CreateOutputImage(input, this->GetOutput(7));
41  CreateOutputImage(input, this->GetOutput(8));
42  CreateOutputImage(input, this->GetOutput(9));
43  CreateOutputImage(input, this->GetOutput(10));
44 
45  typename TInputImageType::SizeType size; size.Fill(5);
46  std::vector<IteratorType> iterVector;
47  for (int i = 0; i < 11; ++i)
48  {
49  IteratorType iter(size, this->GetOutput(i), this->GetOutput(i)->GetLargestPossibleRegion());
50  iterVector.push_back(iter);
51  }
52 
53  ConstIteratorType inputIter( size, input, input->GetLargestPossibleRegion());
54  while (!inputIter.IsAtEnd())
55  {
56  for (int i = 0; i < 11; ++i)
57  {
58  iterVector[i].SetCenterPixel(0);
59  }
60 
61  for (int i = 0; i < inputIter.Size(); ++i)
62  {
63  double value = inputIter.GetPixel(i);
64  value -= offset;
65  value /= delta;
66  int pos = (int)(value);
67  pos = std::max(0, std::min(10, pos));
68  iterVector[pos].SetCenterPixel(iterVector[pos].GetCenterPixel() + 1);
69  }
70 
71  for (int i = 0; i < 11; ++i)
72  {
73  ++(iterVector[i]);
74  }
75  ++inputIter;
76  }
77 }
78 
79 template< class TInputImageType, class TOuputImageType>
82 {
83  DataObject::Pointer output;
84  output = ( TOuputImageType::New() ).GetPointer();
85  return output.GetPointer();
86 }
87 
88 template< class TInputImageType, class TOuputImageType>
89 void
91 {
92  output->SetRegions(input->GetLargestPossibleRegion());
93  output->Allocate();
94 }
95 
96 #endif //itkMultiHistogramFilter_cpp
itk::SmartPointer< Self > Pointer
DataObject::Pointer MakeOutput(unsigned int)
void CreateOutputImage(InputImagePointer input, OutputImagePointer output)
static Vector3D offset
TInputImageType::ConstPointer InputImagePointer
static T max(T x, T y)
Definition: svm.cpp:70
static T min(T x, T y)
Definition: svm.cpp:67
TOuputImageType::Pointer OutputImagePointer
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.