color¶
Functions
|
Convert a color in either supported format to a HEX string. |
|
Generate new color which oppositely by exist colors. |
|
|
|
Convert HEX RGB string to integer RGB format. |
|
Generate RGB color with fixed saturation and lightness. |
|
Convert integer color format to HEX string. |
|
Generates ValueError if value not between 0 and 255. |
Description
Color utilities.
- color2hex(color)[source]¶
Convert a color in either supported format to a HEX string.
Accepts a HEX string or an RGB list. Useful on API boundaries, where the server expects HEX while the SDK stores RGB. Both forms are validated, so an invalid color fails here rather than as a server-side 400.
- Parameters:
- Raises:
ValueError – If the string is not a valid HEX RGB color, or a channel of the RGB list is out of range.
- Returns:
HEX RGB string
- Return type:
- Usage Example:
import supervisely as sly sly.color.color2hex([128, 64, 255]) # '#8040FF' sly.color.color2hex('#8040FF') # '#8040FF'
- generate_rgb(exist_colors)[source]¶
Generate new color which oppositely by exist colors.
-
random_rgb(fix_satlight=
True)[source]¶ Generate RGB color with fixed saturation and lightness.
- Returns:
RGB integer values
- Return type:
List[int, int, int]- Usage Example:
import supervisely as sly color = sly.color.random_rgb() print(color) # Output: [138, 15, 123]