SimpleITK  
itk::simple::ContourExtractor2DImageFilter Class Reference

Computes a list of PolyLineParametricPath objects from the contours in a 2D image. More...

#include <sitkContourExtractor2DImageFilter.h>

+ Inheritance diagram for itk::simple::ContourExtractor2DImageFilter:
+ Collaboration diagram for itk::simple::ContourExtractor2DImageFilter:

Detailed Description

Computes a list of PolyLineParametricPath objects from the contours in a 2D image.

Uses the "marching squares" method to compute a the iso-valued contours of the input 2D image for a given intensity value. Multiple outputs may be produced because an image can have multiple contours at a given level, so it is advised to call GetNumberOfIndexedOutputs() and GetOutput(n) to retrieve all of the contours. The contour value to be extracted can be set with SetContourValue(). Image intensities will be linearly interpolated to provide sub-pixel resolution for the output contours.

The marching squares algorithm is a special case of the marching cubes algorithm [73]. A simple explanation is available here: http://users.polytech.unice.fr/~lingrand/MarchingCubes/algo.html

There is an ambiguous case in the marching squares algorithm: if a given 2x2-pixel square has two high-valued and two low-valued pixels, each pair diagonally adjacent. (Note that high-valued and low-valued are with respect to the contour value sought when LabelContours is false. When LabelContours is true, high-valued means the label being traced and low-valued means any other label.) In this case, the default behavior is that the low-valued pixels are connected into the same contour via an isthmus that separates the high-valued pixels into separate contours. To reverse this, call VertexConnectHighPixelsOn(). Note that when LabelContours is true, the default behavior will leave all four pixels in separate contours. In this case, VertexConnectHighPixels equal to true can instead create contours that are crossing barbells.

Outputs are not guaranteed to be closed paths: contours which intersect the image edge will be left open. All other paths will be closed. (The closedness of a path can be tested by checking whether the beginning point is the same as the end point.)

Produced paths are oriented. Following the path from beginning to end, image intensity values lower than the contour value are to the left of the path and intensity values greater than the contour value are to the right. In other words, the image gradient at a path segment is (approximately) in the direct of that segment rotated right by 90 degrees, because the image intensity values increase from left-to-right across the segment. This means that the generated contours will circle clockwise around "hills" of above-contour-value intensity, and counter-clockwise around "depressions" of below-contour-value intensity. This convention can be reversed by calling ReverseContourOrientationOn().

By default values are interpreted as intensities relative to a contour value. First calling LabelContoursOn() changes this behavior to instead interpret each value as a label. Boundaries are computed for each label separately and all are returned. The value of LabelContours affects the interpretation of VertexConnectHighPixels; see above.

By default the input image's largest possible region will be processed; call SetRequestedRegion() to process a different region, or ClearRequestedRegion() to revert to the default value. Note that the requested regions are usually set on the output; however since paths have no notion of a "region", this must be set at the filter level.

This class was contributed to the Insight Journal by Zachary Pincus. https://doi.org/10.54294/olkmog

See also
itk::ContourExtractor2DImageFilter for the Doxygen on the original ITK class.

Definition at line 80 of file sitkContourExtractor2DImageFilter.h.

Public Types

using PixelIDTypeList = BasicPixelIDTypeList
 
using Self = ContourExtractor2DImageFilter
 
- Public Types inherited from itk::simple::ImageFilter
using Self = ImageFilter
 
- Public Types inherited from itk::simple::ProcessObject
using Self = ProcessObject
 

Public Member Functions

 ContourExtractor2DImageFilter ()
 
void Execute (const Image &image1)
 
std::vector< double > GetContour (unsigned int n) const
 
double GetContourValue () const
 
bool GetLabelContours () const
 
std::string GetName () const
 
unsigned int GetNumberOfCountours () const
 
bool GetReverseContourOrientation () const
 
bool GetVertexConnectHighPixels () const
 
