Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
itkShortestPathCostFunctionLiveWire.h
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #ifndef itkShortestPathCostFunctionLiveWire_h
14 #define itkShortestPathCostFunctionLiveWire_h
15 
17 
18 #include <itkImageRegionConstIterator.h>
19 
20 namespace itk
21 {
49  template <class TInputImageType>
50  class ITK_EXPORT ShortestPathCostFunctionLiveWire : public ShortestPathCostFunction<TInputImageType>
51  {
52  public:
58  typedef itk::ImageRegionConstIterator<TInputImageType> ConstIteratorType;
59 
61  itkFactorylessNewMacro(Self);
62  itkCloneMacro(Self);
63 
66 
67  typedef itk::Image<unsigned char, 2> UnsignedCharImageType;
68  typedef itk::Image<float, 2> FloatImageType;
69 
70  typedef float ComponentType;
71  typedef itk::CovariantVector<ComponentType, 2> OutputPixelType;
72  typedef itk::Image<OutputPixelType, 2> VectorOutputImageType;
73 
74  typedef typename TInputImageType::IndexType IndexType;
75  typedef TInputImageType ImageType;
76  typedef itk::ImageRegion<2> RegionType;
77 
89  double GetCost(IndexType p1, IndexType p2) override;
90 
95  double GetMinCost() override;
96 
107  void Initialize() override;
108 
120  virtual void AddRepulsivePoint(const IndexType &index);
121 
130  virtual void RemoveRepulsivePoint(const IndexType &index);
131 
140  virtual void ClearRepulsivePoints();
141 
143  itkSetMacro(RequestedRegion, RegionType);
145  itkGetMacro(RequestedRegion, RegionType);
146 
155  void SetImage(const TInputImageType *_arg) override;
156 
169  void SetDynamicCostMap(std::map<int, int> &costMap)
170  {
171  this->m_CostMap = costMap;
172  this->m_UseCostMap = true;
173  this->m_MaxMapCosts = -1;
174  this->Modified();
175  }
176 
182  void SetUseCostMap(bool useCostMap) { this->m_UseCostMap = useCostMap; }
183 
192  void SetCostMapMaximum(double max) { this->m_MaxMapCosts = max; }
193 
198  {
199  MAPSCALEFACTOR = 10
200  };
201 
217  static double Gaussian(double x, double xOfGaussian, double yOfGaussian);
218 
223  const UnsignedCharImageType *GetMaskImage() { return this->m_MaskImage.GetPointer(); };
224 
229  const FloatImageType *GetGradientMagnitudeImage() { return this->m_GradientMagnitudeImage.GetPointer(); };
230 
235  const FloatImageType *GetEdgeImage() { return this->m_EdgeImage.GetPointer(); };
236 
241  const VectorOutputImageType *GetGradientImage() { return this->m_GradientImage.GetPointer(); };
242  protected:
244 
246 
247  FloatImageType::Pointer m_GradientMagnitudeImage;
248  FloatImageType::Pointer m_EdgeImage;
249  UnsignedCharImageType::Pointer m_MaskImage;
250  VectorOutputImageType::Pointer m_GradientImage;
251 
252  double m_MinCosts;
253 
255 
257 
260 
262 
264 
266 
267  std::map<int, int> m_CostMap;
268 
270 
272 
273  private:
274  double SigmoidFunction(double I, double max, double min, double alpha, double beta);
275  };
276 
277 } // end namespace itk
278 
279 #ifndef ITK_MANUAL_INSTANTIATION
280 #include <itkShortestPathCostFunctionLiveWire.tpp>
281 #endif
282 
283 #endif /* itkShortestPathCostFunctionLiveWire_h */
Cost function for LiveWire interactive segmentation.
const UnsignedCharImageType * GetMaskImage()
Get the repulsive-point mask image.
void Initialize() override
Initialize the cost function by computing derived images.
itk::ImageRegionConstIterator< TInputImageType > ConstIteratorType
const FloatImageType * GetEdgeImage()
Get the computed edge image (Canny edge detection result).
virtual void ClearRepulsivePoints()
Clear all repulsive points from the cost function.
const FloatImageType * GetGradientMagnitudeImage()
Get the computed gradient magnitude image.
void SetCostMapMaximum(double max)
Set the maximum value of the dynamic cost map.
virtual void RemoveRepulsivePoint(const IndexType &index)
Remove a repulsive point from the cost map.
void SetImage(const TInputImageType *_arg) override
Set the input image and initialize the mask image.
ShortestPathCostFunction< TInputImageType > Superclass
static double Gaussian(double x, double xOfGaussian, double yOfGaussian)
Evaluate a Gaussian function at position x.
void SetUseCostMap(bool useCostMap)
Enable or disable the dynamic cost map.
void SetDynamicCostMap(std::map< int, int > &costMap)
Set a dynamic (non-linear) cost map for gradient magnitude mapping.
itk::CovariantVector< ComponentType, 2 > OutputPixelType
double GetCost(IndexType p1, IndexType p2) override
Calculate the weighted cost of transitioning from p1 to p2.
virtual void AddRepulsivePoint(const IndexType &index)
Mark a pixel as repulsive in the cost map.
Constants
Constants used internally for cost map scaling.
double GetMinCost() override
Return the minimal possible cost (needed for the A* heuristic).
const VectorOutputImageType * GetGradientImage()
Get the computed gradient vector image.
Abstract base class for cost functions used by ShortestPathImageFilter.
TInputImageType::IndexType IndexType
TInputImageType::PixelType PixelType