void PatchMatch<TImage, TPropagation, TRandomSearch>::RandomlyInitializeNNField() { itk::ImageRegion<2> internalRegion = ITKHelpers::GetInternalRegion(this->Image->GetLargestPossibleRegion(), this->PatchRadius); this->NNField->SetRegions(this->Image->GetLargestPossibleRegion()); this->NNField->Allocate(); itk::ImageRegionIteratorWithIndex<NNFieldType> nnFieldIterator(this->NNField, internalRegion); while(!nnFieldIterator.IsAtEnd()) { itk::ImageRegion<2> targetRegion = ITKHelpers::GetRegionInRadiusAroundPixel(nnFieldIterator.GetIndex(), this->PatchRadius); itk::ImageRegion<2> randomRegion = PatchMatchHelpers::GetRandomRegionInRegion(internalRegion, this->PatchRadius); Match randomMatch; randomMatch.SetRegion(randomRegion); randomMatch.SetScore(this->RandomSearchFunctor->GetPatchDistanceFunctor()->Distance(randomRegion, targetRegion)); nnFieldIterator.Set(randomMatch); ++nnFieldIterator; } }
void ReadNNField(const std::string& fileName, const unsigned int patchRadius, NNFieldType* const nnField) { typedef itk::ImageFileReader<CoordinateImageType> NNFieldReaderType; NNFieldReaderType::Pointer nnFieldReader = NNFieldReaderType::New(); nnFieldReader->SetFileName(fileName); nnFieldReader->Update(); itk::ImageRegionIterator<CoordinateImageType> imageIterator(nnFieldReader->GetOutput(), nnFieldReader->GetOutput()->GetLargestPossibleRegion()); while(!imageIterator.IsAtEnd()) { Match match; itk::Index<2> center = {{static_cast<unsigned int>(imageIterator.Get()[0]), static_cast<unsigned int>(imageIterator.Get()[1])}}; itk::ImageRegion<2> region = ITKHelpers::GetRegionInRadiusAroundPixel(center, patchRadius); match.SetRegion(region); nnField->SetPixel(imageIterator.GetIndex(), match); ++imageIterator; } }