darsia.ColorSpectrum#
- class ColorSpectrum(base_color, spectrum, histogram, color_range)[source]#
Bases:
objectData 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
Get the color mode of the spectrum.
Compute the absolute color spectrum.
Compute the effective color spectrum as colors within the color range.
Return the shape of the spectrum.
Reference color for the spectrum.
Distribution of colors in the spectrum.
Histogram of color occurrences.
Color range associated with the spectrum.
- classmethod from_dict(data)[source]#
Create a ColorSpectrum from a dictionary.
- Parameters:
- data
dict Dictionary representation of the color spectrum.
- data
- Returns:
ColorSpectrumThe created ColorSpectrum instance.
- classmethod load(file_path)[source]#
Load the color spectrum from a file.
- Parameters:
- file_path
Path The path to the file from which the color spectrum will be loaded.
- file_path
- Returns:
ColorSpectrumThe loaded color spectrum.
- distance(color)[source]#
Compute the (minimum) distance between a color and the spectrum.
- Parameters:
- color
np.ndarray The color to compare against the spectrum.
- color
- Returns:
np.ndarray|floatThe computed distance.
- in_spectrum(colors, color_mode)[source]#
Check if given colors are within the spectrum.
- Parameters:
- colors
np.ndarray Colors to check.
- color_mode
darsia.ColorMode Color mode of the input colors.
- colors
- Returns:
np.ndarrayBoolean array indicating if each color is in the spectrum.
- save(file_path)[source]#
Save the color spectrum to a file.
- Parameters:
- file_path
Path The path to the file where the color spectrum will be saved.
- file_path
- to_dict()[source]#
Convert the color spectrum to a dictionary.
- Returns:
dictDictionary 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.ndarrayAbsolute color spectrum.
- histogram#
Histogram of color occurrences.
- property relative_colors#
Compute the effective color spectrum as colors within the color range.
- Returns:
np.ndarrayEffective color spectrum.
- property shape#
Return the shape of the spectrum.
- spectrum#
Distribution of colors in the spectrum.