Color corrections (darsia.corrections.color)#

The provided color correction require the presence of a color palette as part of an image to be able to calibrate the colors and thus the data. Both standard references are provided as well as meas to define custom standards.

Color correction implementations#

colorcorrection

Module containing a Machine learning free color correction/calibration based on the Classic Color Checker from calibrite / x-rite.

experimentalcolorcorrection

Color corrections using ML-located color checker.

darsia.corrections.color.colorcorrection module#

Module containing a Machine learning free color correction/calibration based on the Classic Color Checker from calibrite / x-rite.

class ColorChecker[source]#

Bases: ABC

Base class for color checkers.

plot()[source]#

Plot color checker.

save(path)[source]#
property swatches_RGB#
property swatches_rgb#
class ColorCheckerAfter2014[source]#

Bases: ColorChecker

Definition of the classic color checker under (hardcoded) default illumination conditions.

plot()#

Plot color checker.

save(path)#
property swatches_RGB#
property swatches_rgb#
class ColorCorrection(base=None, config=None)[source]#

Bases: BaseCorrection

Color correction with user-specified location of a color checker.

Precise user-input is required for detecting the color checker. The Calibrite/ X-rite color checker has four corner landmarks on the colorchecker. The pixel coordinates of these have to be provided as input parameters, starting with the corner close to the brown swatch, and continuing in counter-clockwise direction. The color correction is applied prior to curvature correction in the darsia.Image initialization, and therefore, the roi should be with respect to the uncorrected image.

correct_array(img)[source]#

Similar workflow as by colour-science to match the colors of the color checker with the corresponding reference values, but tailored and simplified, based on the precise user-input on the location of the color checker. Reference to the general workflow: colour-science/colour-checker-detection

Parameters:

img (np.ndarray) – image in RGB space, with values in uint8, uint16, float32, or float64.

Returns:

corrected image

Return type:

np.ndarray

correct_metadata(metadata={})#

Correction routine on metadata level.

Parameters:

metadata (dict) – metadata dictionary.

Returns:

corrected metadata dictionary.

Return type:

dict

load(path)[source]#

Load the color correction from a file.

Parameters:

path (Path) – path to the file

save(path)[source]#

Save the color correction to a file.

Parameters:

path (Path) – path to the file

write_config_to_file(path)[source]#

Writes the config dictionary to a json-file.

Parameters:

path (Path) – path to the json file

config#

Config dictionary for initialization of color correction.

class CustomColorChecker(reference_colors=None, image=None, path=None)[source]#

Bases: ColorChecker

Swatch colors determined from user-prescribed input image.

plot()#

Plot color checker.

save(path)#
property swatches_RGB#
property swatches_rgb#

darsia.corrections.color.experimentalcolorcorrection module#

Color corrections using ML-located color checker.

Module containing the color correction based on the Classic Color Checker from calibrite / x-rite. The algorithms here heavily use code from colour-science (see their github). This includes some ML-based algorithms. Sometimes, the algorithms are not able to detect the color checker despite a rather precise user-input on the location of the color checker. Or the swatches are not extracted correcty. In such cases, darsia.ColorCorrection should be used which should always work. It is therefore recommended to double-check the results of the any of the color correction routines by setting verbosity to True once.

class ClassicColorChecker[source]#

Bases: object

Definition of the classic color checker under default illumination conditions.

class EOTF[source]#

Bases: object

Electro-optical transfer function (EOTF),the standard transfer function for sRGB, cf. https://en.wikipedia.org/wiki/SRGB

adjust(image)[source]#

Apply EOTF using the look up table.

Parameters:

image (np.ndarray) – image in linear RGB (uint8) format.

Returns:

image with tranformed color space, with values in [0,1].

Return type:

np.ndarray

inverse_approx(image)[source]#

Apply approximate of the inverse of EOTF using the look up table. In order to apply the exact inverse, the expensive function colout.cctf_encoding would have to be applied to all pixels (with values in [0,1]). By restricting the allowed input values to uint8 values, allows for faster LUT.

Parameters:

image (np.ndarray) – image in gamma-corrected RGB format with values in [0,1].

Returns:

image in linear RGB (uint8) format.

Return type:

np.ndarray

class ExperimentalColorCorrection(config=None, roi=None, verbosity=False, whitebalancing=True)[source]#

Bases: BaseCorrection

correct_array(image)[source]#

Apply workflow from colour-science to match the colors of the color checker with the corresponding color values, cf. colour-science/colour-checker-detection

Parameters:

image (np.ndarray) – image with uint8 value in (linear) RGB color space

Returns:

corrected image with uint8 values in (linear) RGB color space,

with colors matched based on the color checker within the roi

Return type:

np.ndarray

correct_metadata(metadata={})#

Correction routine on metadata level.

Parameters:

metadata (dict) – metadata dictionary.

Returns:

corrected metadata dictionary.

Return type:

dict

load(path)[source]#
save(path)[source]#