ColorThreshold method (Main Control)

C++ Builder example

Delphi example

 

Builder Syntax

int ColorThreshold(unsigned uColorSpace, const COMPAREDATA * CompDataArray);

Delphi Syntax

Function ColorThreshold (uColorSpace: L_UINT; CompDataArray: TLEADComparedDataArray): L_INT;

Overview

Refer to Correcting Colors

Remarks

Resets those bitmap pixel component values that fall outside of a specified range, using any one of eight color spaces.

Please note that each 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

The method 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 COMPAREDATA record (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 vice-versa.

3.

If CLTH_MOD_CHANNEL is set, the components are modified independently. If CLTH_MOD_ALL has been set, 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 method 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 record (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] is used for the Red component

pCompData[1] is used for the Green component

pCompData[2] is used for the Blue component

This method 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 method.

See Also

Elements:

Intensity method, GammaCorrect method, Contrast method, HistoContrast method, StretchIntensity method, RemapIntensity method, Invert method, Saturation method, HistoEqualize method, Fill method, Pixel property, GetHistogram method, WindowLevel method, Hue method, Average method, IntensityDetect method, ColorReplace method, ChangeHueSatInt method

Topics:

Raster Images: Modifying Intensity Values

 

Raster Images: Doing Color Space Conversions

 

Using Color Values in LEADTOOLS