pypindou.color.space

Color-space helpers used by quantizers.

The quantizers operate on RGB arrays but can compute distances either directly in RGB or in CIE Lab. Lab is the default for image-to-pattern generation because it is usually closer to perceived color difference.

Example:

>>> import numpy as np
>>> convert_colors(np.array([[255, 255, 255]], dtype=np.uint8), color_space="rgb").tolist()
[[255.0, 255.0, 255.0]]

ColorSpace

pypindou.color.space.ColorSpace

Literal['rgb', 'lab'] 的别名

as_color_array

pypindou.color.space.as_color_array(rgb)[源代码]

Normalize an array-like RGB table to a float64 (n, 3) array.

参数:

rgb (numpy.ndarray) -- RGB array-like object.

返回:

Normalized float64 array.

返回类型:

numpy.ndarray

抛出:

ValueError -- If the input shape is not (n, 3).

convert_colors

pypindou.color.space.convert_colors(rgb, color_space='lab')[源代码]

Convert RGB values in 0..255 to the requested distance space.

参数:
  • rgb (numpy.ndarray) -- RGB values with shape (n, 3).

  • color_space (ColorSpace, optional) -- Target distance space, defaults to "lab".

返回:

Converted color array.

返回类型:

numpy.ndarray

抛出:

ValueError -- If color_space is unsupported.