colourlab.metric module

metric: Colour metric functions. Part of the colourlab package.

Copyright (C) 2013-2017 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.metric.dE_00(dat1, dat2, k_L=1, k_C=1, k_h=1)[source]

Compute the CIEDE00 metric.

Parameters:
  • dat1 (Points) – The colour data of the first data set.
  • dat2 (Points) – The colour data of the second data set.
  • k_L (float) – Parameter of the CIEDE00 metric
  • k_C (float) – Parameter of the CIEDE00 metric
  • k_h (float) – Parameter of the CIEDE00 metric
Returns:

distance – Array of the difference or distances between the two data sets.

Return type:

ndarray

colourlab.metric.dE_DIN99(dat1, dat2)[source]

Compute the DIN99 metric.

Parameters:
  • dat1 (Points) – The colour data of the first data set.
  • dat2 (Points) – The colour data of the second data set.
Returns:

distance – Array of the difference or distances between the two data sets.

Return type:

ndarray

colourlab.metric.dE_DIN99b(dat1, dat2)[source]

Compute the DIN99b metric.

Parameters:
  • dat1 (Points) – The colour data of the first data set.
  • dat2 (Points) – The colour data of the second data set.
Returns:

distance – Array of the difference or distances between the two data sets.

Return type:

ndarray

colourlab.metric.dE_DIN99c(dat1, dat2)[source]

Compute the DIN99c metric.

Parameters:
  • dat1 (Points) – The colour data of the first data set.
  • dat2 (Points) – The colour data of the second data set.
Returns:

distance – Array of the difference or distances between the two data sets.

Return type:

ndarray

colourlab.metric.dE_DIN99d(dat1, dat2)[source]

Compute the DIN99d metric.

Parameters:
  • dat1 (Points) – The colour data of the first data set.
  • dat2 (Points) – The colour data of the second data set.
Returns:

distance – Array of the difference or distances between the two data sets.

Return type:

ndarray

colourlab.metric.dE_E(dat1, dat2)[source]

Compute the DEE metric.

Parameters:
  • dat1 (Points) – The colour data of the first data set.
  • dat2 (Points) – The colour data of the second data set.
Returns:

distance – Array of the difference or distances between the two data sets.

Return type:

ndarray

colourlab.metric.dE_ab(dat1, dat2)[source]

Compute the DEab metric.

Parameters:
  • dat1 (Points) – The colour data of the first data set.
  • dat2 (Points) – The colour data of the second data set.
Returns:

distance – Array of the difference or distances between the two data sets.

Return type:

ndarray

colourlab.metric.dE_uv(dat1, dat2)[source]

Compute the DEuv metric.

Parameters:
  • dat1 (Points) – The colour data of the first data set.
  • dat2 (Points) – The colour data of the second data set.
Returns:

distance – Array of the difference or distances between the two data sets.

Return type:

ndarray

colourlab.metric.euclidean(sp, dat1, dat2)[source]

Compute the Euclidean metric between the two data sets in the given space.

Parameters:
  • sp (Space) – Colour space
  • dat1 (Points) – Colour data set 1
  • dat2 (Points) – Colour data set 2
Returns:

distance – Array of the difference or distances between the two data sets.

Return type:

ndarray

colourlab.metric.linear(sp, dat1, dat2, metric_tensor_function)[source]

Compute the linearised colour difference between the two data sets.

The function metric_tensor_function is used to compute the metric tensor at the midpoint between the two data sets in the given colour space. Then the colour metric is computed as dC^T * g * dC.

Parameters:
  • sp (Space) – The colour space in which to compute the linearised metric.
  • dat1 (Points) – The colour data of the first data set.
  • dat2 (Points) – The colour data of the second data set.
  • metric_tensor_function (function) – Function giving the metric tensors at given colour data points.
Returns:

distance – Array of the difference or distances between the two data sets.

Return type:

ndarray

colourlab.metric.poincare_disk(sp, dat1, dat2)[source]

Compute the Poincare Disk metric betwen the two data sets.

Compted in the given space. Assumes that the space is some form of a Poincare Disk space, such that the radius of curvature is given by sp.R. The first coordinate is treated as Euclidean.

Parameters:
  • sp (Space) – Colour space (should be of Poincare Disk type)
  • dat1 (Points) – Colour data set 1
  • dat2 (Points) – Colour data set 2
Returns:

distance – Array of the difference or distances between the two data sets.

Return type:

ndarray

colourlab.metric.reshape_diff(diff, sh)[source]

Reshape the computed metric differences to fit with original data.

The purpose is for, e.g., the difference of two MxNx3 images to be a MxN scalar image etc.

Parameters:
  • diff (ndarray) – The computed differences
  • sh (tuple) – The shape of the original data (not the diff)