w2kmeans::KMeansSegmenter< T > Class Template Reference

Inheritance diagram for w2kmeans::KMeansSegmenter< T >:

w2kmeans::MultiscaleSegmenter w2img::Segmenter List of all members.

Detailed Description

template<class T>
class w2kmeans::KMeansSegmenter< T >

A hierarchical K-means segmentation algorithm that aggregates regions at different scales based purely on size.

Author:
Lakshman
Version:
Id
w2kmeans_KMeansSegmenter.h,v 1.30 2010/07/07 15:34:52 lakshman Exp


Public Types

typedef Cluster< SingleFeature > RegionProperty
 The simplest region property is a cluster of a single feature.
typedef std::vector< int > Replacement
 Given a region with label i, Replacement[i] provides the new label, usually at a particular scale.

Public Member Functions

virtual w2img::SegmenterResult segment (const code::Image< int > &orig)
 The resulting image has pixels marked with the region number, starting at 1.
virtual ~KMeansSegmenter ()
 KMeansSegmenter (int min_val, int max_val, size_t number_of_clusters, int max_depth)
 Pass in the range of values to consider in thresholding.
w2img::SegmenterResult getScale (size_t scale, bool rawlabels=false) const
 The different scales.
const ReplacementgetReplacement (size_t scale) const
 Gets the replacement at different scales.
size_t getNumScales () const
 Returns the total number of scales in the segmentation.

Static Public Member Functions

static void setMarkovWeight (float lambda)
 Set the weight of the Markov energy relative to the Discontiguity measure.
static void setMinimumRegionSizes (const std::string &minimum_allowed)
 Set the size thresholds for the scales.
static void keepAllSizes (bool flag)
 By default, isolated, small regions will be removed at successive scales.
static void setSizeParams (const std::string &params)
 Convenient way to set the sizes and allSizes option through a single string.
static size_t getMaxScales ()
 Returns the maximum number of scales in the segmentation.
static void computeRegionProperty (const code::Image< int > &orig, const SegmenterResult &label, std::vector< RegionProperty > *fillme)
 Fills in the passed in vector with a vector of computed region properties.
static void computeRegionProperty (const SegmenterResult &label, std::vector< RegionProperty > *fillme)
 Fills in the passed in vector with a vector of computed region properties.
static void normalize (Segmenter::Replacement &replacement)
 completes the cycle
static SegmenterResult relabel (const SegmenterResult &label_img)
 Will relabel the image, removing unused labels.

Protected Member Functions

void doCurvatureCheck (w2img::SegmenterResult &label) const
 If there is a highly curved or elongated large object, split it into smaller objects.
code::Image< int > doKMeans (const w2img::ImageAttr< T > &attr, code::Image< int > *init_clusters, std::vector< w2img::Cluster< T > > *clusters, int iter_no=0) const
 Perform K means segmentation, returns a better set of clusters.
code::Image< int > initialize (const code::Image< int > &orig, const w2img::ImageAttr< T > &attr, std::vector< w2img::Cluster< T > > *clusters) const
 Get an initial cut of clusters, somehow.
void computeClusterAttr (const w2img::ImageAttr< T > &attr, const code::Image< int > &clusterid, std::vector< w2img::Cluster< T > > *clusters, int max_clusterid) const
 Compute cluster attributes from the image attribute and labeling.
int findBestCluster (const T &current, const std::vector< w2img::Cluster< T > > &clusters, const code::Image< int > &clusterid, int x, int y) const
 Return label corresponding to best cluster available.
float computeMeasureDistance (const w2img::Cluster< T > &cluster, const T &current, int x, int y) const
 Way to compute distance between a point (value,x,y) and a cluster's mean.
float computeMeasureDistance (const T &other, const T &current) const
 Finds distance between two statistics.
float computeDiscontiguityDistance (const code::Image< int > &label, int x, int y, int candidate_label) const
 Way to compute discontiguity if the current label were to be changed to the candidate.
virtual void computeReplacements (Pruner &pruner)
 This function may be over-ridden to provide a different way of choosing how to combine/replace regions at higher levels.
void expand_segment (int x, int y, const code::Image< int > &orig, code::Image< int > &segimg, int label) const
 Set the segimg at x,y to be label and then call this function.

Static Protected Attributes

static const int Unset = -1000
static const int Invalid = -2000

Classes

class  Pruner
 Controls pruning of regions based on size. More...
