colour.recovery.Tree_Otsu2018#

class colour.recovery.Tree_Otsu2018(*args: Any, **kwargs: Any)[source]#

Sub-class of colour.recovery.otsu2018.Node representing the root node of a tree containing information shared with all nodes, such as the standard observer colour matching functions and the illuminant, if any is used.

Implement global operations involving the entire tree, such as optimisation and conversion to dataset.

Parameters:
  • reflectances (MultiSpectralDistributions) – Reference reflectances of the n reference colours to use for optimisation.

  • cmfs (MultiSpectralDistributions | None) – Standard observer colour matching functions, default to the CIE 1931 2 Degree Standard Observer.

  • illuminant (SpectralDistribution | None) – Illuminant spectral distribution, default to CIE Standard Illuminant D65.

Attributes

  • reflectances

  • cmfs

  • illuminant

Methods

  • __init__()

  • __str__()

  • optimise()

  • to_dataset()

References

[OYH18]

Examples

>>> import os
>>> import colour
>>> from colour import MSDS_CMFS, SDS_COLOURCHECKERS, SDS_ILLUMINANTS
>>> from colour.colorimetry import sds_and_msds_to_msds
>>> from colour.utilities import numpy_print_options
>>> XYZ = np.array([0.20654008, 0.12197225, 0.05136952])
>>> cmfs = (
...     MSDS_CMFS["CIE 1931 2 Degree Standard Observer"]
...     .copy()
...     .align(SpectralShape(360, 780, 10))
... )
>>> illuminant = SDS_ILLUMINANTS["D65"].copy().align(cmfs.shape)
>>> reflectances = sds_and_msds_to_msds(
...     SDS_COLOURCHECKERS["ColorChecker N Ohta"].values()
... )
>>> node_tree = Tree_Otsu2018(reflectances, cmfs, illuminant)
>>> node_tree.optimise(iterations=2, print_callable=lambda x: x)
>>> dataset = node_tree.to_dataset()
>>> path = os.path.join(
...     colour.__path__[0],
...     "recovery",
...     "tests",
...     "resources",
...     "ColorChecker_Otsu2018.npz",
... )
>>> dataset.write(path)
>>> dataset = Dataset_Otsu2018()
>>> dataset.read(path)
>>> sd = XYZ_to_sd_Otsu2018(XYZ, cmfs, illuminant, dataset)
>>> with numpy_print_options(suppress=True):
...     sd
SpectralDistribution([[ 360.        ,    0.0651341...],
                      [ 370.        ,    0.0651341...],
                      [ 380.        ,    0.0651341...],
                      [ 390.        ,    0.0749684...],
                      [ 400.        ,    0.0815578...],
                      [ 410.        ,    0.0776439...],
                      [ 420.        ,    0.0721897...],
                      [ 430.        ,    0.0649064...],
                      [ 440.        ,    0.0567185...],
                      [ 450.        ,    0.0484685...],
                      [ 460.        ,    0.0409768...],
                      [ 470.        ,    0.0358964...],
                      [ 480.        ,    0.0307857...],
                      [ 490.        ,    0.0270148...],
                      [ 500.        ,    0.0273773...],
                      [ 510.        ,    0.0303157...],
                      [ 520.        ,    0.0331285...],
                      [ 530.        ,    0.0363027...],
                      [ 540.        ,    0.0425987...],
                      [ 550.        ,    0.0513442...],
                      [ 560.        ,    0.0579256...],
                      [ 570.        ,    0.0653850...],
                      [ 580.        ,    0.0929522...],
                      [ 590.        ,    0.1600326...],
                      [ 600.        ,    0.2586159...],
                      [ 610.        ,    0.3701242...],
                      [ 620.        ,    0.4702243...],
                      [ 630.        ,    0.5396261...],
                      [ 640.        ,    0.5737561...],
                      [ 650.        ,    0.590848 ...],
                      [ 660.        ,    0.5935371...],
                      [ 670.        ,    0.5923295...],
                      [ 680.        ,    0.5956326...],
                      [ 690.        ,    0.5982513...],
                      [ 700.        ,    0.6017904...],
                      [ 710.        ,    0.6016419...],
                      [ 720.        ,    0.5996892...],
                      [ 730.        ,    0.6000018...],
                      [ 740.        ,    0.5964443...],
                      [ 750.        ,    0.5868181...],
                      [ 760.        ,    0.5860973...],
                      [ 770.        ,    0.5614878...],
                      [ 780.        ,    0.5289331...]],
                     SpragueInterpolator,
                     {},
                     Extrapolator,
                     {'method': 'Constant', 'left': None, 'right': None})

Return a new instance of the colour.utilities.TreeNode class.

Parameters:
__init__(reflectances: MultiSpectralDistributions, cmfs: MultiSpectralDistributions | None = None, illuminant: SpectralDistribution | None = None) None[source]#
Parameters:
Return type:

None

Methods

__init__(reflectances[, cmfs, illuminant])

branch_reconstruction_error()

Compute the reconstruction error for all leaves data connected to the node or its children.

is_inner()

Determine whether the node is an inner node.

is_leaf()

Determine whether the node is a leaf node.

is_root()

Determine whether the node is a root node.

leaf_reconstruction_error()

Compute the reconstruction error of the node data.

minimise(minimum_cluster_size)

Minimise the leaf reconstruction error by finding the best partition for the node.

optimise([iterations, minimum_cluster_size, ...])

Optimise the tree by repeatedly performing optimal partitioning of nodes, creating a tree that minimises the total reconstruction error.

render([tab_level])

Render the node and its children as a formatted tree string.

split(children, axis)

Convert the leaf node into an inner node using the specified children and partition axis.

to_dataset()

Create a colour.recovery.Dataset_Otsu2018 class instance based on data stored in the tree.

walk_hierarchy([ascendants])

Generate a generator to walk the colour.utilities.TreeNode tree hierarchy.

Attributes

children

Getter and setter for the node children.

cmfs

Getter for the standard observer colour matching functions.

data

Getter and setter for the node data.

id

Getter for the node identifier.

illuminant

Getter for the test illuminant.

leaves

Getter for all leaf nodes in the hierarchy.

name

Getter and setter for the node name.

parent

Getter and setter for the node parent.

partition_axis

Getter for the node partition axis.

reflectances

Getter for the reference reflectances.

root

Getter for the root node of the tree hierarchy.

row

Getter for the node row of the selector array.

siblings

Getter for the sibling nodes at the same hierarchical level.