Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
itk::ShortestPathCostFunctionLiveWire< TInputImageType > Class Template Reference

Cost function for LiveWire interactive segmentation. More...

#include <itkShortestPathCostFunctionLiveWire.h>

Inheritance diagram for itk::ShortestPathCostFunctionLiveWire< TInputImageType >:
Collaboration diagram for itk::ShortestPathCostFunctionLiveWire< TInputImageType >:

Public Types

enum  Constants { MAPSCALEFACTOR }
 Constants used internally for cost map scaling. More...
 
typedef ShortestPathCostFunctionLiveWire Self
 
typedef ShortestPathCostFunction< TInputImageType > Superclass
 
typedef SmartPointer< Self > Pointer
 
typedef SmartPointer< const Self > ConstPointer
 
typedef itk::ImageRegionConstIterator< TInputImageType > ConstIteratorType
 
typedef itk::Image< unsigned char, 2 > UnsignedCharImageType
 
typedef itk::Image< float, 2 > FloatImageType
 
typedef float ComponentType
 
typedef itk::CovariantVector< ComponentType, 2 > OutputPixelType
 
typedef itk::Image< OutputPixelType, 2 > VectorOutputImageType
 
typedef TInputImageType::IndexType IndexType
 
typedef TInputImageType ImageType
 
typedef itk::ImageRegion< 2 > RegionType
 
- Public Types inherited from itk::ShortestPathCostFunction< TInputImageType >
typedef ShortestPathCostFunction Self
 
typedef Object Superclass
 
typedef SmartPointer< Self > Pointer
 
typedef SmartPointer< const Self > ConstPointer
 
typedef ShapedNeighborhoodIterator< TInputImageType > ShapedNeighborhoodIteratorType
 
typedef TInputImageType ImageType
 
typedef TInputImageType::Pointer ImagePointer
 
typedef TInputImageType::ConstPointer ImageConstPointer
 
typedef TInputImageType::PixelType PixelType
 
typedef TInputImageType::IndexType IndexType
 

Public Member Functions

Pointer Clone () const
 
virtual const char * GetClassName () const
 
double GetCost (IndexType p1, IndexType p2) override
 Calculate the weighted cost of transitioning from p1 to p2. More...
 
double GetMinCost () override
 Return the minimal possible cost (needed for the A* heuristic). More...
 
void Initialize () override
 Initialize the cost function by computing derived images. More...
 
virtual void AddRepulsivePoint (const IndexType &index)
 Mark a pixel as repulsive in the cost map. More...
 
virtual void RemoveRepulsivePoint (const IndexType &index)
 Remove a repulsive point from the cost map. More...
 
virtual void ClearRepulsivePoints ()
 Clear all repulsive points from the cost function. More...
 
virtual void SetRequestedRegion (RegionType _arg)
 Set the requested image region for processing. More...
 
virtual RegionType GetRequestedRegion ()
 Get the requested image region. More...
 
void SetImage (const TInputImageType *_arg) override
 Set the input image and initialize the mask image. More...
 
void SetDynamicCostMap (std::map< int, int > &costMap)
 Set a dynamic (non-linear) cost map for gradient magnitude mapping. More...
 
void SetUseCostMap (bool useCostMap)
 Enable or disable the dynamic cost map. More...
 
void SetCostMapMaximum (double max)
 Set the maximum value of the dynamic cost map. More...
 
const UnsignedCharImageType * GetMaskImage ()
 Get the repulsive-point mask image. More...
 
const FloatImageType * GetGradientMagnitudeImage ()
 Get the computed gradient magnitude image. More...
 
const FloatImageType * GetEdgeImage ()
 Get the computed edge image (Canny edge detection result). More...
 
const VectorOutputImageType * GetGradientImage ()
 Get the computed gradient vector image. More...
 
- Public Member Functions inherited from itk::ShortestPathCostFunction< TInputImageType >
void SetStartIndex (const IndexType &index)
 Set the starting index of the path. More...
 
void SetEndIndex (const IndexType &index)
 Set the ending index of the path. More...
 

Static Public Member Functions

static Pointer New ()
 
static double Gaussian (double x, double xOfGaussian, double yOfGaussian)
 Evaluate a Gaussian function at position x. More...
 

Protected Member Functions

 ShortestPathCostFunctionLiveWire ()
 
 ~ShortestPathCostFunctionLiveWire () override
 
- Protected Member Functions inherited from itk::ShortestPathCostFunction< TInputImageType >
 ShortestPathCostFunction ()
 
 ~ShortestPathCostFunction () override
 
void PrintSelf (std::ostream &os, Indent indent) const override
 

Protected Attributes

