4 #include <itkImageRegionIterator.h> 5 #include <itkImageRegionConstIterator.h> 13 template <
typename TInputImage,
typename TOutputImage>
15 T1SERelaxometryEstimationImageFilter <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 outT1Iterator(this->GetOutput(1),outputRegionForThread);
70 OutImageIteratorType outM0Iterator(this->GetOutput(0),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);
81 cost->SetTRValues(m_TRValues);
83 std::vector <double> relaxoData(numInputs,0);
86 unsigned int dimension = cost->GetNumberOfParameters();
87 itk::Array<double> lowerBounds(dimension);
88 itk::Array<double> upperBounds(dimension);
89 OptimizerType::ParametersType p(dimension);
91 lowerBounds[0] = 1.0e-4;
92 upperBounds[0] = m_M0UpperBound;
94 lowerBounds[1] = 1.0e-4;
95 upperBounds[1] = m_T1UpperBound;
97 while (!maskItr.IsAtEnd())
99 if (maskItr.Get() == 0)
101 outT1Iterator.Set(0);
102 outM0Iterator.Set(0);
108 for (
unsigned int i = 0;i < numInputs;++i)
114 for (
unsigned int i = 0;i < numInputs;++i)
115 relaxoData[i] = inIterators[i].Get();
117 cost->SetRelaxometrySignals(relaxoData);
119 OptimizerType::Pointer optimizer = OptimizerType::New();
120 optimizer->SetAlgorithm(NLOPT_LN_BOBYQA);
122 optimizer->SetMaxEval(m_MaximumOptimizerIterations);
123 optimizer->SetXTolRel(m_OptimizerStopCondition);
125 optimizer->SetLowerBoundParameters(lowerBounds);
126 optimizer->SetUpperBoundParameters(upperBounds);
131 optimizer->SetMaximize(
false);
133 optimizer->SetCostFunction(cost);
135 optimizer->SetInitialPosition(p);
136 optimizer->StartOptimization();
138 p = optimizer->GetCurrentPosition();
140 outM0Iterator.Set(p[0]);
141 outT1Iterator.Set(p[1]);
147 for (
unsigned int i = 0;i < numInputs;++i)
Implements an ITK wrapper for the NLOPT library.
Superclass::OutputImageRegionType OutputImageRegionType
itk::SmartPointer< Self > Pointer