struct  SurrRegion
 Used by the pruner to control pruning of regions based on size. More...


Member Typedef Documentation

typedef Cluster< SingleFeature > w2img::Segmenter::RegionProperty [inherited]

The simplest region property is a cluster of a single feature.

typedef std::vector<int> w2img::Segmenter::Replacement [inherited]

Given a region with label i, Replacement[i] provides the new label, usually at a particular scale.

The Replacement structure is such that replacement[i] provides the replacement label for the current label i. This replacement may be 0 or negative, which means that no replacement exists.


Constructor & Destructor Documentation

template<class T>
virtual w2kmeans::KMeansSegmenter< T >::~KMeansSegmenter (  )  [inline, virtual]

template<class T>
w2kmeans::KMeansSegmenter< T >::KMeansSegmenter ( int  min_val,
int  max_val,
size_t  number_of_clusters,
int  max_depth 
)

Pass in the range of values to consider in thresholding.

Specify the number of initial quantization levels and the maximum depth (in quantization levels) that a cluster can range over without being too dissimilar. Specify a -ve value for max_depth if you don't want dissimilarity to affect cluster combination.


Member Function Documentation

template<class T>
void w2kmeans::KMeansSegmenter< T >::computeClusterAttr ( const w2img::ImageAttr< T > &  attr,
const code::Image< int > &  clusterid,
std::vector< w2img::Cluster< T > > *  clusters,
int  max_clusterid 
) const [protected]

Compute cluster attributes from the image attribute and labeling.

During K-means, the computation is always done with K levels, but pass in false if you are using this after K-means and relabeling.

template<class T>
float w2kmeans::KMeansSegmenter< T >::computeDiscontiguityDistance ( const code::Image< int > &  label,
int  x,
int  y,
int  candidate_label 
) const [protected]

Way to compute discontiguity if the current label were to be changed to the candidate.

Returns a number between 0 and 1.

template<class T>
float w2kmeans::KMeansSegmenter< T >::computeMeasureDistance ( const T &  other,
const T &  current 
) const [protected]

Finds distance between two statistics.

template<class T>
float w2kmeans::KMeansSegmenter< T >::computeMeasureDistance ( const w2img::Cluster< T > &  cluster,
const T &  current,
int  x,
int  y 
) const [protected]

Way to compute distance between a point (value,x,y) and a cluster's mean.

The base class does not use the location information, but derived classes may want to. Between 0 and 1.

static void w2img::Segmenter::computeRegionProperty ( const SegmenterResult label,
std::vector< RegionProperty > *  fillme 
) [static, inherited]

Fills in the passed in vector with a vector of computed region properties.

The input label image should be a labeled image such as that returned by the segmenter. WARNING: The resulting properties will not have any of the value elements set because the original image was not passed in.

static void w2img::Segmenter::computeRegionProperty ( const code::Image< int > &  orig,
const SegmenterResult label,
std::vector< RegionProperty > *  fillme 
) [static, inherited]

Fills in the passed in vector with a vector of computed region properties.

The input label image should be a labeled image such as that returned by the segmenter.

template<class T>
virtual void w2kmeans::KMeansSegmenter< T >::computeReplacements ( Pruner pruner  )  [protected, virtual]

This function may be over-ridden to provide a different way of choosing how to combine/replace regions at higher levels.

Parameters:
label The image with the K-means segmentation done and labels computed based on 8-neighborhood, but no selection among the regions performed.
pruner to be used.
replacements_list The list of replacements; the first element (most detail) should be filled already. Coarser detail will be filled in here.

template<class T>
void w2kmeans::KMeansSegmenter< T >::doCurvatureCheck ( w2img::SegmenterResult label  )  const [protected]

If there is a highly curved or elongated large object, split it into smaller objects.

changes the labels in the image passed in.

template<class T>
code::Image<int> w2kmeans::KMeansSegmenter< T >::doKMeans ( const w2img::ImageAttr< T > &  attr,
code::Image< int > *  init_clusters,
std::vector< w2img::Cluster< T > > *  clusters,
int  iter_no = 0 
) const [protected]

Perform K means segmentation, returns a better set of clusters.

These can be segmented using the ContourSegmenter to yield a w2img::SegmenterResult.

void w2img::Segmenter::expand_segment ( int  x,
int  y,
const code::Image< int > &  orig,
code::Image< int > &  segimg,
int  label 
) const [protected, inherited]

Set the segimg at x,y to be label and then call this function.