FloatImageType::Pointer m_GradientMagnitudeImage
 
FloatImageType::Pointer m_EdgeImage
 
UnsignedCharImageType::Pointer m_MaskImage
 
VectorOutputImageType::Pointer m_GradientImage
 
double m_MinCosts
 
bool m_UseRepulsivePoints
 
Superclass::PixelType val
 
Superclass::PixelType startValue
 
Superclass::PixelType endValue
 
double m_GradientMax
 
RegionType m_RequestedRegion
 
bool m_Initialized
 
std::map< int, int > m_CostMap
 
bool m_UseCostMap
 
double m_MaxMapCosts
 
- Protected Attributes inherited from itk::ShortestPathCostFunction< TInputImageType >
ImageConstPointer m_Image
 The input image used for cost computation. More...
 
IndexType m_StartIndex
 
IndexType m_EndIndex
 Start and end indices defining the path endpoints. More...
 

Detailed Description

template<class TInputImageType>
class itk::ShortestPathCostFunctionLiveWire< TInputImageType >

Cost function for LiveWire interactive segmentation.

This cost function computes the cumulative link cost between two neighboring pixels using a weighted combination of three image features:

  • Gradient Magnitude: Mapped linearly (or dynamically via a cost map) to values between 0 (strong edge, low cost) and 1 (weak edge, high cost).
  • Gradient Direction: The angular difference between gradient vectors at the two pixels, normalized to [0, 1].
  • Laplacian Zero Crossing (via Canny edge detection): Binary cost of 0 at edge pixels and 1 elsewhere.

By default, gradient magnitude is mapped linearly to cost values. A dynamic cost map can be set via SetDynamicCostMap() to use a non-linear mapping based on an inverted histogram of the gradient magnitude image.

The cost is scaled by the Euclidean distance between the two pixels (1.0 for horizontal/vertical neighbors, sqrt(2) for diagonal neighbors).

Repulsive points can be added to force the path away from certain pixels.

Template Parameters
TInputImageTypeThe ITK image type used as input (typically 2D).
See also
ShortestPathCostFunction
ShortestPathImageFilter

Definition at line 50 of file itkShortestPathCostFunctionLiveWire.h.

Member Typedef Documentation

◆ ComponentType

template<class TInputImageType >
typedef float itk::ShortestPathCostFunctionLiveWire< TInputImageType >::ComponentType

Definition at line 70 of file itkShortestPathCostFunctionLiveWire.h.

◆ ConstIteratorType

template<class TInputImageType >
typedef itk::ImageRegionConstIterator<TInputImageType> itk::ShortestPathCostFunctionLiveWire< TInputImageType >::ConstIteratorType

Definition at line 58 of file itkShortestPathCostFunctionLiveWire.h.

◆ ConstPointer

template<class TInputImageType >
typedef SmartPointer<const Self> itk::ShortestPathCostFunctionLiveWire< TInputImageType >::ConstPointer

Definition at line 57 of file itkShortestPathCostFunctionLiveWire.h.

◆ FloatImageType

template<class TInputImageType >
typedef itk::Image<float, 2> itk::ShortestPathCostFunctionLiveWire< TInputImageType >::FloatImageType

Definition at line 68 of file itkShortestPathCostFunctionLiveWire.h.

◆ ImageType

template<class TInputImageType >
typedef TInputImageType itk::ShortestPathCostFunctionLiveWire< TInputImageType >::ImageType

Definition at line 75 of file itkShortestPathCostFunctionLiveWire.h.

◆ IndexType

template<class TInputImageType >
typedef TInputImageType::IndexType itk::ShortestPathCostFunctionLiveWire< TInputImageType >::IndexType

Definition at line 74 of file itkShortestPathCostFunctionLiveWire.h.

◆ OutputPixelType

template<class TInputImageType >
typedef itk::CovariantVector<ComponentType, 2> itk::ShortestPathCostFunctionLiveWire< TInputImageType >::OutputPixelType

Definition at line 71 of file itkShortestPathCostFunctionLiveWire.h.

◆ Pointer

template<class TInputImageType >
typedef SmartPointer<Self> itk::ShortestPathCostFunctionLiveWire< TInputImageType >::Pointer

Definition at line 56 of file itkShortestPathCostFunctionLiveWire.h.

◆ RegionType

template<class TInputImageType >
typedef itk::ImageRegion<2> itk::ShortestPathCostFunctionLiveWire< TInputImageType >::RegionType

Definition at line 76 of file itkShortestPathCostFunctionLiveWire.h.

◆ Self

template<class TInputImageType >
typedef ShortestPathCostFunctionLiveWire itk::ShortestPathCostFunctionLiveWire< TInputImageType >::Self