void LabelContoursOff ()
 
void LabelContoursOn ()
 
void ReverseContourOrientationOff ()
 
void ReverseContourOrientationOn ()
 
void SetContourValue (double ContourValue)
 
void SetLabelContours (bool LabelContours)
 
void SetReverseContourOrientation (bool ReverseContourOrientation)
 
void SetVertexConnectHighPixels (bool VertexConnectHighPixels)
 
std::string ToString () const
 
void VertexConnectHighPixelsOff ()
 
void VertexConnectHighPixelsOn ()
 
virtual ~ContourExtractor2DImageFilter ()
 
- Public Member Functions inherited from itk::simple::ImageFilter
 ImageFilter ()
 
virtual ~ImageFilter ()=0
 
- Public Member Functions inherited from itk::simple::ProcessObject
virtual void Abort ()
 
virtual int AddCommand (itk::simple::EventEnum event, const std::function< void()> &func)
 Directly add a callback to observe an event.
 
virtual int AddCommand (itk::simple::EventEnum event, itk::simple::Command &cmd)
 Add a Command Object to observer the event.
 
virtual float GetProgress () const
 An Active Measurement of the progress of execution.
 
virtual bool HasCommand (itk::simple::EventEnum event) const
 Query of this object has any registered commands for event.
 
 ProcessObject ()
 
virtual void RemoveAllCommands ()
 Remove all registered commands.
 
virtual ~ProcessObject ()
 
virtual void DebugOn ()
 
virtual void DebugOff ()
 
virtual bool GetDebug () const
 
virtual void SetDebug (bool debugFlag)
 
virtual void SetNumberOfThreads (unsigned int n)
 
virtual unsigned int GetNumberOfThreads () const
 
virtual void SetNumberOfWorkUnits (unsigned int n)
 
virtual unsigned int GetNumberOfWorkUnits () const
 

Private Types

using MemberFunctionType = void (Self::*)(const Image &image1)
 

Private Member Functions

template<class TImageType>
void ExecuteInternal (const Image &image1)
 

Static Private Member Functions

static const detail::MemberFunctionFactory< MemberFunctionType > & GetMemberFunctionFactory ()
 

Private Attributes

double m_ContourValue { 0.0 }
 
std::unique_ptr< itk::ProcessObject, ProcessObjectDeleterm_Filter {nullptr}
 
bool m_LabelContours { false }
 
unsigned int m_NumberOfCountours { 0 }
 
std::function< std::vector< double >(unsigned int)> m_pfGetContour
 
bool m_ReverseContourOrientation { false }
 
bool m_VertexConnectHighPixels { false }
 

Friends

struct detail::MemberFunctionAddressor< MemberFunctionType >
 

Additional Inherited Members

- Static Public Member Functions inherited from itk::simple::ProcessObject
static bool GetGlobalDefaultDebug ()
 
static void GlobalDefaultDebugOff ()
 
static void GlobalDefaultDebugOn ()
 
static void SetGlobalDefaultDebug (bool debugFlag)
 
static void GlobalWarningDisplayOn ()
 
static void GlobalWarningDisplayOff ()
 
static void SetGlobalWarningDisplay (bool flag)
 
static bool GetGlobalWarningDisplay ()
 
static double GetGlobalDefaultCoordinateTolerance ()
 Access the global tolerance to determine congruent spaces.
 
static void SetGlobalDefaultCoordinateTolerance (double)
 Access the global tolerance to determine congruent spaces.
 
static double GetGlobalDefaultDirectionTolerance ()
 Access the global tolerance to determine congruent spaces.
 
static void SetGlobalDefaultDirectionTolerance (double)
 Access the global tolerance to determine congruent spaces.
 
static bool SetGlobalDefaultThreader (const std::string &threader)
 Set/Get the default threader used for process objects.
 
static std::string GetGlobalDefaultThreader ()
 Set/Get the default threader used for process objects.
 
