colourlab.statistics module

statistics: Colour metric statistics, part of the colourlab package

Copyright (C) 2013-2016 Ivar Farup

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

colourlab.statistics.dataset_distance(data1, data2)[source]

Euclidean distances between data in the two data sets.

Parameters:
  • data1 (ndarray) – The first dataset, Nx3.
  • data2 (ndarray) – The second data set, Nx3.
Returns:

diff – Array of Euclidean distances, N.

Return type:

ndarray

colourlab.statistics.minimal_dataset_distance(dataset, ground_truth)[source]

Return the minimal dataset distance between a dataset and a ground truth.

The dataset is assumed to be on the Lab form (as an Nx3 ndarray) and is changed by scaling and rotation about the L axis.

Parameters:
  • dataset (ndarray) – Nx3 ndarray with the colour data.
  • ground_truth (ndarray) – Nx3 ndarray with the ground truth colour data.
Returns:

  • diff (ndarray) – Array of minimal Euclidean distances.
  • opt_data (ndarray) – The optimised data set by scaling and rotation.
  • L-scale (float) – The optimal scale.
  • C-scale (float) – The optimal scale.
  • angle (float) – The optimal angle.

colourlab.statistics.pant_R_values(space, tdata1, tdata2, optimise=True, plane=None)[source]

Compute the list of R values for the given metric tensors in tdataN.

The R values are computed in the given colour space. If optimise=True, the maximum overall R values are found by scaling one of the data sets. The ellipses are computed in the given plane. If plane=None, all three principal planes are used, and the resulting array of R values will be three times the length ot tdataN.

Parameters:
  • space (Space) – The colour space in which to compute the R values.
  • tdata1 (Tensors) – The first set of colour metric tensors.
  • tdata2 (Tensors) – The second set of colour metric tensors.
  • optimise (bool) – Whether or not to optimise the scaling of the ellipse set.
  • plane (slice) – The principal plan for the ellipsoid cross sections.
Returns:

r_values – Pant R values

Return type:

ndarray

colourlab.statistics.stress(diff1, diff2, weights=None, confidence=0.95)[source]

Compute the STRESS for the two sets of differences.

The STRESS (standardised residual sum of squares) is returned as a percentage. If weights are given, WSTRESS is calculated.

Parameters:
  • diff1 (ndarray) – 1D array of colour differences.
  • diff2 (ndarray) – 1D array of colour differences.
  • weights (ndarray) – 1D array of individual weights for the colour differences. If None, the standard STRESS is calculated, if given, WSTRESS is calculated.
  • confidence (float) – The size of the confidence interval (e.g., .95 for a 95% confidence interval)
Returns:

  • stress (float) – Standard residual sum of squares.
  • interval (tuple) – The confidence interval for STRESS_a / STRESS_b