Standard class typedefs.

Definition at line 54 of file itkShortestPathCostFunctionLiveWire.h.

◆ Superclass

template<class TInputImageType >
typedef ShortestPathCostFunction<TInputImageType> itk::ShortestPathCostFunctionLiveWire< TInputImageType >::Superclass

Definition at line 55 of file itkShortestPathCostFunctionLiveWire.h.

◆ UnsignedCharImageType

template<class TInputImageType >
typedef itk::Image<unsigned char, 2> itk::ShortestPathCostFunctionLiveWire< TInputImageType >::UnsignedCharImageType

Definition at line 67 of file itkShortestPathCostFunctionLiveWire.h.

◆ VectorOutputImageType

template<class TInputImageType >
typedef itk::Image<OutputPixelType, 2> itk::ShortestPathCostFunctionLiveWire< TInputImageType >::VectorOutputImageType

Definition at line 72 of file itkShortestPathCostFunctionLiveWire.h.

Member Enumeration Documentation

◆ Constants

template<class TInputImageType >
enum itk::ShortestPathCostFunctionLiveWire::Constants

Constants used internally for cost map scaling.

Enumerator
MAPSCALEFACTOR 

Scale factor applied to gradient magnitude for cost map lookup.

Definition at line 197 of file itkShortestPathCostFunctionLiveWire.h.

Constructor & Destructor Documentation

◆ ShortestPathCostFunctionLiveWire()

template<class TInputImageType >
itk::ShortestPathCostFunctionLiveWire< TInputImageType >::ShortestPathCostFunctionLiveWire ( )
protected

◆ ~ShortestPathCostFunctionLiveWire()

template<class TInputImageType >
itk::ShortestPathCostFunctionLiveWire< TInputImageType >::~ShortestPathCostFunctionLiveWire ( )
inlineoverrideprotected

Definition at line 245 of file itkShortestPathCostFunctionLiveWire.h.

Member Function Documentation

◆ AddRepulsivePoint()

template<class TInputImageType >
virtual void itk::ShortestPathCostFunctionLiveWire< TInputImageType >::AddRepulsivePoint ( const IndexType &  index)
virtual

Mark a pixel as repulsive in the cost map.

Pixels marked as repulsive receive a very high cost (1000) to discourage the shortest path from passing through them.

Parameters
[in]indexThe pixel index to mark as repulsive.
See also
RemoveRepulsivePoint
ClearRepulsivePoints

◆ ClearRepulsivePoints()

template<class TInputImageType >
virtual void itk::ShortestPathCostFunctionLiveWire< TInputImageType >::ClearRepulsivePoints ( )
virtual

Clear all repulsive points from the cost function.

Resets the mask image to zero and disables repulsive point checking.

See also
AddRepulsivePoint
RemoveRepulsivePoint

◆ Clone()

template<class TInputImageType >
Pointer itk::ShortestPathCostFunctionLiveWire< TInputImageType >::Clone ( ) const

◆ Gaussian()

template<class TInputImageType >
static double itk::ShortestPathCostFunctionLiveWire< TInputImageType >::Gaussian ( double  x,
double  xOfGaussian,
double  yOfGaussian 
)
static

Evaluate a Gaussian function at position x.

Computes the Gaussian approximation:

f(x) = yOfGaussian * exp( -0.5 * (x - xOfGaussian)^2 )

Used for interpolating between cost map entries.

Parameters
[in]xThe position at which to evaluate.
[in]xOfGaussianThe center (mean) of the Gaussian.
[in]yOfGaussianThe amplitude (peak value) of the Gaussian.
Returns
The Gaussian value at position x.

◆ GetClassName()

template<class TInputImageType >
virtual const char* itk::ShortestPathCostFunctionLiveWire< TInputImageType >::GetClassName ( ) const
virtual

Run-time type information (and related methods).

Reimplemented from itk::ShortestPathCostFunction< TInputImageType >.

◆ GetCost()

template<class TInputImageType >
double itk::ShortestPathCostFunctionLiveWire< TInputImageType >::GetCost ( IndexType  p1,
IndexType  p2 
)
overridevirtual

Calculate the weighted cost of transitioning from p1 to p2.

The cost is a weighted sum of Laplacian zero-crossing cost, gradient magnitude cost, and gradient direction cost, scaled by the Euclidean distance between the two pixels.

Parameters
[in]p1The source pixel index.
[in]p2The destination pixel index.
Returns
The combined weighted cost. Returns 1000 if either pixel is a repulsive point.

Implements itk::ShortestPathCostFunction< TInputImageType >.

