L_WatershedBitmap

#include "ltimgcor.h"

L_LTIMGCOR_API L_INT L_WatershedBitmap( pBitmap, ppPoints, pLengths, nSize)

pBITMAPHANDLE pBitmap;

pointer to the bitmap handle

L_POINT** ppPoints;

pointer to a pointer to an L_POINT structure

L_INT* pLengths;

pointer to the number of points in each path

L_INT nSize;

number of paths

Separates the image into different segments using the Watershed algorithm.

Parameter

Description

pBitmap

Pointer to the bitmap handle.

ppPoints

Holds the initial point/path that represents the point or path from which to segment the bitmap.

pLengths

Number of points in each path.

nSize

Number of paths.

Returns

SUCCESS

The function was successful.

< 1

An error occurred. Refer to Return Codes.

Comments

Each segment's pixels have the same color. The Watershed algorithm treats an image as if it were a topographic surface.

The dark areas are basins. The light areas are the ridges around the basins.

The user is responsible for determining the number of output segments and the location of each segment in the input array.

This function supports 8- and 16-bit grayscale and colored images and 24- and 32-bit colored images.

This function does not support 32-bit grayscale 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_LevelsetBitmapRgnL_ShrinkWrapTool, L_KMeansBitmapSegmentation, L_GWireGetMinPathL_OtsuThreshold

Topics:

Raster Image Functions: Image Analysis
Raster Image Functions: Processing an Image      
Processing an Image

Example

#define MAKE_IMAGE_PATH(pFileName) TEXT("C:\\Users\\Public\\Documents\\LEADTOOLS Images\\")pFileName 
L_INT WatershedBitmapExample(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; 
   /* Apply a WatershedBitmap filter */ 
   L_POINT* ppPoints[4] = {} ; 
   L_INT Lengths[4]  = {} ; 
   L_INT nSize = 4 ; 
   for(L_INT i = 0 ; i < nSize; i++) 
   { 
      Lengths[i]  = 2 ; 
      ppPoints[i] = (L_POINT*) malloc(Lengths[i]*sizeof(L_POINT)); 
      if ( ppPoints[i] == NULL ) 
      { 
         for( L_INT j = 0 ; j < nSize ; j++ ) 
         { 
            if ( ppPoints[j] != NULL ) 
            { 
               free(ppPoints[j]) ; 
            } 
         } 
         if(LeadBitmap.Flags.Allocated) 
            L_FreeBitmap(&LeadBitmap); 
         return ERROR_NOT_ENOUGH_MEMORY ; 
      } 
   } 
   ppPoints[0][0].x = 35 ; ppPoints[0][0].y = 100 ; 
   ppPoints[0][1].x = 35 ; ppPoints[0][1].y = 200 ; 
   ppPoints[1][0].x = 180 ; ppPoints[1][0].y = 115 ; 
   ppPoints[1][1].x = 300 ; ppPoints[1][1].y = 115 ; 
   ppPoints[2][0].x = 235 ; ppPoints[2][0].y = 220 ; 
   ppPoints[2][1].x = 260 ; ppPoints[2][1].y = 220 ; 
   ppPoints[3][0].x = 180 ; ppPoints[3][0].y = 330 ; 
   ppPoints[3][1].x = 350 ; ppPoints[3][1].y = 330 ; 
   nRet = L_WatershedBitmap(&LeadBitmap, ppPoints, Lengths, nSize); 
   for( L_INT j = 0 ; j < nSize ; j++ ) 
   { 
      free(ppPoints[j]) ; 
   } 
   if(nRet == SUCCESS) 
      nRet = L_SaveBitmap(MAKE_IMAGE_PATH(TEXT("Result.BMP")), &LeadBitmap, FILE_BMP, 24, 0, NULL); 
   //free bitmap 
   if(LeadBitmap.Flags.Allocated) 
      L_FreeBitmap(&LeadBitmap) ; 
   return nRet ; 
} 

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