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 <unsigned int> numPixels(numSamplesDatabase, 0);
46 std::vector <VectorType> meanVectors(numSamplesDatabase, patchMean);
47 std::vector <CovarianceType> varianceVector(numSamplesDatabase, baseVar);
50 unsigned int numDistances = numSamplesDatabase * (numSamplesDatabase + 1) / 2 - numSamplesDatabase;
55 while (!maskIterator.IsAtEnd())
57 if (maskIterator.Get() == 0)
59 outMeanIterator.Set(0.0);
60 outStdIterator.Set(0.0);
68 curIndex = maskIterator.GetIndex();
70 for (
unsigned int i = 0;i < 3;++i)
72 tmpBlockRegion.SetIndex(i,std::max(0,(
int)curIndex[i] - (
int)m_PatchHalfSize));
73 tmpBlockRegion.SetSize(i,std::min((
unsigned int)(largestRegionOut.GetSize()[i] - 1),(
unsigned int)(curIndex[i] + m_PatchHalfSize)) - tmpBlockRegion.GetIndex(i) + 1);
76 for (
unsigned int i = 0;i < numSamplesDatabase;++i)
81 for (
unsigned int i = 0;i < numSamplesDatabase;++i)
82 for (
unsigned int j = i+1;j < numSamplesDatabase;++j)
85 varianceVector[i], varianceVector[j]);
87 varDist += tmpDist * tmpDist;
90 varDist /= numDistances;
91 meanDist /= numDistances;
92 varDist -= meanDist * meanDist;
93 varDist *= numDistances / (numDistances - 1.0);
95 outMeanIterator.Set(meanDist);
96 outStdIterator.Set(std::sqrt(varDist));
98 this->IncrementNumberOfProcessedPoints();
InputImageType::IndexType InputImageIndexType
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.
double VectorMeansTest(itk::VariableLengthVector< T > &refPatchMean, itk::VariableLengthVector< T > &movingPatchMean, const unsigned int &refPatchNumElts, const unsigned int &movingPatchNumElts, vnl_matrix< T > &refPatchCov, vnl_matrix< T > &movingPatchCov)
Test if vector means are different (returns distance)
void BeforeThreadedGenerateData() ITK_OVERRIDE
InputImageType::PixelType VectorType
vnl_matrix< double > CovarianceType
Superclass::OutputImageRegionType OutputImageRegionType
void DynamicThreadedGenerateData(const OutputImageRegionType &outputRegionForThread) ITK_OVERRIDE