SimpleITK  
itk::simple::SLICImageFilter Class Reference

Simple Linear Iterative Clustering (SLIC) super-pixel segmentation. More...

#include <sitkSLICImageFilter.h>

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

Detailed Description

Simple Linear Iterative Clustering (SLIC) super-pixel segmentation.

The Simple Linear Iterative Clustering (SLIC) algorithm groups pixels into a set of labeled regions or super-pixels. Super-pixels follow natural image boundaries, are compact, and are nearly uniform regions which can be used as a larger primitive for more efficient computation. The SLIC algorithm can be viewed as a spatially constrained iterative k-means method.

The original algorithm was designed to cluster on the joint domain of the images index space and its CIELAB color space. This implementation works with images of arbitrary dimension as well as scalar, single channel, images and most multi-component image types including ITK's arbitrary length VectorImage .

The distance between a pixel and a cluster is the sum of squares of the difference between their joint range and domains ( index and value ). The computation is done in index space with scales provided by the SpatialProximityWeight parameters.

The output is a label image with each label representing a superpixel cluster. Every pixel in the output is labeled, and the starting label id is zero.

This code was contributed in the Insight Journal paper: "Scalable Simple Linear Iterative Clustering (SSLIC) Using a Generic and Parallel Approach" by Lowekamp B. C., Chen D. T., Yaniv Z., Yoo T. S. https://doi.org/10.54294/8hic7f

See also
itk::simple::SLIC for the procedural interface
itk::SLICImageFilter for the Doxygen on the original ITK class.

Definition at line 60 of file sitkSLICImageFilter.h.

Public Types

using PixelIDTypeList = typelist2::append<BasicPixelIDTypeList, VectorPixelIDTypeList>::type
 
using Self = SLICImageFilter
 
- Public Types inherited from itk::simple::ImageFilter
using Self = ImageFilter
 
- Public Types inherited from itk::simple::ProcessObject
using Self = ProcessObject
 

Public Member Functions

void EnforceConnectivityOff ()
 
void EnforceConnectivityOn ()
 
Image Execute (const Image &image1)
 
double GetAverageResidual () const
 Get the current average cluster residual. After each iteration the residual is computed as the distance between the current clusters and the previous. This is averaged so that the value is independent of the number of clusters.
 
bool GetEnforceConnectivity () const
 
bool GetInitializationPerturbation () const
 
uint32_t GetMaximumNumberOfIterations () const
 
std::string GetName () const
 
double GetSpatialProximityWeight () const
 
std::vector< unsigned int > GetSuperGridSize () const
 
void InitializationPerturbationOff ()
 
void InitializationPerturbationOn ()
 
void SetEnforceConnectivity (bool EnforceConnectivity)
 Post processing step to enforce superpixel morphology. Enable an additional computation which ensures all label pixels of the same value are spatially connected. Disconnected labeled components are assigned a new value if of sufficient size, or are relabeled to the previously encountered value if small.
 
void SetInitializationPerturbation (bool InitializationPerturbation)
 Enable perturbation of initial cluster center location. After grid based initialization, this option enables moving the initial cluster center location to the minimum gradient in a small neighborhood. If the grid size is less than three this is automatically disabled.
 
void SetMaximumNumberOfIterations (uint32_t MaximumNumberOfIterations)
 Number of iterations to run. Specify the number of iterations to run when optimizing the clusters.
 
void SetSpatialProximityWeight (double SpatialProximityWeight)
 The spatial weight for the distance function. Increasing this value makes the superpixel shape more regular, but more varied in image values. The range of the pixel values and image dimension can effect the appropriate value.
 
void SetSuperGridSize (std::vector< unsigned int > SuperGridSize)
 
 SLICImageFilter ()
 
std::string ToString () const
 
virtual ~SLICImageFilter ()
 
- 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 = Image (Self::*)(const Image &image1)
 

Private Member Functions

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

Static Private Member Functions

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

Private Attributes

bool m_EnforceConnectivity { true }
 
