LBitmap::GWireInit

Summary

Changes the color of each pixel in the class objects bitmap to the median color of pixels in its neighborhood. This is similar to the LBitmap::AverageFilter function, but it is used for noise reduction, rather than a blur effect.

Syntax

#include "ltwrappr.h"

virtual L_INT LBitmap::GWireInit(pHGWire, nExternalEnergy)

Parameters

GWIREHANDLE *pHGWire

pointer to the Gwire handle.

L_INT nExternalEnergy

Integer value that represents the value of the external energy used in constructing the minimum paths in the image. Possible values range from 0 to 100. The default value is 90.

Returns

Value Meaning
SUCCESS The function was successful.
< 1 An error occurred. Refer to Return Codes.

Comments

GWire is an adaptation of the livewire technique for segmenting an image. Whereas livewire techniques use external energy (only) to find the boundary, GWire uses both external energy as well as internal energy, making it less sensitive to noise. The nExternalEnergy parameter balances the minimal path length with the minimal path weight.

This function initializes the GWire engine and should be called before using the LBitmap::GWireSetSeedPoint or LBitmap::GWireGetMinPath function. Free the handle generated by calling the LBitmap::DestroyGWireHandle function.

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.

Required DLLs and Libraries

Platforms

Win32, x64.

See Also

Functions

Topics

Example

L_INT LBitmap__GWireFilterBitmapExample(L_VOID) 
{ 
    L_INT nRet ; 
    LBitmap LeadBitmap ; 
 
    nRet = LeadBitmap.Load(MAKE_IMAGE_PATH(TEXT("IMAGE3.dcm")), 0,ORDER_BGR); 
    if(nRet !=SUCCESS) 
        return nRet; 
 
    GWIREHANDLE gwire ; 
 
    nRet = LeadBitmap.GWireInit(&gwire, 90); 
    if(nRet != SUCCESS) 
    { 
        LeadBitmap.DestroyGWireHandle(gwire); 
        return nRet ; 
    } 
 
    POINT** ppGWirePaths  ; 
    L_INT*  pGWireLengths ; 
    ppGWirePaths = (POINT**) malloc(10 * sizeof(POINT*)); 
    pGWireLengths = (L_INT*) malloc(10 * sizeof(L_INT)); 
    if(ppGWirePaths == NULL || pGWireLengths == NULL) 
    { 
        if(ppGWirePaths == NULL) free(ppGWirePaths); 
        if(pGWireLengths == NULL) free(pGWireLengths); 
 
        LeadBitmap.DestroyGWireHandle(gwire); 
 
        return ERROR_NO_MEMORY ; 
    } 
 
    // Get the boundaries of the object 
    POINT SeedPoints[9] ; 
    SeedPoints[0].x =  200 ; SeedPoints[0].y = 163 ; 
    SeedPoints[1].x =  245 ; SeedPoints[1].y = 195 ; 
    SeedPoints[2].x =  289 ; SeedPoints[2].y = 163 ; 
    SeedPoints[3].x =  282 ; SeedPoints[3].y = 188 ; 
    SeedPoints[4].x =  304 ; SeedPoints[4].y = 314 ; 
    SeedPoints[5].x =  247 ; SeedPoints[5].y = 271 ; 
    SeedPoints[6].x =  201 ; SeedPoints[6].y = 315 ; 
    SeedPoints[7].x =  228 ; SeedPoints[7].y = 199 ; 
    SeedPoints[8].x =  199 ; SeedPoints[8].y = 175 ; 
 
    L_INT pointIdx = 0 ; 
 
    // Loop over the list of SeedPoints to get the minimum path between each set of two points. 
    for (int index = 0; index < 4; index++) 
    { 
        // Set the seed point. 
        LeadBitmap.GWireSetSeedPoint(gwire, SeedPoints[pointIdx]); 
 
        pointIdx++; 
 
        // Get the minimum path from the seed point to the target point. 
        LeadBitmap.GWireGetMinPath(gwire, SeedPoints[pointIdx], &ppGWirePaths[index], &pGWireLengths[index]); 
    } 
 
    L_INT PointsSum = 0 ; 
    for(L_INT i = 0 ; i < pointIdx ; i++) 
    { 
        PointsSum += pGWireLengths[i] ; 
    } 
 
    // have all paths in one buffer. 
    POINT* pFinalPath = (POINT*) malloc(PointsSum * sizeof(POINT)); 
    L_INT PointsCount = 0 ; 
    for(L_INT i = 0 ; i < pointIdx ; i++) 
    { 
        memcpy(&(pFinalPath[PointsCount]),ppGWirePaths[i],pGWireLengths[i]*sizeof(POINT)); 
        LeadBitmap.FreeGWirePath(ppGWirePaths[i]); 
        PointsCount+=pGWireLengths[i] ; 
    } 
 
    LeadBitmap.DestroyGWireHandle(gwire); 
    free(ppGWirePaths); 
    free(pGWireLengths); 
    free(pFinalPath); 
 
    return SUCCESS; 
} 
Help Version 22.0.2023.2.2
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Raster Imaging C++ Class Library Help
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.