Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
itkAdcImageFilter.txx
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #ifndef __itkAdcImageFilter_txx
18 #define __itkAdcImageFilter_txx
19 
20 #include <time.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 
24 #define _USE_MATH_DEFINES
25 #include <math.h>
26 
27 #include "itkImageRegionConstIterator.h"
28 #include "itkImageRegionConstIteratorWithIndex.h"
29 #include "itkImageRegionIterator.h"
30 
31 namespace itk {
32 
33 
34 template< class TInPixelType, class TOutPixelType >
35 AdcImageFilter< TInPixelType, TOutPixelType>
36 ::AdcImageFilter()
37 {
38  this->SetNumberOfRequiredInputs( 1 );
39 }
40 
41 template< class TInPixelType, class TOutPixelType >
42 void
43 AdcImageFilter< TInPixelType, TOutPixelType>
44 ::BeforeThreadedGenerateData()
45 {
46  typename OutputImageType::Pointer outputImage =
47  static_cast< OutputImageType * >(this->ProcessObject::GetOutput(0));
48  outputImage->FillBuffer(0.0);
49 }
50 
51 template< class TInPixelType, class TOutPixelType >
52 void
53 AdcImageFilter< TInPixelType, TOutPixelType>
54 ::ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, ThreadIdType )
55 {
56  typename OutputImageType::Pointer outputImage =
57  static_cast< OutputImageType * >(this->ProcessObject::GetOutput(0));
58 
59  ImageRegionIterator< OutputImageType > oit(outputImage, outputRegionForThread);
60  oit.GoToBegin();
61 
62  typedef ImageRegionConstIterator< InputImageType > InputIteratorType;
63  typename InputImageType::Pointer inputImagePointer = NULL;
64  inputImagePointer = static_cast< InputImageType * >( this->ProcessObject::GetInput(0) );
65 
66  InputIteratorType git( inputImagePointer, outputRegionForThread );
67  git.GoToBegin();
68  while( !git.IsAtEnd() )
69  {
70  typename InputImageType::PixelType pix = git.Get();
71  TOutPixelType outval = 0;
72 
73  double S0 = 0;
74  int c = 0;
75  for (unsigned int i=0; i<inputImagePointer->GetVectorLength(); i++)
76  {
77  GradientDirectionType g = m_GradientDirections->GetElement(i);
78  if (g.magnitude()<0.001)
79  {
80  if (pix[i]>0)
81  {
82  S0 += pix[i];
83  c++;
84  }
85  }
86  }
87  if (c>0)
88  S0 /= c;
89 
90  if (S0>0)
91  {
92  c = 0;
93  for (unsigned int i=0; i<inputImagePointer->GetVectorLength(); i++)
94  {
95  GradientDirectionType g = m_GradientDirections->GetElement(i);
96  if (g.magnitude()>0.001)
97  {
98  double twonorm = g.two_norm();
99  double b = m_B_value*twonorm*twonorm;
100  if (b>0)
101  {
102  double S = pix[i];
103  if (S>0 && S0>0)
104  {
105  outval -= std::log(S/S0)/b;
106  c++;
107  }
108  }
109  }
110  }
111 
112  if (c>0)
113  outval /= c;
114  }
115 
116  if (outval==outval && outval<10000)
117  oit.Set( outval );
118 
119  ++oit;
120  ++git;
121  }
122 
123  std::cout << "One Thread finished calculation" << std::endl;
124 }
125 
126 template< class TInPixelType, class TOutPixelType >
127 void
128 AdcImageFilter< TInPixelType, TOutPixelType>
129 ::PrintSelf(std::ostream& os, Indent indent) const
130 {
131  Superclass::PrintSelf(os,indent);
132 }
133 
134 }
135 
136 #endif // __itkAdcImageFilter_txx