Medical Imaging Interaction Toolkit  2018.4.99-12ad79a3
Medical Imaging Interaction Toolkit
itkMultiHistogramFilter.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #ifndef itkMultiHistogramFilter_cpp
14 #define itkMultiHistogramFilter_cpp
15 
17 
18 #include <itkNeighborhoodIterator.h>
19 #include <itkImageRegionIterator.h>
20 #include <itkImageIterator.h>
21 #include "itkMinimumMaximumImageCalculator.h"
22 
23 template< class TInputImageType, class TOuputImageType>
25 m_Delta(0.6), m_Offset(-3.0), m_Bins(11), m_Size(5), m_UseImageIntensityRange(false)
26 {
27  this->SetNumberOfRequiredOutputs(m_Bins);
28  this->SetNumberOfRequiredInputs(0);
29 
30  for (int i = 0; i < m_Bins; ++i)
31  {
32  this->SetNthOutput( i, this->MakeOutput(i) );
33  }
34 }
35 
36 template< class TInputImageType, class TOuputImageType>
37 void
39 {
40  typedef itk::MinimumMaximumImageCalculator <TInputImageType>
41  ImageCalculatorFilterType;
42 
43  if (m_UseImageIntensityRange)
44  {
45  typename ImageCalculatorFilterType::Pointer imageCalculatorFilter
46  = ImageCalculatorFilterType::New();
47  imageCalculatorFilter->SetImage(this->GetInput(0));
48  imageCalculatorFilter->Compute();
49 
50  m_Offset = imageCalculatorFilter->GetMinimum();
51  m_Delta = 1.0*(imageCalculatorFilter->GetMaximum() - imageCalculatorFilter->GetMinimum()) / (1.0*m_Bins);
52  }
53 
54  InputImagePointer input = this->GetInput(0);
55  for (int i = 0; i < m_Bins; ++i)
56  {
57  CreateOutputImage(input, this->GetOutput(i));
58  }
59 }
60 template< class TInputImageType, class TOuputImageType>
61 void
63 {
64  double offset = m_Offset;// -3.0;
65  double delta = m_Delta;// 0.6;
66 
67  typedef itk::ImageRegionIterator<TInputImageType> IteratorType;
68  typedef itk::ConstNeighborhoodIterator<TInputImageType> ConstIteratorType;
69 
70  typename TInputImageType::SizeType size; size.Fill(m_Size);
71  InputImagePointer input = this->GetInput(0);
72 
73 // MITK_INFO << "Creating output iterator";
74  std::vector<IteratorType> iterVector;
75  for (int i = 0; i < m_Bins; ++i)
76  {
77  IteratorType iter(this->GetOutput(i), outputRegionForThread);
78  iterVector.push_back(iter);
79  }
80 
81  ConstIteratorType inputIter(size, input, outputRegionForThread);
82  while (!inputIter.IsAtEnd())
83  {
84  for (int i = 0; i < m_Bins; ++i)
85  {
86  iterVector[i].Set(0);
87  }
88 
89  for (unsigned int i = 0; i < inputIter.Size(); ++i)
90  {
91  double value = inputIter.GetPixel(i);
92  value -= offset;
93  value /= delta;
94  auto pos = (int)(value);
95  pos = std::max(0, std::min(m_Bins-1, pos));
96  iterVector[pos].Value() += 1;// (iterVector[pos].GetCenterPixel() + 1);
97  }
98 
99  for (int i = 0; i < m_Bins; ++i)
100  {
101  ++(iterVector[i]);
102  }
103  ++inputIter;
104  }
105 }
106 
107 template< class TInputImageType, class TOuputImageType>
108 itk::ProcessObject::DataObjectPointer
109  itk::MultiHistogramFilter<TInputImageType, TOuputImageType>::MakeOutput(itk::ProcessObject::DataObjectPointerArraySizeType /*idx*/)
110 {
111  itk::ProcessObject::DataObjectPointer output;
112  output = ( TOuputImageType::New() ).GetPointer();
113  return output;
114 }
115 
116 template< class TInputImageType, class TOuputImageType>
117 void
119 {
120  output->SetRegions(input->GetLargestPossibleRegion());
121  output->Allocate();
122 }
123 
124 #endif //itkMultiHistogramFilter_cpp
void CreateOutputImage(InputImagePointer input, OutputImagePointer output)
void ThreadedGenerateData(const OutputImageRegionType &outputRegionForThread, ThreadIdType threadId) override
static Vector3D offset
TInputImageType::ConstPointer InputImagePointer
void BeforeThreadedGenerateData(void) override
static T max(T x, T y)
Definition: svm.cpp:56
itk::ProcessObject::DataObjectPointer MakeOutput(itk::ProcessObject::DataObjectPointerArraySizeType) override
static T min(T x, T y)
Definition: svm.cpp:53
TOuputImageType::Pointer OutputImagePointer
TOuputImageType::RegionType OutputImageRegionType