static void SetGlobalDefaultNumberOfThreads (unsigned int n)
 
static unsigned int GetGlobalDefaultNumberOfThreads ()
 Set/Get the default threader used for process objects.
 
- Protected Member Functions inherited from itk::simple::ImageFilter
void CheckImageMatchingDimension (const Image &image1, const Image &image2, const std::string &image2Name)
 
void CheckImageMatchingPixelType (const Image &image1, const Image &image2, const std::string &image2Name)
 
void CheckImageMatchingSize (const Image &image1, const Image &image2, const std::string &image2Name)
 
- Protected Member Functions inherited from itk::simple::ProcessObject
virtual unsigned long AddITKObserver (const itk::EventObject &, itk::Command *)
 
virtual itk::ProcessObjectGetActiveProcess ()
 
virtual void OnActiveProcessDelete ()
 
virtual void onCommandDelete (const itk::simple::Command *cmd) noexcept
 
virtual void PreUpdate (itk::ProcessObject *p)
 
virtual void RemoveITKObserver (EventCommand &e)
 
- Protected Member Functions inherited from itk::simple::NonCopyable
 NonCopyable ()=default
 
 NonCopyable (const NonCopyable &)=delete
 
NonCopyableoperator= (const NonCopyable &)=delete
 
- Static Protected Member Functions inherited from itk::simple::ImageFilter
template<class TImageType>
static void FixNonZeroIndex (TImageType *img)
 
- Static Protected Member Functions inherited from itk::simple::ProcessObject
template<class TImageType>
static TImageType::ConstPointer CastImageToITK (const Image &img)
 
template<class TPixelType, unsigned int VImageDimension, unsigned int VLength, template< typename, unsigned int > class TVector>
static Image CastITKToImage (itk::Image< TVector< TPixelType, VLength >, VImageDimension > *img)
 
template<unsigned int VImageDimension, unsigned int VLength, template< unsigned int > class TVector>
static Image CastITKToImage (itk::Image< TVector< VLength >, VImageDimension > *img)
 
template<class TImageType>
static Image CastITKToImage (TImageType *img)
 
static const itk::EventObjectGetITKEventObject (EventEnum e)
 
template<typename T>
static std::ostream & ToStringHelper (std::ostream &os, const T &v)
 
static std::ostream & ToStringHelper (std::ostream &os, const char &v)
 
static std::ostream & ToStringHelper (std::ostream &os, const signed char &v)
 
static std::ostream & ToStringHelper (std::ostream &os, const unsigned char &v)
 

Member Typedef Documentation

◆ MemberFunctionType

using itk::simple::ContourExtractor2DImageFilter::MemberFunctionType = void (Self::*)(const Image &image1)
private

Setup for member function dispatching

Definition at line 201 of file sitkContourExtractor2DImageFilter.h.

◆ PixelIDTypeList

Define the pixels types supported by this filter

Definition at line 92 of file sitkContourExtractor2DImageFilter.h.

◆ Self

Constructor & Destructor Documentation

◆ ~ContourExtractor2DImageFilter()

virtual itk::simple::ContourExtractor2DImageFilter::~ContourExtractor2DImageFilter ( )
virtual

Destructor

◆ ContourExtractor2DImageFilter()

itk::simple::ContourExtractor2DImageFilter::ContourExtractor2DImageFilter ( )

Default Constructor that takes no arguments and initializes default parameters

Member Function Documentation

◆ Execute()

void itk::simple::ContourExtractor2DImageFilter::Execute ( const Image & image1)

Execute the filter on the input image

◆ ExecuteInternal()

template<class TImageType>
void itk::simple::ContourExtractor2DImageFilter::ExecuteInternal ( const Image & image1)
private

◆ GetContour()

std::vector< double > itk::simple::ContourExtractor2DImageFilter::GetContour ( unsigned int n) const
inline

