darsia.ColorSpectrum#

class ColorSpectrum(base_color, spectrum, histogram, color_range)[source]#

Bases: object

Data structure to hold a (discrete) color spectrum.

Methods

distance(color)

Compute the (minimum) distance between a color and the spectrum.

from_dict(data)

Create a ColorSpectrum from a dictionary.

in_spectrum(colors, color_mode)

Check if given colors are within the spectrum.

load(file_path)

Load the color spectrum from a file.

save(file_path)

Save the color spectrum to a file.

to_dict()

Convert the color spectrum to a dictionary.

Attributes

color_mode

Get the color mode of the spectrum.

colors

Compute the absolute color spectrum.

relative_colors

Compute the effective color spectrum as colors within the color range.

shape

Return the shape of the spectrum.

base_color

Reference color for the spectrum.

spectrum

Distribution of colors in the spectrum.

histogram

Histogram of color occurrences.

color_range

Color range associated with the spectrum.

classmethod from_dict(data)[source]#

Create a ColorSpectrum from a dictionary.

Parameters:
datadict

Dictionary representation of the color spectrum.

Returns:
ColorSpectrum

The created ColorSpectrum instance.

classmethod load(file_path)[source]#

Load the color spectrum from a file.

Parameters:
file_pathPath

The path to the file from which the color spectrum will be loaded.

Returns:
ColorSpectrum

The loaded color spectrum.

distance(color)[source]#

Compute the (minimum) distance between a color and the spectrum.

Parameters:
colornp.ndarray

The color to compare against the spectrum.

Returns:
np.ndarray | float

The computed distance.

in_spectrum(colors, color_mode)[source]#

Check if given colors are within the spectrum.

Parameters:
colorsnp.ndarray

Colors to check.

color_modedarsia.ColorMode

Color mode of the input colors.

Returns:
np.ndarray

Boolean array indicating if each color is in the spectrum.

save(file_path)[source]#

Save the color spectrum to a file.

Parameters:
file_pathPath

The path to the file where the color spectrum will be saved.

to_dict()[source]#

Convert the color spectrum to a dictionary.

Returns:
dict

Dictionary representation of the color spectrum.

base_color#

Reference color for the spectrum.

property color_mode#

Get the color mode of the spectrum.

color_range#

Color range associated with the spectrum.

property colors#

Compute the absolute color spectrum.

Returns:
np.ndarray

Absolute color spectrum.

histogram#

Histogram of color occurrences.

property relative_colors#

Compute the effective color spectrum as colors within the color range.

Returns:
np.ndarray

Effective color spectrum.

property shape#

Return the shape of the spectrum.

spectrum#

Distribution of colors in the spectrum.