Transform Color Space

Description

Allows to transform the current object into a different color space, if possible. Converting the colors of the current object into another color space. After calling this method, the object will be of a different class.

Usage

CIELUV.to(to, fixup=True)

Arguments

tostr
Name of the color space into which the colors should be converted (e.g., "CIEXYZ", "HCL", "hex", "sRGB", …).
fixupbool
Whether or not colors outside the defined rgb color space should be corrected if necessary, defaults to True.

Examples

from colorspace import CIELUV
x = CIELUV([ 25,  45, 65, 85],
           [  6,  75, 90, 16],
           [-70, -50, 30, 42])
x
CIELUV color object (4 colors)
            L       U       V
  1:    25.00    6.00  -70.00
        45.00   75.00  -50.00
        65.00   90.00   30.00
        85.00   16.00   42.00
type(x)
colorspace.colorlib.CIELUV
# Convert colors to sRGB
x.to("sRGB")
x
sRGB color object (4 colors)
            R       G       B
  1:     0.29    0.11    0.57
         0.75    0.13    0.60
         0.95    0.48    0.41
         0.91    0.83    0.61
type(x)
colorspace.colorlib.sRGB
# Convert from sRGB to hex
x.to("hex")
x
  • #4B1C92
  • #BF229A
  • #F27B67
  • #E7D39B
# Convert back to CIELUV colors.
# Round-off errors due to conversion to 'hex'.
x.to("CIELUV")
x
CIELUV color object (4 colors)
            L       U       V
  1:    24.96    5.97  -70.24
        45.02   75.16  -49.87
        64.98   89.60   30.25
        84.97   15.69   41.71
# Extracting hex colors (returns list of str)
x.colors()
['#4B1C92', '#BF229A', '#F27B67', '#E7D39B']