18 #ifndef __itkPSMImageDomainWithCurvature_h 19 #define __itkPSMImageDomainWithCurvature_h 21 #include "itkPSMImageDomainWithHessians.h" 22 #include "itkImageRegionIteratorWithIndex.h" 23 #include "itkImageRegionIterator.h" 24 #include "itkDiscreteGaussianImageFilter.h" 39 template <
class T,
unsigned int VDimension>
47 typedef SmartPointer<Self> Pointer;
48 typedef SmartPointer<const Self> ConstPointer;
49 typedef WeakPointer<const Self> ConstWeakPointer;
51 typedef typename Superclass::PointType
PointType;
52 typedef typename Superclass::ImageType
ImageType;
53 typedef typename Superclass::ScalarInterpolatorType ScalarInterpolatorType;
54 typedef typename Superclass::VnlMatrixType VnlMatrixType;
63 itkStaticConstMacro(Dimension,
unsigned int, VDimension);
70 Superclass::SetImage(I);
72 typedef itk::DiscreteGaussianImageFilter<ImageType, ImageType> DiscreteGaussianImageFilterType;
73 typename DiscreteGaussianImageFilterType::Pointer f = DiscreteGaussianImageFilterType::New();
75 double sig = this->GetImage()->GetSpacing()[0] * 0.5;
78 f->SetInput(this->GetImage());
79 f->SetUseImageSpacingOn();
85 m_CurvatureImage = f->GetOutput();
88 itk::ImageRegionIteratorWithIndex<ImageType> it(f->GetOutput(),
89 f->GetOutput()->GetRequestedRegion());
90 itk::ImageRegionIterator<ImageType> oit(m_CurvatureImage, f->GetOutput()->GetRequestedRegion());
92 for (; !it.IsAtEnd(); ++it, ++oit)
95 if (it.Get() < 4.0 && it.Get() > -4.0)
98 this->GetImage()->TransformIndexToPhysicalPoint(it.GetIndex(), pos);
99 oit.Set(this->MeanCurvature(pos));
101 else oit.Set(1.0e-6);
105 this->DeletePartialDerivativeImages();
107 m_CurvatureInterpolator->SetInputImage(m_CurvatureImage);
110 double GetCurvature(
const PointType &pos)
const 112 return m_CurvatureInterpolator->Evaluate(pos);
115 typename ImageType::Pointer *GetCurvatureImage()
116 {
return m_CurvatureImage; }
121 m_CurvatureInterpolator = ScalarInterpolatorType::New();
122 m_CurvatureImage = ImageType::New();
125 void PrintSelf(std::ostream& os, Indent indent)
const 127 Superclass::PrintSelf(os, indent);
131 double MeanCurvature(
const PointType& pos)
138 typename Superclass::VnlVectorType posnormal = this->SampleNormalVnl(pos, 1.0e-6);
141 typename Superclass::VnlMatrixType I;
144 typename Superclass::VnlMatrixType H = this->SampleHessianVnl(pos);
145 typename Superclass::VnlMatrixType P = I - outer_product(posnormal, posnormal);
146 typename Superclass::VnlMatrixType G = P.transpose() * H * P;
149 double frobnorm = sqrt(fabs(this->vnl_trace(G * G.transpose())) + 1.0e-10);
150 double trace = this->vnl_trace(G);
154 double diff1 = frobnorm * frobnorm *2.0;
155 double diff2 = trace * trace;
158 if (frobnorm <= trace) frobnorm2 = 0.0;
159 else frobnorm2 = sqrt((diff1 - diff2 < 0.0) ? 0.0 : diff1 - diff2);
160 double k1 = (trace + frobnorm2) * 0.5;
161 double k2 = (trace - frobnorm2) * 0.5;
166 return sqrt(k1 * k1 + k2 * k2);
169 inline double vnl_trace(
const VnlMatrixType &m)
const 172 for (
unsigned int i = 0; i < VDimension; i++)
181 void operator=(
const Self&);
184 typename ImageType::Pointer m_CurvatureImage;
185 typename ScalarInterpolatorType::Pointer m_CurvatureInterpolator;
Image< T, VDimension > ImageType
PSMImageDomainWithCurvature Self
void SetImage(ImageType *I)