◆ GetEdgeImage()

template<class TInputImageType >
const FloatImageType* itk::ShortestPathCostFunctionLiveWire< TInputImageType >::GetEdgeImage ( )
inline

Get the computed edge image (Canny edge detection result).

Returns
Pointer to the edge image.

Definition at line 235 of file itkShortestPathCostFunctionLiveWire.h.

◆ GetGradientImage()

template<class TInputImageType >
const VectorOutputImageType* itk::ShortestPathCostFunctionLiveWire< TInputImageType >::GetGradientImage ( )
inline

Get the computed gradient vector image.

Returns
Pointer to the 2D gradient vector image.

Definition at line 241 of file itkShortestPathCostFunctionLiveWire.h.

◆ GetGradientMagnitudeImage()

template<class TInputImageType >
const FloatImageType* itk::ShortestPathCostFunctionLiveWire< TInputImageType >::GetGradientMagnitudeImage ( )
inline

Get the computed gradient magnitude image.

Returns
Pointer to the gradient magnitude image.

Definition at line 229 of file itkShortestPathCostFunctionLiveWire.h.

◆ GetMaskImage()

template<class TInputImageType >
const UnsignedCharImageType* itk::ShortestPathCostFunctionLiveWire< TInputImageType >::GetMaskImage ( )
inline

Get the repulsive-point mask image.

Returns
Pointer to the mask image (pixel value 255 = repulsive, 0 = normal).

Definition at line 223 of file itkShortestPathCostFunctionLiveWire.h.

◆ GetMinCost()

template<class TInputImageType >
double itk::ShortestPathCostFunctionLiveWire< TInputImageType >::GetMinCost ( )
overridevirtual

Return the minimal possible cost (needed for the A* heuristic).

Returns
The stored minimum cost value (0 by default, yielding Dijkstra behavior).

Implements itk::ShortestPathCostFunction< TInputImageType >.

◆ GetRequestedRegion()

template<class TInputImageType >
virtual RegionType itk::ShortestPathCostFunctionLiveWire< TInputImageType >::GetRequestedRegion ( )
virtual

Get the requested image region.

◆ Initialize()

template<class TInputImageType >
void itk::ShortestPathCostFunctionLiveWire< TInputImageType >::Initialize ( )
overridevirtual

Initialize the cost function by computing derived images.

Computes gradient magnitude, gradient direction, and Canny edge detection images from the input image. Also initializes the mask image for repulsive points. Only performs computation on the first call; subsequent calls only update start/end pixel values.

Precondition
The input image must have been set via SetImage().

Implements itk::ShortestPathCostFunction< TInputImageType >.

◆ New()

template<class TInputImageType >
static Pointer itk::ShortestPathCostFunctionLiveWire< TInputImageType >::New ( )
static

Method for creation through the object factory.

◆ RemoveRepulsivePoint()

template<class TInputImageType >
virtual void itk::ShortestPathCostFunctionLiveWire< TInputImageType >::RemoveRepulsivePoint ( const IndexType &  index)
virtual

Remove a repulsive point from the cost map.

Parameters
[in]indexThe pixel index to unmark.
See also
AddRepulsivePoint
ClearRepulsivePoints

◆ SetCostMapMaximum()

template<class TInputImageType >
void itk::ShortestPathCostFunctionLiveWire< TInputImageType >::SetCostMapMaximum ( double  max)
inline

Set the maximum value of the dynamic cost map.

Used for normalization when the dynamic cost map is active. Setting this avoids recomputing the maximum from the map each time.

Parameters
[in]maxThe maximum cost map value.

Definition at line 192 of file itkShortestPathCostFunctionLiveWire.h.

◆ SetDynamicCostMap()

template<class TInputImageType >
void itk::ShortestPathCostFunctionLiveWire< TInputImageType >::SetDynamicCostMap ( std::map< int, int > &  costMap)
inline

Set a dynamic (non-linear) cost map for gradient magnitude mapping.

The map keys are integer-scaled gradient magnitude values, and the map values represent corresponding histogram-derived weights. When set, a Gaussian interpolation is used instead of linear mapping.

Parameters
[in,out]costMapThe cost map to use. Stored by copy.
See also
SetUseCostMap
SetCostMapMaximum

Definition at line 169 of file itkShortestPathCostFunctionLiveWire.h.

◆ SetImage()

template<class TInputImageType >
void itk::ShortestPathCostFunctionLiveWire< TInputImageType >::SetImage ( const TInputImageType *  _arg)
overridevirtual

Set the input image and initialize the mask image.

Overrides the base class to additionally allocate and initialize the repulsive-point mask image to match the input image's geometry.

