darsia.ColorSpectrum#
- class ColorSpectrum(base_color, spectrum, histogram, color_range)[source]#
Bases:
objectData structure to hold a (discrete) color spectrum.
Methods
Edges of the bins of the spectrum for each color channel.
contains(colors, color_mode)Check which colors fall into an active bin of the spectrum.
distance(color)Compute the (minimum) distance between a color and the spectrum.
frame_offset(color_mode)Shift from colors in the given color mode to the frame of the bins.
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.
- bin_edges()[source]#
Edges of the bins of the spectrum for each color channel.
These are the edges used by np.histogramdd when the spectrum is built from colors (bins=shape, range=color_range.range).
- Returns:
list[np.ndarray]Edges for each channel, of length shape[i] + 1.
- contains(colors, color_mode)[source]#
Check which colors fall into an active bin of the spectrum.
The colors are assigned to the bins of the spectrum like in np.histogramdd, with which the spectrum is built; colors outside of the color range are not contained.
- Parameters:
- colors
np.ndarray Colors, shape (…, 3).
- color_mode
darsia.ColorMode Color mode of the colors.
- colors
- Returns:
np.ndarrayBoolean array of shape (…).
- 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.
- frame_offset(color_mode)[source]#
Shift from colors in the given color mode to the frame of the bins.
- Parameters:
- color_mode
darsia.ColorMode Color mode of the colors to be compared with the spectrum.
- color_mode
- Returns:
np.ndarrayColor to add: zero if the modes agree, otherwise plus or minus the base color.
- 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.