std::unique_ptr< itk::ProcessObject, ProcessObjectDeleterm_Filter {nullptr}
 
bool m_InitializationPerturbation { true }
 
uint32_t m_MaximumNumberOfIterations { 5u }
 
std::function< double()> m_pfGetAverageResidual
 
double m_SpatialProximityWeight { 10.0 }
 
std::vector< unsigned int > m_SuperGridSize { std::vector<unsigned int>(3, 50) }
 

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::SLICImageFilter::MemberFunctionType = Image (Self::*)(const Image &image1)
private

Setup for member function dispatching

Definition at line 178 of file sitkSLICImageFilter.h.

◆ PixelIDTypeList

Define the pixels types supported by this filter

Definition at line 72 of file sitkSLICImageFilter.h.

◆ Self

Constructor & Destructor Documentation

◆ ~SLICImageFilter()

virtual itk::simple::SLICImageFilter::~SLICImageFilter ( )
virtual

Destructor

◆ SLICImageFilter()

itk::simple::SLICImageFilter::SLICImageFilter ( )

Default Constructor that takes no arguments and initializes default parameters

Member Function Documentation

◆ EnforceConnectivityOff()

void itk::simple::SLICImageFilter::EnforceConnectivityOff ( )
inline

Definition at line 129 of file sitkSLICImageFilter.h.

References SetEnforceConnectivity().

◆ EnforceConnectivityOn()

void itk::simple::SLICImageFilter::EnforceConnectivityOn ( )
inline

Set the value of EnforceConnectivity to true or false respectfully.

Definition at line 127 of file sitkSLICImageFilter.h.

References SetEnforceConnectivity().

◆ Execute()

Image itk::simple::SLICImageFilter::Execute ( const Image & image1)

Execute the filter on the input image

◆ ExecuteInternal()

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

◆ GetAverageResidual()

double itk::simple::SLICImageFilter::GetAverageResidual ( ) const
inline

Get the current average cluster residual. After each iteration the residual is computed as the distance between the current clusters and the previous. This is averaged so that the value is independent of the number of clusters.

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 163 of file sitkSLICImageFilter.h.

References m_pfGetAverageResidual.

◆ GetEnforceConnectivity()

bool itk::simple::SLICImageFilter::GetEnforceConnectivity ( ) const
inline

Definition at line 133 of file sitkSLICImageFilter.h.

References m_EnforceConnectivity.

◆ GetInitializationPerturbation()

bool itk::simple::SLICImageFilter::GetInitializationPerturbation ( ) const
inline

Definition at line 153 of file sitkSLICImageFilter.h.

References m_InitializationPerturbation.

◆ GetMaximumNumberOfIterations()

uint32_t itk::simple::SLICImageFilter::GetMaximumNumberOfIterations ( ) const
inline

Definition at line 112 of file sitkSLICImageFilter.h.

References m_MaximumNumberOfIterations.

◆ GetMemberFunctionFactory()

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

◆ GetName()

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

Name of this class

Implements itk::simple::ProcessObject.

Definition at line 166 of file sitkSLICImageFilter.h.

◆ GetSpatialProximityWeight()

double itk::simple::SLICImageFilter::GetSpatialProximityWeight ( ) const
inline

Definition at line 99 of file sitkSLICImageFilter.h.

References m_SpatialProximityWeight.

◆ GetSuperGridSize()

std::vector< unsigned int > itk::simple::SLICImageFilter::GetSuperGridSize ( ) const
inline

Definition at line 85 of file sitkSLICImageFilter.h.

References m_SuperGridSize.

◆ InitializationPerturbationOff()

void itk::simple::SLICImageFilter::InitializationPerturbationOff ( )
inline

Definition at line 149 of file sitkSLICImageFilter.h.

References SetInitializationPerturbation().

◆ InitializationPerturbationOn()

void itk::simple::SLICImageFilter::InitializationPerturbationOn ( )
inline

Set the value of InitializationPerturbation to true or false respectfully.

