Performs image segmentation and color reduction using the K-means algorithm.
#include "ltwrappr.h"
virtual L_INT LBitmap::KMeansBitmapSegmentation(nCluster, ppOutCenters, nOutCentersCount, pInCenters, uFlags)
An integer that represents the number of output clusters or colors in the output image. Valid values range from 2 to 255. The default value is 4.
Pointer of a pointer to L_COLORREF values that will be filled with the centers of the output clusters.
Pointer to an integer that represents the number of output clusters.
Pointer to L_COLORREF values that represents the initial centers of the clusters. Used whenever the Type is KMEANS_USERDEFINED input clusters.
Flag that specifies which initializing algorithm to use when choosing the initial centers for the clusters.
Value | Meaning |
---|---|
KMEANS_RANDOM | [0x0001] Use a Random sampling algorithm to set the initial means. This is the default value. |
KMEANS_UNIFORM | [0x0002] Use a Uniform sampling algorithm to set the initial means. |
KMEANS_USERDEFINED | [0x0003] Use an array of user-defined initial centers to set the initial means. |
Value | Meaning |
---|---|
SUCCESS | The function was successful. |
< 1 | An error occurred. Refer to Return Codes. |
K-Means is an algorithm for analyzing data. Each observation gets placed in the cluster having the mean nearest it. The number of clusters returned are less than or equal to the number of input clusters. If the image contains fewer clusters than the number of input clusters, the ppOutCenters parameter will be filled with the centers of the output clusters.
This function can only process entire images. It does not support regions.
This function supports 12- and 16-bit grayscale and 48- and 64-bit color images.
This function supports signed/unsigned images.
Kmeans Segmentation Function - Before
Kmeans Segmentation Function - After
View additional platform support for this Kmeans Segmentation function.
Win32, x64.
#if defined (LEADTOOLS_V19_OR_LATER)
L_INT LBitmap__KMeansBitmapSegmentationExample(L_VOID)
{
L_INT nRet;
LBitmap LeadBitmap;
nRet = LeadBitmap.Load(MAKE_IMAGE_PATH(TEXT("IMAGE3.dcm")), 0,ORDER_BGR);
if(nRet !=SUCCESS)
return nRet ;
L_COLORREF* poutCenters = NULL ;
L_INT outCount ;
nRet = LeadBitmap.KMeansBitmapSegmentation( 5,
&poutCenters,
&outCount,
NULL,
KMEANS_RANDOM) ;
LeadBitmap.FreeKmeansOutput(poutCenters);
return nRet ;
}
#endif // LEADTOOLS_V19_OR_LATER
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document