1 /*===================================================================
3 The Medical Imaging Interaction Toolkit (MITK)
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
13 See LICENSE.txt or http://www.mitk.org for details.
15 ===================================================================*/
17 #ifndef __itkDiffusionQballGeneralizedFaImageFilter_txx
18 #define __itkDiffusionQballGeneralizedFaImageFilter_txx
24 #define _USE_MATH_DEFINES
27 #include "itkImageRegionConstIterator.h"
28 #include "itkImageRegionConstIteratorWithIndex.h"
29 #include "itkImageRegionIterator.h"
31 #include "vnl/vnl_vector.h"
32 #include "itkOrientationDistributionFunction.h"
36 //#define QBALL_RECON_PI M_PI
38 template< class TOdfPixelType,
41 DiffusionQballGeneralizedFaImageFilter< TOdfPixelType,
42 TGfaPixelType, NrOdfDirections>
43 ::DiffusionQballGeneralizedFaImageFilter() :
44 m_ComputationMethod(GFA_STANDARD)
46 // At least 1 inputs is necessary for a vector image.
47 // For images added one at a time we need at least six
48 this->SetNumberOfRequiredInputs( 1 );
51 template< class TOdfPixelType,
54 void DiffusionQballGeneralizedFaImageFilter< TOdfPixelType,
55 TGfaPixelType, NrOdfDirections>
56 ::BeforeThreadedGenerateData()
60 template< class TOdfPixelType,
63 void DiffusionQballGeneralizedFaImageFilter< TOdfPixelType,
64 TGfaPixelType, NrOdfDirections>
65 ::ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread,
68 typename OutputImageType::Pointer outputImage =
69 static_cast< OutputImageType * >(this->ProcessObject::GetOutput(0));
71 ImageRegionIterator< OutputImageType > oit(outputImage, outputRegionForThread);
74 typedef itk::OrientationDistributionFunction<TOdfPixelType,NrOdfDirections> OdfType;
75 typedef ImageRegionConstIterator< InputImageType > InputIteratorType;
76 typedef typename InputImageType::PixelType OdfVectorType;
77 typename InputImageType::Pointer inputImagePointer = NULL;
78 inputImagePointer = static_cast< InputImageType * >(
79 this->ProcessObject::GetInput(0) );
81 InputIteratorType git(inputImagePointer, outputRegionForThread );
83 while( !git.IsAtEnd() )
85 OdfVectorType b = git.Get();
86 TGfaPixelType outval = -1;
88 switch( m_ComputationMethod )
92 OdfType odf = b.GetDataPointer();
93 outval = odf.GetGeneralizedFractionalAnisotropy();
96 case GFA_QUANTILES_HIGH_LOW:
98 vnl_vector_fixed<TOdfPixelType,NrOdfDirections> sorted;
99 for(int i=0; i<NrOdfDirections; i++)
103 std::sort( sorted.begin(), sorted.end() );
104 double q60 = sorted[floor(0.6*(double)NrOdfDirections+0.5)];
105 double q95 = sorted[floor(0.95*(double)NrOdfDirections+0.5)];
106 outval = q95/q60 - 1.0;
109 case GFA_QUANTILE_HIGH:
111 vnl_vector_fixed<TOdfPixelType,NrOdfDirections> sorted;
112 for(int i=0; i<NrOdfDirections; i++)
116 std::sort( sorted.begin(), sorted.end() );
117 //double q40 = sorted[floor(0.4*(double)NrOdfDirections+0.5)];
118 double q95 = sorted[floor(0.95*(double)NrOdfDirections+0.5)];
122 case GFA_MAX_ODF_VALUE:
124 outval = b.GetVnlVector().max_value();
127 case GFA_DECONVOLUTION_COEFFS:
131 case GFA_MIN_MAX_NORMALIZED_STANDARD:
133 OdfType odf = b.GetDataPointer();
134 odf = odf.MinMaxNormalize();
135 outval = odf.GetGeneralizedFractionalAnisotropy();
138 case GFA_NORMALIZED_ENTROPY:
140 OdfType odf = b.GetDataPointer();
141 outval = odf.GetNormalizedEntropy();
144 case GFA_NEMATIC_ORDER_PARAMETER:
146 OdfType odf = b.GetDataPointer();
147 outval = odf.GetNematicOrderParameter();
150 case GFA_QUANTILE_LOW:
152 vnl_vector_fixed<TOdfPixelType,NrOdfDirections> sorted;
153 for(int i=0; i<NrOdfDirections; i++)
157 std::sort( sorted.begin(), sorted.end() );
158 //double q40 = sorted[floor(0.4*(double)NrOdfDirections+0.5)];
159 double q05 = sorted[floor(0.05*(double)NrOdfDirections+0.5)];
163 case GFA_MIN_ODF_VALUE:
165 outval = b.GetVnlVector().min_value();
168 case GFA_QUANTILES_LOW_HIGH:
170 vnl_vector_fixed<TOdfPixelType,NrOdfDirections> sorted;
171 for(int i=0; i<NrOdfDirections; i++)
175 std::sort( sorted.begin(), sorted.end() );
176 double q05 = sorted[floor(0.05*(double)NrOdfDirections+0.5)];
177 double q40 = sorted[floor(0.4*(double)NrOdfDirections+0.5)];
178 outval = q40/q05 - 1.0;
183 OdfType odf = b.GetDataPointer();
184 outval = odf.GetStdDevByMaxValue();
187 case GFA_PRINCIPLE_CURVATURE:
189 OdfType odf = b.GetDataPointer();
190 outval = odf.GetPrincipleCurvature(m_Param1, m_Param2, 0);
193 case GFA_GENERALIZED_GFA:
195 OdfType odf = b.GetDataPointer();
196 outval = odf.GetGeneralizedGFA(m_Param1, m_Param2);
204 ++git; // Gradient image iterator
207 std::cout << "One Thread finished calculation" << std::endl;
210 template< class TOdfPixelType,
213 void DiffusionQballGeneralizedFaImageFilter< TOdfPixelType,
214 TGfaPixelType, NrOdfDirections>
215 ::PrintSelf(std::ostream& os, Indent indent) const
217 Superclass::PrintSelf(os,indent);
222 #endif // __itkDiffusionQballGeneralizedFaImageFilter_txx