Get the coordinates of the n-th contour path as a flat vector of doubles in the format (x1, y1, x2, y2, ...). The index n should be less than the number of outputs returned by GetNumberOfOutputs().

This is an active measurement. It may be accessed while the filter is being executing in command call-backs and can be accessed after execution.

Definition at line 186 of file sitkContourExtractor2DImageFilter.h.

References m_pfGetContour.

◆ GetContourValue()

double itk::simple::ContourExtractor2DImageFilter::GetContourValue ( ) const
inline

Set/Get the image intensity value that the contours should follow. This is the equivalent of an iso-value in Marching Squares.

Definition at line 109 of file sitkContourExtractor2DImageFilter.h.

References m_ContourValue.

◆ GetLabelContours()

bool itk::simple::ContourExtractor2DImageFilter::GetLabelContours ( ) const
inline

Return contours for all distinct labels

Definition at line 168 of file sitkContourExtractor2DImageFilter.h.

References m_LabelContours.

◆ GetMemberFunctionFactory()

static const detail::MemberFunctionFactory< MemberFunctionType > & itk::simple::ContourExtractor2DImageFilter::GetMemberFunctionFactory ( )
staticprivate

◆ GetName()

std::string itk::simple::ContourExtractor2DImageFilter::GetName ( ) const
inlinevirtual

Name of this class

Implements itk::simple::ProcessObject.

Definition at line 189 of file sitkContourExtractor2DImageFilter.h.

◆ GetNumberOfCountours()

unsigned int itk::simple::ContourExtractor2DImageFilter::GetNumberOfCountours ( ) const
inline

Get the number of contour paths generated. Multiple contours may be produced because an image can have multiple contours at a given level.

This is a measurement. Its value is updated in the Execute methods, so the value will only be valid after an execution.

Definition at line 177 of file sitkContourExtractor2DImageFilter.h.

References m_NumberOfCountours.

◆ GetReverseContourOrientation()

bool itk::simple::ContourExtractor2DImageFilter::GetReverseContourOrientation ( ) const
inline

Control the orientation of the contours with reference to the image gradient. (See class documentation.)

Definition at line 128 of file sitkContourExtractor2DImageFilter.h.

References m_ReverseContourOrientation.

◆ GetVertexConnectHighPixels()

bool itk::simple::ContourExtractor2DImageFilter::GetVertexConnectHighPixels ( ) const
inline

Control whether high- or low-valued pixels are vertex-connected. Default is for low-valued pixels to be vertex- connected. (See class documentation.)

Definition at line 149 of file sitkContourExtractor2DImageFilter.h.

References m_VertexConnectHighPixels.

◆ LabelContoursOff()

void itk::simple::ContourExtractor2DImageFilter::LabelContoursOff ( )
inline

Definition at line 163 of file sitkContourExtractor2DImageFilter.h.

References SetLabelContours().

◆ LabelContoursOn()

void itk::simple::ContourExtractor2DImageFilter::LabelContoursOn ( )
inline

Set the value of LabelContours to true or false respectfully.

Definition at line 161 of file sitkContourExtractor2DImageFilter.h.

References SetLabelContours().

◆ ReverseContourOrientationOff()

void itk::simple::ContourExtractor2DImageFilter::ReverseContourOrientationOff ( )
inline

◆ ReverseContourOrientationOn()

void itk::simple::ContourExtractor2DImageFilter::ReverseContourOrientationOn ( )
inline

Set the value of ReverseContourOrientation to true or false respectfully.

Definition at line 121 of file sitkContourExtractor2DImageFilter.h.

References SetReverseContourOrientation().

◆ SetContourValue()

void itk::simple::ContourExtractor2DImageFilter::SetContourValue ( double ContourValue)
inline

Set/Get the image intensity value that the contours should follow. This is the equivalent of an iso-value in Marching Squares.

Definition at line 102 of file sitkContourExtractor2DImageFilter.h.

References m_ContourValue.

◆ SetLabelContours()

