4 #include <itkImageRegionIterator.h> 5 #include <itkImageRegionConstIterator.h> 7 #include <itkThresholdImageFilter.h> 8 #include <itkThresholdLabelerImageFilter.h> 9 #include <itkSignedMaurerDistanceMapImageFilter.h> 14 template <
class TScalarType,
unsigned int NDegreesOfFreedom,
unsigned int NDimensions>
19 unsigned int nbInputs = this->GetNumberOfIndexedInputs();
21 itkExceptionMacro(
"Error: There should be one input...");
23 if (!this->GetRunningInPlace())
24 itkExceptionMacro(
"Error: this filter is made to run in place.");
26 this->Superclass::BeforeThreadedGenerateData();
29 typedef itk::Image <unsigned char, NDimensions> MaskImageType;
30 typedef itk::ThresholdImageFilter <WeightImageType> ThresholdFilterType;
31 typedef itk::ThresholdLabelerImageFilter <WeightImageType, MaskImageType> LabelerFilterType;
33 typename ThresholdFilterType::Pointer thrFilter = ThresholdFilterType::New();
34 thrFilter->SetInput(m_WeightImage);
35 thrFilter->SetNumberOfWorkUnits(this->GetNumberOfWorkUnits());
36 thrFilter->ThresholdBelow(1.0e-3);
38 typename LabelerFilterType::Pointer labelFilter = LabelerFilterType::New();
39 labelFilter->SetInput(thrFilter->GetOutput());
40 typename LabelerFilterType::RealThresholdVector thrVals;
43 labelFilter->SetRealThresholds(thrVals);
44 labelFilter->SetNumberOfWorkUnits(this->GetNumberOfWorkUnits());
45 labelFilter->Update();
47 typedef itk::SignedMaurerDistanceMapImageFilter <MaskImageType, WeightImageType> DistanceFilterType;
48 typename DistanceFilterType::Pointer distFilter = DistanceFilterType::New();
50 distFilter->SetInput(labelFilter->GetOutput());
51 distFilter->SetNumberOfWorkUnits(this->GetNumberOfWorkUnits());
52 distFilter->SetSquaredDistance(
false);
53 distFilter->SetBackgroundValue(0);
54 distFilter->InsideIsPositiveOff();
55 distFilter->UseImageSpacingOn();
58 m_DistanceImage = distFilter->GetOutput();
59 m_DistanceImage->DisconnectPipeline();
62 template <
class TScalarType,
unsigned int NDegreesOfFreedom,
unsigned int NDimensions>
67 typedef itk::ImageRegionIterator <TOutputImage> OutRegionIteratorType;
68 OutRegionIteratorType outIterator(this->GetOutput(), outputRegionForThread);
70 itk::ImageRegionConstIterator <WeightImageType> weightItr(m_WeightImage,outputRegionForThread);
71 itk::ImageRegionConstIterator <WeightImageType> distItr(m_DistanceImage,outputRegionForThread);
76 while (!outIterator.IsAtEnd())
78 double weight = weightItr.Value();
81 curTrsf = outIterator.Get();
83 double distValue = distItr.Value();
84 double externalWeight = 1.0;
87 double centerDist = distValue / (3.0 * m_ExtrapolationSigma);
91 externalWeight = std::pow((1.0 - centerDist), 4) * (4.0 * centerDist + 1.0);
94 curTrsf *= externalWeight / weight;
95 outIterator.Set(curTrsf);
98 outIterator.Set(zeroTrsf);