L_ColorThresholdBitmap

#include "l_bitmap.h"

L_LTIMGCLR_API L_INT L_ColorThresholdBitmap (pBitmap, uColorSpace, pCompData, uFlags)

pBITMAPHANDLE pBitmap;

pointer to the bitmap handle

L_UINT uColorSpace;

color space

pCOMPDATA pCompData;

pointer to an array of structures

L_UINT32 uFlags;

flags

Using any one of eight color spaces, resets those bitmaps pixel component values that fall inside or outside of a specified range.

Parameter Description
pBitmap Pointer to the bitmap handle that references the bitmap on which to apply the effect.
uColorSpace Color space which the threshold is based on. Possible values are
  Value Meaning
  CLTH_RGB_SPACE [0x00000000] RGB color space
  CLTH_HSV_SPACE [0x00000001] HSV color space
  CLTH_HLS_SPACE [0x00000002] HLS color space
  CLTH_XYZ_SPACE [0x00000003] XYZ color space
  CLTH_YCrCb_SPACE [0x00000004] YCrCb color space
  CLTH_YUV_SPACE [0x00000005] YUV color space
  CLTH_LAB_SPACE [0x00000006] LAB color space
  CLTH_CMY_SPACE [0x00000007] CMY color space
pCompData Pointer to an array of 3 COMPDATA structures that contains the parameters used to compare and modify each component.
uFlags Reserved for future use. Must be 0.

Returns

SUCCESS

The function was successful.

< 1

An error occurred. Refer to Return Codes.

Comments

This function does not support signed data images. It returns the error code ERROR_SIGNED_DATA_NOT_SUPPORTED if a signed data image is passed to this function.

This function is similar to the L_ConvertColorSpace function but provides greater flexibility by allowing the specification of a range and different options for handling those values that fall outside of the range. Please note that every color space component may have a different range.

Color Component

Range for 8-bit components

Range for 16-bit components

RGB

 

 

R

0 255

0 - 65535

G

0 255

0 - 65535

B

0 255

0 - 65535

HSV

 

 

H

0 - 360

0 - 36000

S

0 - 100

0 - 10000

V

0 - 255

0 - 65535

HLS

 

 

H

0 - 360

0 - 36000

L

0 - 255

0 - 65535

S

0 - 100

0 - 10000

XYZ

 

 

X

0 - 255

0 - 65535

Y

0 - 255

0 - 65535

Z

0 - 255

0 - 65535

YCrCb

 

 

Y

0 - 255

0 - 65535

Cr

-128 - 127

-32768 - 32767

Cb

-128 - 127

-32768 - 32767

YUV

 

 

Y

0 - 255

0 - 65535

U

-112 - 111

-28567 - 28566

V

-138 - 137

-35337 - 35336

LAB

 

 

L

0 - 100

0 - 10000

A

-128 - 127

-32768 - 32767

B

-128 - 127

-32768 - 32767

CMY

 

 

C

0 - 255

0 - 65535

M

0 - 255

0 - 65535

Y

0 - 255

0 - 65535

This function works as follows:

1. The bitmap is converted to the required color space.
2. For every pixel, the following operations are performed: Each component is compared with the nMinRange and nMaxRange ranges of the appropriate COMPDATA structure.
  a. If it is inside the range, the component is considered to have "passed" the test.
  b. If it is outside the range, the component has been rejected". The CLTH_TYP_BANDREJECT flag inverts this by making "rejected" components "passed" and viceversa.
3. If CLTH_MOD_CHANNEL is set, the components are modified independently. If CLTH_MOD_ALL has been passed, the pixel is rejected by the test if any component is rejected. If the pixel/component is rejected, then:
  a. If CLTH_VALUE_MIN is passed, the rejected pixel/component is set to 0.
  b. If CLTH_VALUE_MAX is passed, the rejected pixel/component is set to 255.
  c. If CLTH_VALUE_CLAMP is passed, components less that nMin go to 0 and components greater than nMax go to 255. This would work only with the CLTH_MOD_CHANNEL and CLTH_TYP_BANDPASS flag.

This function works for 1, 2, 3, 8,16, 24, 32, 48 and 64-bit color bitmaps and can support regions for 24 and 48-bit bitmaps. If a 24 or 48-bit bitmap has a region the effect will be applied on the region only.

One structure is used for each color component. The order is considered to be the same as in the CLTH_xxx_SPACE name. For example, for CLTH_RGB_SPACE:

pCompData[0] structure is used for the Blue component

pCompData[1] structure is used for the Green component

pCompData[2] structure is used for the Red component

The pCompData[0].uStructSize must be set to sizeof(COMPDATA) before calling this function. For an array of structures, only the first structure in the array needs to have uStructSize member set.

To update a status bar or detect a user interrupt during execution of this function, refer to L_SetStatusCallback.

This function does not support 32-bit grayscale images. It returns the error code ERROR_GRAY32_UNSUPPORTED if a 32-bit grayscale image is passed to this function.

Required DLLs and Libraries

LTIMGCLR

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_BinaryFilterBitmap, L_ConvertColorSpace, L_ColorSeparateBitmap, L_ColorMergeBitmap, L_AddBitmapNoise, L_IntensityDetectBitmap, L_SpatialFilterBitmap, L_BinaryFilterBitmap, L_MaxFilterBitmap, L_MinFilterBitmap, L_AddShadowBitmap, L_ChangeHueSatIntBitmap, L_ColorThresholdBitmap, L_DFTBitmap, L_AllocFTArray, L_DirectionEdgeStatisticalBitmap, L_FFTBitmap, L_FreeFTArray, L_FrqFilterBitmap, L_FrqFilterMaskBitmap, L_FTDisplayBitmap, L_GetBitmapStatisticsInfo, L_GetFeretsDiameter, L_GetObjectInfo, L_GetRgnContourPoints, L_GetRgnPerimeterLength, L_MathFunctionBitmap, L_RevEffectBitmap, L_SegmentBitmap, L_SubtractBackgroundBitmap, L_UserFilterBitmap, L_AdjustBitmapTint, L_ColorHalfToneBitmap

Topics:

Raster Image Functions: Modifying Intensity Values

 

Correcting Colors

 

Raster Image Functions: Getting and Setting Pixel Values

 

Raster Image Functions: Doing Color Space Conversions

 

Raster Image Functions: Correcting Colors

Example

L_INT ColorThresholdBitmapExample(L_VOID) 
{ 
   L_INT nRet; 
   BITMAPHANDLE LeadBitmap;   /* Bitmap handle for the image */ 
   COMPDATA          pCompData[3]; 
   L_INT                     nI; 
 
   /* Load a bitmap at its own bits per pixel  */ 
   nRet = L_LoadBitmap(MAKE_IMAGE_PATH(TEXT("ImageProcessingDemo\\Image1.jpg")), &LeadBitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGR, NULL, NULL); 
   if(nRet !=SUCCESS) 
      return nRet; 
 
   pCompData[0].uStructSize = sizeof(COMPDATA); 
   for (nI = 0; nI < 3; nI++) 
   { 
       pCompData[nI].nMinRange = 128; 
       pCompData[nI].nMaxRange = 255;  
       pCompData[nI].uFlags = 0; 
   } 
 
   /* Apply color Threshold effect on the image*/ 
   nRet = L_ColorThresholdBitmap(&LeadBitmap, CLTH_RGB_SPACE,  pCompData, 0); 
   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 20.0.2018.1.19
Products | Support | Contact Us | Copyright Notices
© 1991-2018 LEAD Technologies, Inc. All Rights Reserved.
LEADTOOLS Raster Imaging C API Help