4 #include <itkImageRegionConstIterator.h> 5 #include <itkImageRegionConstIteratorWithIndex.h> 10 template <
class ImageType>
11 NonLocalPatchBaseSearcher <ImageType>
17 m_WeightThreshold = 0.0;
22 template <
class ImageType>
25 ::AddComparisonImage(ImageType *arg)
27 m_ComparisonImages.push_back(arg);
30 template <
class ImageType>
33 ::GetComparisonImage(
unsigned int index)
35 if (index >= m_ComparisonImages.size())
38 return m_ComparisonImages[index];
41 template <
class ImageType>
46 if (m_ComparisonImages.size() == 0)
47 this->AddComparisonImage(m_InputImage);
48 unsigned int numComparisonImages = m_ComparisonImages.size();
50 m_DatabaseWeights.clear();
51 m_DatabaseSamples.clear();
53 IndexType blockIndex, dispIndex, movingIndex;
55 ImageRegionType largestImageRegion = this->GetInputImage()->GetLargestPossibleRegion();
58 for (
unsigned int d = 0; d < ImageType::ImageDimension;++d)
60 int tmpIndex = dataIndex[d] - m_PatchHalfSize;
61 blockIndex[d] = std::max(0, tmpIndex);
63 int maxSize = largestImageRegion.GetSize()[d] - 1;
64 int tmpSize = dataIndex[d] + m_PatchHalfSize;
65 blockSize[d] = std::min(maxSize, tmpSize) - blockIndex[d] + 1;
67 tmpIndex = dataIndex[d] - m_MaxAbsDisp;
68 dispIndex[d] = std::max(0, tmpIndex);
70 tmpSize = dataIndex[d] + m_MaxAbsDisp;
71 dispSize[d] = std::min(maxSize,tmpSize) - dispIndex[d] + 1;
75 blockRegion.SetIndex(blockIndex);
76 blockRegion.SetSize(blockSize);
78 this->ComputeInputProperties(blockIndex,blockRegion);
81 dispRegion.SetIndex(dispIndex);
82 dispRegion.SetSize(dispSize);
84 typedef itk::ImageRegionConstIteratorWithIndex <ImageType> InIteratorType;
85 InIteratorType dispIt(m_InputImage, dispRegion);
87 typedef itk::ImageRegionConstIterator <ImageType> ComparisonIteratorType;
88 std::vector <ComparisonIteratorType> comparisonIt(numComparisonImages);
89 for (
unsigned int k = 0;k < numComparisonImages;++k)
90 comparisonIt[k] = ComparisonIteratorType(m_ComparisonImages[k],dispRegion);
92 IndexType dispBaseIndex = dispIt.GetIndex();
94 while (!dispIt.IsAtEnd())
96 dispCurIndex = dispIt.GetIndex();
98 bool onSearchStepSize(
true), movingRegionIsValid(
true), isCentralIndex(
true);
99 for (
unsigned int d = 0; d < ImageType::ImageDimension && onSearchStepSize && movingRegionIsValid; ++d)
102 if ((dispCurIndex[d] - dispBaseIndex[d]) % m_SearchStepSize)
104 onSearchStepSize =
false;
109 movingIndex[d] = blockIndex[d] + (dispCurIndex[d] - dataIndex[d]);
110 unsigned int maxBlock = movingIndex[d] + blockSize[d];
112 if (maxBlock > largestImageRegion.GetSize()[d] || movingIndex[d] < 0)
114 movingRegionIsValid =
false;
119 if (dispCurIndex[d] != dataIndex[d])
120 isCentralIndex =
false;
123 if (movingRegionIsValid && onSearchStepSize && (!isCentralIndex))
125 blockRegionMoving.SetIndex(movingIndex);
126 blockRegionMoving.SetSize(blockRegion.GetSize());
128 for (
unsigned int k = 0;k < numComparisonImages;++k)
130 this->ComputeComparisonProperties(k,blockRegionMoving);
133 if (this->TestPatchConformity(k,dataIndex,dispCurIndex))
135 double weightValue = this->ComputeWeightValue(k,blockRegion,blockRegionMoving);
136 if (weightValue > m_WeightThreshold)
138 m_DatabaseWeights.push_back(weightValue);
140 m_DatabaseSamples.push_back(comparisonIt[k].Get());
147 for (
unsigned int k = 0;k < numComparisonImages;++k)
itk::VectorImage< ImageScalarType, DataImageType::ImageDimension > ::RegionType ImageRegionType
itk::VectorImage< ImageScalarType, DataImageType::ImageDimension > ::SizeType SizeType
itk::VectorImage< ImageScalarType, DataImageType::ImageDimension > ::IndexType IndexType