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.

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.

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.

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.

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', preview_image=None, preview_images=None, preview_baseline=None, ignore_labels=None, verbose=False)[source]#

Find relative color paths for each label in the spectrum 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

Color-path selection mode. "auto" returns the automated result. "manual" enables interactive key-color postprocessing.

preview_imagedarsia.Image | None

Calibration image for manual preview.

preview_imageslist[darsia.Image] | None

Calibration images for manual preview navigation.

preview_baselinedarsia.Image | None

Baseline used for relative color preview.

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.

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.

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.