• Roman Donchenko's avatar
    Merge remote-tracking branch 'origin/2.4' into merge-2.4 · 6b5ac42a
    Roman Donchenko authored
    Conflicts:
    	modules/calib3d/doc/camera_calibration_and_3d_reconstruction.rst
    	modules/features2d/doc/common_interfaces_of_descriptor_extractors.rst
    	modules/features2d/doc/object_categorization.rst
    	modules/gpu/doc/camera_calibration_and_3d_reconstruction.rst
    	modules/gpu/doc/image_filtering.rst
    	modules/gpu/doc/image_processing.rst
    	modules/gpu/doc/video.rst
    	modules/imgproc/doc/miscellaneous_transformations.rst
    	modules/imgproc/doc/object_detection.rst
    	modules/imgproc/doc/structural_analysis_and_shape_descriptors.rst
    	modules/imgproc/src/samplers.cpp
    	modules/ml/doc/k_nearest_neighbors.rst
    	modules/nonfree/doc/feature_detection.rst
    	modules/ocl/include/opencv2/ocl/ocl.hpp
    	modules/photo/doc/inpainting.rst
    	modules/ts/include/opencv2/ts.hpp
    	platforms/scripts/camera_build.conf
    	samples/android/camera-calibration/AndroidManifest.xml
    6b5ac42a
clustering.rst 4.73 KB

Clustering

kmeans

Finds centers of clusters and groups input samples around the clusters.

The function kmeans implements a k-means algorithm that finds the centers of cluster_count clusters and groups the input samples around the clusters. As an output, \texttt{labels}_i contains a 0-based cluster index for the sample stored in the i^{th} row of the samples matrix.

The function returns the compactness measure that is computed as

\sum _i  \| \texttt{samples} _i -  \texttt{centers} _{ \texttt{labels} _i} \| ^2

after every attempt. The best (minimum) value is chosen and the corresponding labels and the compactness value are returned by the function. Basically, you can use only the core of the function, set the number of attempts to 1, initialize labels each time using a custom algorithm, pass them with the ( flags = KMEANS_USE_INITIAL_LABELS ) flag, and then choose the best (most-compact) clustering.

Note

  • An example on K-means clustering can be found at opencv_source_code/samples/cpp/kmeans.cpp
  • (Python) An example on K-means clustering can be found at opencv_source_code/samples/python2/kmeans.py

partition

Splits an element set into equivalency classes.

The generic function partition implements an O(N^2) algorithm for splitting a set of N elements into one or more equivalency classes, as described in http://en.wikipedia.org/wiki/Disjoint-set_data_structure . The function returns the number of equivalency classes.

[Arthur2007] Arthur and S. Vassilvitskii. k-means++: the advantages of careful seeding, Proceedings of the eighteenth annual ACM-SIAM symposium on Discrete algorithms, 2007