Definition at line 147 of file sitkSLICImageFilter.h.

References SetInitializationPerturbation().

◆ SetEnforceConnectivity()

void itk::simple::SLICImageFilter::SetEnforceConnectivity ( bool EnforceConnectivity)
inline

Post processing step to enforce superpixel morphology. Enable an additional computation which ensures all label pixels of the same value are spatially connected. Disconnected labeled components are assigned a new value if of sufficient size, or are relabeled to the previously encountered value if small.

Definition at line 122 of file sitkSLICImageFilter.h.

References m_EnforceConnectivity.

Referenced by EnforceConnectivityOff(), and EnforceConnectivityOn().

◆ SetInitializationPerturbation()

void itk::simple::SLICImageFilter::SetInitializationPerturbation ( bool InitializationPerturbation)
inline

Enable perturbation of initial cluster center location. After grid based initialization, this option enables moving the initial cluster center location to the minimum gradient in a small neighborhood. If the grid size is less than three this is automatically disabled.

Definition at line 142 of file sitkSLICImageFilter.h.

References m_InitializationPerturbation.

Referenced by InitializationPerturbationOff(), and InitializationPerturbationOn().

◆ SetMaximumNumberOfIterations()

void itk::simple::SLICImageFilter::SetMaximumNumberOfIterations ( uint32_t MaximumNumberOfIterations)
inline

Number of iterations to run. Specify the number of iterations to run when optimizing the clusters.

Definition at line 107 of file sitkSLICImageFilter.h.

References m_MaximumNumberOfIterations.

◆ SetSpatialProximityWeight()

void itk::simple::SLICImageFilter::SetSpatialProximityWeight ( double SpatialProximityWeight)
inline

The spatial weight for the distance function. Increasing this value makes the superpixel shape more regular, but more varied in image values. The range of the pixel values and image dimension can effect the appropriate value.

Definition at line 94 of file sitkSLICImageFilter.h.

References m_SpatialProximityWeight.

◆ SetSuperGridSize()

void itk::simple::SLICImageFilter::SetSuperGridSize ( std::vector< unsigned int > SuperGridSize)
inline

Definition at line 80 of file sitkSLICImageFilter.h.

References m_SuperGridSize.

◆ ToString()

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

Print ourselves out

Reimplemented from itk::simple::ProcessObject.

Friends And Related Symbol Documentation

◆ detail::MemberFunctionAddressor< MemberFunctionType >

Definition at line 179 of file sitkSLICImageFilter.h.

References ExecuteInternal().

Member Data Documentation

◆ m_EnforceConnectivity

bool itk::simple::SLICImageFilter::m_EnforceConnectivity { true }
private

Definition at line 191 of file sitkSLICImageFilter.h.

Referenced by GetEnforceConnectivity(), and SetEnforceConnectivity().

◆ m_Filter

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

Definition at line 201 of file sitkSLICImageFilter.h.

◆ m_InitializationPerturbation

bool itk::simple::SLICImageFilter::m_InitializationPerturbation { true }
private

◆ m_MaximumNumberOfIterations

uint32_t itk::simple::SLICImageFilter::m_MaximumNumberOfIterations { 5u }
private

◆ m_pfGetAverageResidual

std::function<double()> itk::simple::SLICImageFilter::m_pfGetAverageResidual
private

Definition at line 197 of file sitkSLICImageFilter.h.

Referenced by GetAverageResidual().

◆ m_SpatialProximityWeight

double itk::simple::SLICImageFilter::m_SpatialProximityWeight { 10.0 }
private

Definition at line 186 of file sitkSLICImageFilter.h.

Referenced by GetSpatialProximityWeight(), and SetSpatialProximityWeight().

◆ m_SuperGridSize

std::vector<unsigned int> itk::simple::SLICImageFilter::m_SuperGridSize { std::vector<unsigned int>(3, 50) }
private

Definition at line 184 of file sitkSLICImageFilter.h.

Referenced by GetSuperGridSize(), and SetSuperGridSize().


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