4 #include <itkImageRegionIteratorWithIndex.h> 5 #include <itkSymmetricEigenAnalysis.h> 12 template <
class PixelScalarType>
17 Superclass::BeforeThreadedGenerateData();
21 unsigned int nbInputs = this->GetNumberOfIndexedInputs();
23 itkExceptionMacro(
"Error: Not enough inputs available... Exiting...");
26 template <
class PixelScalarType>
31 typedef itk::ImageRegionIteratorWithIndex< OutputImageType > OutRegionIteratorType;
32 typedef itk::ImageRegionConstIteratorWithIndex < MaskImageType > MaskRegionIteratorType;
34 OutRegionIteratorType outMeanIterator(this->GetOutput(0), outputRegionForThread);
35 OutRegionIteratorType outStdIterator(this->GetOutput(1), outputRegionForThread);
37 MaskRegionIteratorType maskIterator (this->GetComputationMask(), outputRegionForThread);
39 unsigned int numSamplesDatabase = this->GetNumberOfIndexedInputs();
41 unsigned int ndim = this->GetInput(0)->GetNumberOfComponentsPerPixel();
45 std::vector <CovarianceType> varianceVector(numSamplesDatabase, baseVar);
46 std::vector <CovarianceType> logVarianceVector(numSamplesDatabase, baseVar);
49 unsigned int numDistances = numSamplesDatabase * (numSamplesDatabase + 1) / 2 - numSamplesDatabase;
52 vnl_diag_matrix <double> eVals(ndim);
53 itk::SymmetricEigenAnalysis <vnl_matrix <double>, vnl_diag_matrix <double>, vnl_matrix <double> > EigenAnalysis(ndim);
58 while (!maskIterator.IsAtEnd())
60 if (maskIterator.Get() == 0)
62 outMeanIterator.Set(0.0);
63 outStdIterator.Set(0.0);
71 curIndex = maskIterator.GetIndex();
73 for (
unsigned int i = 0;i < 3;++i)
75 tmpBlockRegion.SetIndex(i,std::max(0,(
int)curIndex[i] - (
int)m_PatchHalfSize));
76 tmpBlockRegion.SetSize(i,std::min((
unsigned int)(largestRegionOut.GetSize()[i] - 1),(
unsigned int)(curIndex[i] + m_PatchHalfSize)) - tmpBlockRegion.GetIndex(i) + 1);
79 for (
unsigned int i = 0;i < numSamplesDatabase;++i)
82 EigenAnalysis.ComputeEigenValuesAndVectors(varianceVector[i], eVals, eVec);
84 for (
unsigned int j = 0;j < ndim;++j)
85 eVals[j] = log(eVals[j]);
87 logVarianceVector[i] = eVec.transpose() * eVals * eVec;
92 for (
unsigned int i = 0;i < numSamplesDatabase;++i)
93 for (
unsigned int j = i+1;j < numSamplesDatabase;++j)
97 varDist += tmpDist * tmpDist;
100 varDist /= numDistances;
101 meanDist /= numDistances;
102 varDist -= meanDist * meanDist;
103 varDist *= numDistances / (numDistances - 1.0);
105 outMeanIterator.Set(meanDist);
106 outStdIterator.Set(sqrt(varDist));
108 this->IncrementNumberOfProcessedPoints();
InputImageType::IndexType InputImageIndexType
InputImageType::PixelType VectorType
unsigned int computePatchMeanAndCovariance(const itk::VectorImage< T1, Dimension > *inputImage, const itk::ImageRegion< Dimension > &patchRegion, itk::VariableLengthVector< T2 > &patchMean, vnl_matrix< T2 > &patchCov)
Computes the average and covariance matrix from a patch of a vector image.
Superclass::OutputImageRegionType OutputImageRegionType
double VectorCovarianceTest(vnl_matrix< T > &logRefPatchCov, vnl_matrix< T > &movingPatchCov)
Test if covariance matrices are different (returns distance)
vnl_matrix< double > CovarianceType
void DynamicThreadedGenerateData(const OutputImageRegionType &outputRegionForThread) ITK_OVERRIDE
void BeforeThreadedGenerateData() ITK_OVERRIDE