Inheritance diagram for kmeans::MergingKMSegmenter< T >:
Unlike the KMeansSegmenter which relies on progressive pruning of regions based on size to implement multiscale segmentation, the MergingKMSegmenter uses inter-cluster distances and progressively raises the threshold below which regions should be merged.
Public Types | |
typedef KMeansSegmenter< T >::Replacement | Replacement |
Given a region with label i, Replacement[i] provides the new label, usually at a particular scale. | |
typedef Cluster< SingleFeature > | RegionProperty |
The simplest region property is a cluster of a single feature. | |
Public Member Functions | |
MergingKMSegmenter (int min_val=0, int max_val=100, size_t number_of_clusters=16) | |
virtual | ~MergingKMSegmenter () |
virtual LImage< int > | segment (const LImage< int > &orig) |
void | setOutputImageDir (const std::string &newDir) |
Pass in an empty string to turn off output. | |
void | writeGraph (const std::string &filename) const |
Write out a DOT output file (in a form that the Graphviz utility dot can read). | |
LImage< int > | getScale (size_t scale, bool rawlabels=false) const |
The different scales. | |
const Replacement & | getReplacement (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 | computeRegionProperty (const LImage< int > &orig, const LImage< int > &label, vector< RegionProperty > *fillme) |
Fills in the passed in vector with a vector of computed region properties. | |
static void | computeRegionProperty (const LImage< int > &label, vector< RegionProperty > *fillme) |
Fills in the passed in vector with a vector of computed region properties. | |
Protected Member Functions | |
virtual void | computeReplacements (const LImage< int > &label, const ImageAttr< T > &attr, std::vector< Replacement > *replacements_list) |
Uses inter-cluster distance to decide the replacement of region labels at different scales. | |
LImage< int > | doKMeans (const ImageAttr< T > &attr, LImage< int > *label, vector< Cluster< T > > *clusters, int iter_no=0) const |
Do K means segmentation, filling in the cluster array. | |
LImage< int > | initialize (const LImage< int > &orig, const ImageAttr< T > &attr, vector< Cluster< T > > *clusters) const |
Get an initial cut of clusters, somehow. | |
void | computeClusterAttr (const ImageAttr< T > &attr, const LImage< int > &label, vector< Cluster< T > > *clusters, bool has_K_levels=true) const |
Compute cluster attributes from the image attribute and labeling. | |
int | findBestCluster (const T ¤t, const vector< Cluster< T > > &clusters, const LImage< int > &labels, int x, int y) const |
Return label corresponding to best cluster available. | |
float | computeMeasureDistance (const Cluster< T > &cluster, const T ¤t, 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 ¤t) const |
Finds distance between two statistics. | |
float | computeDiscontiguityDistance (const LImage< 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 LImage< int > | computeDetailImage (const LImage< int > &label, const ImageAttr< T > &attr, std::vector< Replacement > *replacements_list) |
This function may be over-ridden to provide a different way of selecting among the regions produced by K-means segmentation. | |
virtual void | computeReplacements (const LImage< int > &label, const ImageAttr< T > &attr, std::vector< Replacement > *replacements_list) |
This function may be over-ridden to provide a different way of choosing how to combine/replace regions at higher levels. | |
Static Protected Member Functions | |
static void | expand_segment (int x, int y, const LImage< int > &orig, LImage< int > &segimg, int label) |
Set the segimg at x,y to be label and then call this function. | |
static LImage< int > | relabel (const LImage< int > &label_img) |
Will relabel the image, removing unused labels. | |
static LImage< int > | pruneRegions (const LImage< int > &label, RegionPruner &) |
This method removes all regions that meet certain criteria. | |
Static Protected Attributes | |
static const int | Unset = -1000 |
static const int | Invalid = -2000 |
Friends | |
class | Pruner |
Classes | |
class | RegionCheck |
A class that makes it easy to check whether a region is valid or has been merged away. |
typedef Cluster< SingleFeature > kmeans::Segmenter::RegionProperty [inherited] |
The simplest region property is a cluster of a single feature.
typedef KMeansSegmenter<T>::Replacement kmeans::MergingKMSegmenter< T >::Replacement |
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.
Reimplemented from kmeans::Segmenter.
kmeans::MergingKMSegmenter< T >::MergingKMSegmenter | ( | int | min_val = 0 , |
|
int | max_val = 100 , |
|||
size_t | number_of_clusters = 16 | |||
) | [inline] |
virtual kmeans::MergingKMSegmenter< T >::~MergingKMSegmenter | ( | ) | [inline, virtual] |
void kmeans::KMeansSegmenter< T >::computeClusterAttr | ( | const ImageAttr< T > & | attr, | |
const LImage< int > & | label, | |||
vector< Cluster< T > > * | clusters, | |||
bool | has_K_levels = true | |||
) | const [protected, inherited] |
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.
virtual LImage<int> kmeans::KMeansSegmenter< T >::computeDetailImage | ( | const LImage< int > & | label, | |
const ImageAttr< T > & | attr, | |||
std::vector< Replacement > * | replacements_list | |||
) | [protected, virtual, inherited] |
This function may be over-ridden to provide a different way of selecting among the regions produced by K-means segmentation.
label | The image with the K-means segmentation done and labels computed based on 8-neighborhood, but no selection among the regions performed. | |
attr | The attributes computed at every pixel of the image to be segmented. | |
replacements_list | The list of replacements; the first element (most detail) will be filled in here. |
float kmeans::KMeansSegmenter< T >::computeDiscontiguityDistance | ( | const LImage< int > & | label, | |
int | x, | |||
int | y, | |||
int | candidate_label | |||
) | const [protected, inherited] |
Way to compute discontiguity if the current label were to be changed to the candidate.
Returns a number between 0 and 1.
float kmeans::KMeansSegmenter< T >::computeMeasureDistance | ( | const T & | other, | |
const T & | current | |||
) | const [protected, inherited] |
Finds distance between two statistics.
float kmeans::KMeansSegmenter< T >::computeMeasureDistance | ( | const Cluster< T > & | cluster, | |
const T & | current, | |||
int | x, | |||
int | y | |||
) | const [protected, inherited] |
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 kmeans::Segmenter::computeRegionProperty | ( | const LImage< int > & | label, | |
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 kmeans::Segmenter::computeRegionProperty | ( | const LImage< int > & | orig, | |
const LImage< int > & | label, | |||
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.
virtual void kmeans::KMeansSegmenter< T >::computeReplacements | ( | const LImage< int > & | label, | |
const ImageAttr< T > & | attr, | |||
std::vector< Replacement > * | replacements_list | |||
) | [protected, virtual, inherited] |
This function may be over-ridden to provide a different way of choosing how to combine/replace regions at higher levels.
label | The image with the K-means segmentation done and labels computed based on 8-neighborhood, but no selection among the regions performed. | |
attr | The attributes computed at every pixel of the image to be segmented. | |
replacements_list | The list of replacements; the first element (most detail) should be filled already. Coarser detail will be filled in here. |
virtual void kmeans::MergingKMSegmenter< T >::computeReplacements | ( | const LImage< int > & | label, | |
const ImageAttr< T > & | attr, | |||
std::vector< Replacement > * | replacements_list | |||
) | [protected, virtual] |
Uses inter-cluster distance to decide the replacement of region labels at different scales.
label | The image with the K-means segmentation done and labels computed based on 8-neighborhood, but no selection among the regions performed. | |
attr | The attributes computed at every pixel of the image to be segmented. | |
replacements_list | The list of replacements; the first element (most detail) should be filled already. Coarser detail will be filled in here. |
LImage<int> kmeans::KMeansSegmenter< T >::doKMeans | ( | const ImageAttr< T > & | attr, | |
LImage< int > * | label, | |||
vector< Cluster< T > > * | clusters, | |||
int | iter_no = 0 | |||
) | const [protected, inherited] |
Do K means segmentation, filling in the cluster array.
static void kmeans::Segmenter::expand_segment | ( | int | x, | |
int | y, | |||
const LImage< int > & | orig, | |||
LImage< int > & | segimg, | |||
int | label | |||
) | [static, 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
int kmeans::KMeansSegmenter< T >::findBestCluster | ( | const T & | current, | |
const vector< Cluster< T > > & | clusters, | |||
const LImage< int > & | labels, | |||
int | x, | |||
int | y | |||
) | const [protected, inherited] |
Return label corresponding to best cluster available.
size_t kmeans::KMeansSegmenter< T >::getNumScales | ( | ) | const [inherited] |
Returns the total number of scales in the segmentation.
The returned values correspond to the previous call to segment()
const Replacement& kmeans::KMeansSegmenter< T >::getReplacement | ( | size_t | scale | ) | const [inherited] |
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()
LImage<int> kmeans::KMeansSegmenter< T >::getScale | ( | size_t | scale, | |
bool | rawlabels = false | |||
) | const [inherited] |
The different scales.
The returned values correspond to the previous call to segment()
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. |
LImage<int> kmeans::KMeansSegmenter< T >::initialize | ( | const LImage< int > & | orig, | |
const ImageAttr< T > & | attr, | |||
vector< Cluster< T > > * | clusters | |||
) | const [protected, inherited] |
Get an initial cut of clusters, somehow.
The implementation here is to divide the measurement space (max-min) into equal parts.
static LImage<int> kmeans::Segmenter::pruneRegions | ( | const LImage< int > & | label, | |
RegionPruner & | ||||
) | [static, protected, inherited] |
This method removes all regions that meet certain criteria.
The function object RegionPruner should be provided to target the appropriate regions.
Usually, you'd want to relabel the image that you get after pruning.
static LImage<int> kmeans::Segmenter::relabel | ( | const LImage< int > & | label_img | ) | [static, protected, inherited] |
Will relabel the image, removing unused labels.
virtual LImage<int> kmeans::KMeansSegmenter< T >::segment | ( | const LImage< int > & | orig | ) | [virtual, inherited] |
Implements kmeans::Segmenter.
static void kmeans::KMeansSegmenter< T >::setMarkovWeight | ( | float | lambda | ) | [static, inherited] |
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!
void kmeans::KMeansSegmenter< T >::setOutputImageDir | ( | const std::string & | newDir | ) | [inherited] |
Pass in an empty string to turn off output.
void kmeans::KMeansSegmenter< T >::writeGraph | ( | const std::string & | filename | ) | const [inherited] |
Write out a DOT output file (in a form that the Graphviz utility dot can read).
This is a directed graph.
friend class Pruner [friend, inherited] |
const int kmeans::Segmenter::Invalid = -2000 [static, protected, inherited] |
const int kmeans::Segmenter::Unset = -1000 [static, protected, inherited] |