It will expand out segimg to all contiguous values that match

template<class T>
int w2kmeans::KMeansSegmenter< T >::findBestCluster ( const T &  current,
const std::vector< w2img::Cluster< T > > &  clusters,
const code::Image< int > &  clusterid,
int  x,
int  y 
) const [protected]

Return label corresponding to best cluster available.

template<class T>
static size_t w2kmeans::KMeansSegmenter< T >::getMaxScales (  )  [static]

Returns the maximum number of scales in the segmentation.

See also:
getNumScales()

template<class T>
size_t w2kmeans::KMeansSegmenter< T >::getNumScales (  )  const [virtual]

Returns the total number of scales in the segmentation.

The returned values correspond to the previous call to segment()

See also:
getMaxScales()

Implements w2kmeans::MultiscaleSegmenter.

template<class T>
const Replacement& w2kmeans::KMeansSegmenter< T >::getReplacement ( size_t  scale  )  const

Gets the replacement at different scales.

0 is the most detail, 1 is less and so on. If the scale passed in exceeeds the number of scales in the segmentation, an invalid Replacement ( .size() == 0 ) is returned.

The returned values correspond to the previous call to segment()

template<class T>
w2img::SegmenterResult w2kmeans::KMeansSegmenter< T >::getScale ( size_t  scale,
bool  rawlabels = false 
) const [virtual]

The different scales.

The returned values correspond to the previous call to segment()

Parameters:
scale The scale to return. 0 is the most detail, 1 is less ...
rawlabels If true, then no relabeling of the original image is done. If false, the labeling corresponds to that of raw_segimg.
Returns:
image at scale. If the scale passed in exceeeds the number of scales in the segmentation, an invalid image (dim_x()*dim_y() <= 0) is returned.
The returned values correspond to the previous call to segment()

Implements w2kmeans::MultiscaleSegmenter.

template<class T>
code::Image<int> w2kmeans::KMeansSegmenter< T >::initialize ( const code::Image< int > &  orig,
const w2img::ImageAttr< T > &  attr,
std::vector< w2img::Cluster< T > > *  clusters 
) const [protected]

Get an initial cut of clusters, somehow.

The implementation here is to divide the measurement space (max-min) into equal parts.

template<class T>
static void w2kmeans::KMeansSegmenter< T >::keepAllSizes ( bool  flag  )  [static]

By default, isolated, small regions will be removed at successive scales.

Set this flag to 'true' if you want larger scales to contain the isolated regions from smaller scales.

static void w2img::Segmenter::normalize ( Segmenter::Replacement replacement  )  [static, inherited]

completes the cycle

static SegmenterResult w2img::Segmenter::relabel ( const SegmenterResult label_img  )  [static, inherited]

Will relabel the image, removing unused labels.

template<class T>
virtual w2img::SegmenterResult w2kmeans::KMeansSegmenter< T >::segment ( const code::Image< int > &  orig  )  [virtual]

The resulting image has pixels marked with the region number, starting at 1.

Zero values do not belong to any region.

What gets returned is the segmentation with the most detail. To obtain the segmentation at coarser levels of detail, use the getScale() function.

This is not really a constant function -- getScale() and getReplacement()'s results will change because of this function.

Implements w2kmeans::MultiscaleSegmenter.

template<class T>
static void w2kmeans::KMeansSegmenter< T >::setMarkovWeight ( float  lambda  )  [static]

Set the weight of the Markov energy relative to the Discontiguity measure.

The default value is 0.6 and should be left alone unless you know what you are doing. If wish to change it, provide any number in the range [0,1].

This is more that "just" a static function -- you are setting it for all values of the template parameter T as well!

template<class T>
static void w2kmeans::KMeansSegmenter< T >::setMinimumRegionSizes ( const std::string &  minimum_allowed  )  [static]

Set the size thresholds for the scales.

By default, this string is 20,160,480

This is more that "just" a static function -- you are setting it for all values of the template parameter T as well!

template<class T>
static void w2kmeans::KMeansSegmenter< T >::setSizeParams ( const std::string &  params  )  [static]

Convenient way to set the sizes and allSizes option through a single string.

The default values are 20,160,480:0


Member Data Documentation

const int w2img::Segmenter::Invalid = -2000 [static, protected, inherited]

const int w2img::Segmenter::Unset = -1000 [static, protected, inherited]


Generated on Fri May 4 13:40:24 2012 for WDSS-IIw2algs by  doxygen 1.4.7