L_KMeansBitmapSegmentation

#include "Ltimgcor.h"

L_LTIMGCOR_API L_INT L_KMeansBitmapSegmentation(pBitmap, nCluster, ppOutCenters, nOutCentersCount, pInCenters, uFlags)

pBITMAPHANDLE pBitmap;

pointer to the bitmap handle

L_UINT nCluster;

an integer that represents the number of output clusters or colors in the output image

L_COLORREF** ppOutCenters;

pointer of a pointer to an L_COLORREF structure that will be filled with the centers of the output clusters

L_INT* nOutCentersCount;

pointer to an integer that represents the number of output clusters

L_COLORREF* pInCenters;

pointer to L_COLORREF values that represents the initial centers of the clusters. Used whenever the Type is KMEANS_USERDEFINED input clusters

L_UINT uFlags;

flag that determines which initializing algorithm to use when choosing the initial centers for the clusters

Performs image segmentation and color reduction using the K-means algorithm.

Parameter Description
pBitmap Pointer to the bitmap handle.
nCluster 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.
ppOutCenters Pointer of a pointer to L_COLORREF values that will be filled with the centers of the output clusters.
nOutCentersCount Pointer to an integer that represents the number of output clusters.
pInCenters Pointer to L_COLORREF values that represents the initial centers of the clusters. Used whenever the Type is KMEANS_USERDEFINED input clusters.
uFlags Flag that specifies which initializing algorithm to use when choosing the initial centers for the clusters.
  Value Meaning
  KMEANS_RANDOM       [0x00000002] Use a Random sampling algorithm to set the initial means. This is the default value.
  KMEANS_UNIFORM      [0x00000003] Use a Uniform sampling algorithm to set the initial means.
  KMEANS_USERDEFINED [0x00000004] Use an array of user-defined initial centers to set the initial means.

Returns

SUCCESS

The function was successful.

< 1

An error occurred. Refer to Return Codes.

Comments

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.

Required DLLs and Libraries

LTIMGCOR

For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application.

Platforms

Win32, x64, Linux.

See Also

Functions:

L_LevelsetBitmapRgn, L_LambdaConnectedness, L_ShrinkWrapTool, L_WatershedBitmap, L_GWireGetMinPath

Topics:

Raster Image Functions: Doing Color Expansion or Reduction 

 

Raster Image Functions: Image Analysis
Processing an Image

Example

#define MAKE_IMAGE_PATH(pFileName) TEXT("C:\\Users\\Public\\Documents\\LEADTOOLS Images\\")pFileName 
L_INT KMeansBitmapSegmentationExample(L_VOID) 
{ 
   L_INT nRet; 
   BITMAPHANDLE LeadBitmap;   /* Bitmap handle to hold the loaded image. */ 
   /* Load the bitmap, keeping the bits per pixel of the file */ 
   nRet = L_LoadBitmap (MAKE_IMAGE_PATH(TEXT("IMAGE3.dcm")), &LeadBitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGR, NULL, NULL); 
   if(nRet != SUCCESS) 
      return nRet ; 
   L_COLORREF* poutCenters = NULL; 
   L_INT outCount ; 
   nRet = L_KMeansBitmapSegmentation(&LeadBitmap, 
   5, 
   &poutCenters, 
   &outCount, 
   NULL, 
   KMEANS_RANDOM) ; 
   L_FreeKmeansOutput(poutCenters); 
   if(nRet !=SUCCESS) 
      return nRet ; 
   nRet = L_SaveBitmap(MAKE_IMAGE_PATH(TEXT("Result.BMP")), &LeadBitmap, FILE_BMP, 24, 0, NULL); 
   if(nRet !=SUCCESS) 
      return nRet ; 
   //free bitmap 
   if(LeadBitmap.Flags.Allocated) 
      L_FreeBitmap(&LeadBitmap) ; 
   return SUCCESS; 
} 

Help Version 19.0.2017.10.27
Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.
LEADTOOLS Raster Imaging C API Help