Parameters
[in]_argThe input image.

Reimplemented from itk::ShortestPathCostFunction< TInputImageType >.

◆ SetRequestedRegion()

template<class TInputImageType >
virtual void itk::ShortestPathCostFunctionLiveWire< TInputImageType >::SetRequestedRegion ( RegionType  _arg)
virtual

Set the requested image region for processing.

◆ SetUseCostMap()

template<class TInputImageType >
void itk::ShortestPathCostFunctionLiveWire< TInputImageType >::SetUseCostMap ( bool  useCostMap)
inline

Enable or disable the dynamic cost map.

Parameters
[in]useCostMapIf true, use the dynamic cost map; if false, use linear mapping.

Definition at line 182 of file itkShortestPathCostFunctionLiveWire.h.

Member Data Documentation

◆ endValue

template<class TInputImageType >
Superclass::PixelType itk::ShortestPathCostFunctionLiveWire< TInputImageType >::endValue
protected

Definition at line 259 of file itkShortestPathCostFunctionLiveWire.h.

◆ m_CostMap

template<class TInputImageType >
std::map<int, int> itk::ShortestPathCostFunctionLiveWire< TInputImageType >::m_CostMap
protected

Definition at line 267 of file itkShortestPathCostFunctionLiveWire.h.

◆ m_EdgeImage

template<class TInputImageType >
FloatImageType::Pointer itk::ShortestPathCostFunctionLiveWire< TInputImageType >::m_EdgeImage
protected

Definition at line 248 of file itkShortestPathCostFunctionLiveWire.h.

◆ m_GradientImage

template<class TInputImageType >
VectorOutputImageType::Pointer itk::ShortestPathCostFunctionLiveWire< TInputImageType >::m_GradientImage
protected

Definition at line 250 of file itkShortestPathCostFunctionLiveWire.h.

◆ m_GradientMagnitudeImage

template<class TInputImageType >
FloatImageType::Pointer itk::ShortestPathCostFunctionLiveWire< TInputImageType >::m_GradientMagnitudeImage
protected

Definition at line 247 of file itkShortestPathCostFunctionLiveWire.h.

◆ m_GradientMax

template<class TInputImageType >
double itk::ShortestPathCostFunctionLiveWire< TInputImageType >::m_GradientMax
protected

Definition at line 261 of file itkShortestPathCostFunctionLiveWire.h.

◆ m_Initialized

template<class TInputImageType >
bool itk::ShortestPathCostFunctionLiveWire< TInputImageType >::m_Initialized
protected

Definition at line 265 of file itkShortestPathCostFunctionLiveWire.h.

◆ m_MaskImage

template<class TInputImageType >
UnsignedCharImageType::Pointer itk::ShortestPathCostFunctionLiveWire< TInputImageType >::m_MaskImage
protected

Definition at line 249 of file itkShortestPathCostFunctionLiveWire.h.

◆ m_MaxMapCosts

template<class TInputImageType >
double itk::ShortestPathCostFunctionLiveWire< TInputImageType >::m_MaxMapCosts
protected

Definition at line 271 of file itkShortestPathCostFunctionLiveWire.h.

◆ m_MinCosts

template<class TInputImageType >
double itk::ShortestPathCostFunctionLiveWire< TInputImageType >::m_MinCosts
protected

Definition at line 252 of file itkShortestPathCostFunctionLiveWire.h.

◆ m_RequestedRegion

template<class TInputImageType >
RegionType itk::ShortestPathCostFunctionLiveWire< TInputImageType >::m_RequestedRegion
protected

Definition at line 263 of file itkShortestPathCostFunctionLiveWire.h.

◆ m_UseCostMap

template<class TInputImageType >
bool itk::ShortestPathCostFunctionLiveWire< TInputImageType >::m_UseCostMap
protected

Definition at line 269 of file itkShortestPathCostFunctionLiveWire.h.

◆ m_UseRepulsivePoints

template<class TInputImageType >
bool itk::ShortestPathCostFunctionLiveWire< TInputImageType >::m_UseRepulsivePoints
protected

Definition at line 254 of file itkShortestPathCostFunctionLiveWire.h.

◆ startValue

template<class TInputImageType >
Superclass::PixelType itk::ShortestPathCostFunctionLiveWire< TInputImageType >::startValue
protected

Definition at line 258 of file itkShortestPathCostFunctionLiveWire.h.

◆ val

template<class TInputImageType >
Superclass::PixelType itk::ShortestPathCostFunctionLiveWire< TInputImageType >::val
protected

Definition at line 256 of file itkShortestPathCostFunctionLiveWire.h.


The documentation for this class was generated from the following file: