4 #include <itkImageRegionIterator.h> 5 #include <itkImageRegionConstIterator.h> 13 template <
typename TInputImage,
typename TOutputImage>
15 T2RelaxometryEstimationImageFilter <TInputImage,TOutputImage>
16 ::CheckComputationMask()
18 if (this->GetComputationMask())
21 typedef itk::ImageRegionConstIterator <InputImageType> IteratorType;
22 typedef itk::ImageRegionIterator <MaskImageType> MaskIteratorType;
24 std::vector <IteratorType> inItrs(this->GetNumberOfIndexedInputs());
25 for (
unsigned int i = 0;i < this->GetNumberOfIndexedInputs();++i)
26 inItrs[i] = IteratorType(this->GetInput(i),this->GetOutput()->GetLargestPossibleRegion());
28 typename MaskImageType::Pointer maskImage = MaskImageType::New();
29 maskImage->Initialize();
30 maskImage->SetRegions(this->GetInput(0)->GetLargestPossibleRegion());
31 maskImage->SetSpacing (this->GetInput(0)->GetSpacing());
32 maskImage->SetOrigin (this->GetInput(0)->GetOrigin());
33 maskImage->SetDirection (this->GetInput(0)->GetDirection());
34 maskImage->Allocate();
36 MaskIteratorType maskItr (maskImage,this->GetOutput()->GetLargestPossibleRegion());
37 while (!maskItr.IsAtEnd())
39 double averageVal = 0;
40 for (
unsigned int i = 0;i < this->GetNumberOfIndexedInputs();++i)
41 averageVal += inItrs[i].Get();
43 averageVal /= this->GetNumberOfIndexedInputs();
45 bool maskPoint = (averageVal <= m_AverageSignalThreshold);
52 for (
unsigned int i = 0;i < this->GetNumberOfIndexedInputs();++i)
58 this->SetComputationMask(maskImage);
61 template <
typename TInputImage,
typename TOutputImage>
66 typedef itk::ImageRegionConstIterator <InputImageType> ImageIteratorType;
67 typedef itk::ImageRegionIterator <OutputImageType> OutImageIteratorType;
69 OutImageIteratorType outT2Iterator(this->GetOutput(0),outputRegionForThread);
70 OutImageIteratorType outM0Iterator(this->GetOutput(1),outputRegionForThread);
72 unsigned int numInputs = this->GetNumberOfIndexedInputs();
73 std::vector <ImageIteratorType> inIterators;
74 for (
unsigned int i = 0;i < numInputs;++i)
75 inIterators.push_back(ImageIteratorType(this->GetInput(i),outputRegionForThread));
77 typedef itk::ImageRegionIterator <MaskImageType> MaskIteratorType;
78 MaskIteratorType maskItr(this->GetComputationMask(),outputRegionForThread);
80 OutImageIteratorType t1MapItr;
82 t1MapItr = OutImageIteratorType(m_T1Map,outputRegionForThread);
87 typename CostFunctionType::Pointer cost = CostFunctionType::New();
88 cost->SetT2EchoSpacing(m_EchoSpacing);
89 cost->SetTRValue(m_TRValue);
91 unsigned int dimension = cost->GetNumberOfParameters();
92 itk::Array<double> lowerBounds(dimension);
93 itk::Array<double> upperBounds(dimension);
94 OptimizerType::ParametersType p(dimension);
96 std::vector <double> relaxoT2Data(numInputs,0);
98 while (!maskItr.IsAtEnd())
100 if (maskItr.Get() == 0)
102 outT2Iterator.Set(0);
103 outM0Iterator.Set(0);
109 for (
unsigned int i = 0;i < numInputs;++i)
118 double t1Value = 1000.0;
122 t1Value = t1MapItr.Get();
127 for (
unsigned int i = 0;i < numInputs;++i)
128 relaxoT2Data[i] = inIterators[i].Get();
130 cost->SetT2RelaxometrySignals(relaxoT2Data);
132 OptimizerType::Pointer optimizer = OptimizerType::New();
133 optimizer->SetAlgorithm(NLOPT_LN_BOBYQA);
134 optimizer->SetXTolRel(m_OptimizerStopCondition);
135 optimizer->SetFTolRel(1.0e-2 * m_OptimizerStopCondition);
136 optimizer->SetMaxEval(5000);
137 optimizer->SetVectorStorageSize(2000);
139 lowerBounds[0] = 1.0;
140 upperBounds[0] = m_T2UpperBoundValue;
141 if (m_T1Map && (m_T2UpperBoundValue > t1Value))
142 upperBounds[0] = t1Value;
145 if (p[0] > upperBounds[0])
146 p[0] = (upperBounds[0] - lowerBounds[0]) / 2.0;
148 optimizer->SetLowerBoundParameters(lowerBounds);
149 optimizer->SetUpperBoundParameters(upperBounds);
150 optimizer->SetMaximize(
false);
152 optimizer->SetCostFunction(cost);
154 optimizer->SetInitialPosition(p);
155 optimizer->StartOptimization();
157 p = optimizer->GetCurrentPosition();
161 outT2Iterator.Set(p[0]);
162 outM0Iterator.Set(cost->GetM0Value());
168 for (
unsigned int i = 0;i < numInputs;++i)
Implements an ITK wrapper for the NLOPT library.
Superclass::OutputImageRegionType OutputImageRegionType