void itk::simple::ContourExtractor2DImageFilter::SetLabelContours ( bool LabelContours)
inline

Return contours for all distinct labels

Definition at line 156 of file sitkContourExtractor2DImageFilter.h.

References m_LabelContours.

Referenced by LabelContoursOff(), and LabelContoursOn().

◆ SetReverseContourOrientation()

void itk::simple::ContourExtractor2DImageFilter::SetReverseContourOrientation ( bool ReverseContourOrientation)
inline

Control the orientation of the contours with reference to the image gradient. (See class documentation.)

Definition at line 116 of file sitkContourExtractor2DImageFilter.h.

References m_ReverseContourOrientation.

Referenced by ReverseContourOrientationOff(), and ReverseContourOrientationOn().

◆ SetVertexConnectHighPixels()

void itk::simple::ContourExtractor2DImageFilter::SetVertexConnectHighPixels ( bool VertexConnectHighPixels)
inline

Control whether high- or low-valued pixels are vertex-connected. Default is for low-valued pixels to be vertex- connected. (See class documentation.)

Definition at line 136 of file sitkContourExtractor2DImageFilter.h.

References m_VertexConnectHighPixels.

Referenced by VertexConnectHighPixelsOff(), and VertexConnectHighPixelsOn().

◆ ToString()

std::string itk::simple::ContourExtractor2DImageFilter::ToString ( ) const
virtual

Print ourselves out

Reimplemented from itk::simple::ProcessObject.

◆ VertexConnectHighPixelsOff()

void itk::simple::ContourExtractor2DImageFilter::VertexConnectHighPixelsOff ( )
inline

Definition at line 143 of file sitkContourExtractor2DImageFilter.h.

References SetVertexConnectHighPixels().

◆ VertexConnectHighPixelsOn()

void itk::simple::ContourExtractor2DImageFilter::VertexConnectHighPixelsOn ( )
inline

Set the value of VertexConnectHighPixels to true or false respectfully.

Definition at line 141 of file sitkContourExtractor2DImageFilter.h.

References SetVertexConnectHighPixels().

Friends And Related Symbol Documentation

◆ detail::MemberFunctionAddressor< MemberFunctionType >

Definition at line 202 of file sitkContourExtractor2DImageFilter.h.

References ExecuteInternal().

Member Data Documentation

◆ m_ContourValue

double itk::simple::ContourExtractor2DImageFilter::m_ContourValue { 0.0 }
private

Definition at line 207 of file sitkContourExtractor2DImageFilter.h.

Referenced by GetContourValue(), and SetContourValue().

◆ m_Filter

std::unique_ptr<itk::ProcessObject, ProcessObjectDeleter> itk::simple::ContourExtractor2DImageFilter::m_Filter {nullptr}
private

Definition at line 222 of file sitkContourExtractor2DImageFilter.h.

◆ m_LabelContours

bool itk::simple::ContourExtractor2DImageFilter::m_LabelContours { false }
private

Definition at line 213 of file sitkContourExtractor2DImageFilter.h.

Referenced by GetLabelContours(), and SetLabelContours().

◆ m_NumberOfCountours

unsigned int itk::simple::ContourExtractor2DImageFilter::m_NumberOfCountours { 0 }
private

Definition at line 217 of file sitkContourExtractor2DImageFilter.h.

Referenced by GetNumberOfCountours().

◆ m_pfGetContour

std::function<std::vector<double>(unsigned int)> itk::simple::ContourExtractor2DImageFilter::m_pfGetContour
private

Definition at line 218 of file sitkContourExtractor2DImageFilter.h.

Referenced by GetContour().

◆ m_ReverseContourOrientation

bool itk::simple::ContourExtractor2DImageFilter::m_ReverseContourOrientation { false }
private

◆ m_VertexConnectHighPixels

bool itk::simple::ContourExtractor2DImageFilter::m_VertexConnectHighPixels { false }
private

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