darsia.LabelColorPathMapRegression#

class LabelColorPathMapRegression(labels, color_range, resolution=11, mask=None, ignore_labels=[])[source]#

Bases: object

Algorithmic definition of relative color paths through regression for labeled images.

Methods

base_color_image(image)

Create an image where each label is colored by its base color.

color_path_map(prepared, keys[, directory])

Color paths of all labels from the edited key colors.

expand_color_spectrum(color_spectrum[, ...])

Expand the color spectrum through linear regression.

find_color_path(color_spectrum[, ignore, ...])

Find relative color paths for each label in the spectrum map (automatic).

get_base_colors(image[, verbose])

Get the base colors for each label in the image.

get_color_spectrum(images[, baseline, ...])

Get the color spectrum for each label in the image.

get_mean_base_color(image)

Get the mean base color across all labels in the image.

prepare_color_path_editing(color_spectrum[, ...])

Start of the manual calibration: the data to edit the paths of all labels.

Attributes

labels

Labeled image to define color paths for.

color_range

Color range for the regression.

discrete_color_range

Discrete color range for regression.

mask

Mask to apply when analyzing colors.

ignore_labels

Labels to ignore during color path regression.

color_mode

Color mode.

base_color_image(image)[source]#

Create an image where each label is colored by its base color.

Parameters:
imagedarsia.Image

The image from which to extract base colors.

Returns:
darsia.Image

An image where each label is colored by its base color.

color_path_map(prepared, keys, directory=None)[source]#

Color paths of all labels from the edited key colors.

Parameters:
prepareddict

Result of prepare_color_path_editing.

keysdict[int, list[np.ndarray]]

Relative key colors of the edited labels.

directoryPath, optional

Directory of the plots of the paths.

Returns:
LabelColorPathMap

Edited paths, and the fixed paths of the labels that are not editable.

expand_color_spectrum(color_spectrum, min_points=6, verbose=False)[source]#

Expand the color spectrum through linear regression.

Parameters:
color_spectrumColorSpectrum or LabelColorSpectrumMap

The color spectrum to expand.

min_pointsint

Minimum number of significant points to perform regression.

verbosebool

Whether to print additional information.

Returns:
LabelColorSpectrumMap

The expanded color spectrum.

find_color_path(color_spectrum, ignore=None, num_segments=1, directory=None, weighting='threshold', mode='auto', ignore_labels=None, verbose=False)[source]#

Find relative color paths for each label in the spectrum map (automatic).

For the manual calibration, see prepare_color_path_editing and color_path_map.

Parameters:
color_spectrumLabelColorSpectrumMap

The color spectrum map to analyze.

ignoreLabelColorSpectrumMap | None

The color spectrum map to ignore.

num_segmentsint

The number of segments for the color path.

weightingLiteral

How to use histogram counts when fitting each path. "threshold" (default) uses binary 0/1 weights from the spectrum threshold – counts are not used beyond that. "wls", "wls_sqrt", and "wls_log" use count-weighted average errors – see _find_color_path() for details.

modeLiteral

Only "auto"; "manual" raises (see prepare_color_path_editing).

ignore_labelslist[int] | None

Label IDs to skip fitting and produce zero-paths for instead. Defaults to None (no labels ignored).

verbosebool

Whether to print additional information.

Returns:
LabelColorPathMap

The relative color path map through the significant boxes.

get_base_colors(image, verbose=False)[source]#

Get the base colors for each label in the image.

Parameters:
imagedarsia.Image

The image from which to extract base colors.

verbosebool

Whether to print additional information.

Returns:
LabelColorMap

An object containing the base colors for each label.

get_color_spectrum(images, baseline=None, ignore=None, threshold_zero=0.0, threshold_significant=0.0, path=None, verbose=False)[source]#

Get the color spectrum for each label in the image.

The color spectrum is calculated by analyzing the distribution of colors within each label across the provided images. This involves creating a 3D histogram of color occurrences, which is then normalized to identify significant colors.

Parameters:
imageslist[darsia.Image]

The images to analyze. An empty list stands for the baseline alone: all relative colors are zero, as for images=[baseline], but without copying the baseline or looping over its pixels. Images in an integer type (see native in darsia.imread_from_optical) are converted to floats one at a time.

baselinedarsia.Image | None

The baseline image for comparison.

ignoredarsia.LabelColorSpectrumMap | darsia.ColorSpectrum | None

Colors to ignore in the spectrum.

threshold_zerofloat

The threshold for zeroing out insignificant colors.

threshold_significantfloat

The threshold for significant colors.

pathPath

Folder to store images.

verbosebool

Whether to print verbose output.

Returns:
LabelColorSpectrumMap

The color spectrum for each label.

get_mean_base_color(image)[source]#

Get the mean base color across all labels in the image.

Parameters:
imagedarsia.Image

The image from which to extract base colors.

Returns:
np.ndarray

The mean base color across all labels.

prepare_color_path_editing(color_spectrum, ignore=None, num_segments=1, weighting='threshold', ignore_labels=None, initial_paths=None, verbose=False)[source]#

Start of the manual calibration: the data to edit the paths of all labels.

Parameters:
color_spectrumLabelColorSpectrumMap

The color spectrum map to analyze.

ignoreLabelColorSpectrumMap | None

The color spectrum map to ignore.

num_segmentsint

The number of segments of the automatic fit.

weightingLiteral

How to use histogram counts when fitting (see _prepare_label).

ignore_labelslist[int] | None

Labels with a zero path (not editable).

initial_pathsdict[int, list[np.ndarray]] | None

Previously calibrated relative key colors per label; start instead of the automatic fit.

verbosebool

Whether to print additional information.

Returns:
dict

Per label the inputs of the editor (ColorPathInputs), or a fixed path (zero path of an ignored label, default path if no path can be fitted).

color_mode#

Color mode.

color_range#

Color range for the regression.

discrete_color_range#

Discrete color range for regression.

ignore_labels#

Labels to ignore during color path regression.

labels#

Labeled image to define color paths for.

mask#

Mask to apply when analyzing colors.