# qualpal::colorDifferenceMatrix

C++ · 4.1.0

<a id="cpp-overloads"></a>

## Overloads

<a id="cpp-1b229a5c41bc799ed59276e6a39cc2bfa725babf1ba46b8883e489b5166072ad"></a>

### `colorDifferenceMatrix`

```cpp
Matrix<double> colorDifferenceMatrix(const std::vector<colors::XYZ> & colors, const metrics::MetricType & metric_type, const double max_memory = 1, const std::array<double, 3> & white_point = { 0.95047, 1, 1.08883 })
```

[Source](<https://github.com/jolars/qualpal/blob/887b793a3795d298a62e49356a72314ce59dab0d/include/qualpal/color_difference.h>)

Generate a color difference matrix for XYZ colors with runtime metric selection. 

Computes the pairwise color differences between all colors in the input vector, using the specified color difference metric (selected at runtime via MetricType). Internally converts XYZ colors to the appropriate color space for the selected metric.

<a id="cpp-1b229a5c41bc799ed59276e6a39cc2bfa725babf1ba46b8883e489b5166072ad-documentation-parameters"></a>

##### Parameters

**`colors`**

Vector of [colors::XYZ](<4d1887fdbe70c609fc0a10099309f48798368a21d082afcf2ea7968852b3bc87>) colors to compare. 

**`metric_type`**

Color difference metric to use (DIN99d, CIEDE2000, or CIE76). 

**`max_memory`**

Maximum memory (in GB) allowed for the matrix (default: 1.0). 

**`white_point`**

Reference white point for XYZ to Lab/DIN99d conversions (default: D65). 

 

<a id="cpp-1b229a5c41bc799ed59276e6a39cc2bfa725babf1ba46b8883e489b5166072ad-documentation-returns"></a>

##### Returns

[Matrix\<double\>](<5fe94dbe5eb001e79f83ec8732ccf4a60bb67506bda2c4a122d94885ebe71b3b>) Symmetric matrix of pairwise color differences \[size: n x n\]. 

 

<a id="cpp-1b229a5c41bc799ed59276e6a39cc2bfa725babf1ba46b8883e489b5166072ad-documentation-throws"></a>

##### Throws

**`std::invalid_argument`**

if the metric type is unsupported or input is invalid. 

**`std::runtime_error`**

if the estimated matrix size exceeds max\_memory.

 

<a id="cpp-1b229a5c41bc799ed59276e6a39cc2bfa725babf1ba46b8883e489b5166072ad-documentation-see-also"></a>

##### See also

[metrics::MetricType](<163ba1d9fcf391ead8f884f03d78de88badeb63c2287e002bd358200082069d7>) 

<a id="cpp-cb588a6f7fd35071934e2ef49e83dcf59ba428ad9f98021b08df43921008ab9b"></a>

### `colorDifferenceMatrix`

```cpp
template<typename ColorType, typename Metric = metrics::DIN99d> Matrix<double> colorDifferenceMatrix(const std::vector<ColorType> & colors, const Metric & metric = Metric { }, const double max_memory = 1)
```

[Source](<https://github.com/jolars/qualpal/blob/887b793a3795d298a62e49356a72314ce59dab0d/include/qualpal/color_difference.h>)

Generate a symmetric color difference matrix for a set of colors. 

Computes the pairwise perceptual color differences between all colors in the input vector, using the specified color difference metric (e.g., DIN99d, CIEDE2000, CIE76). The result is a symmetric matrix where element (i, j) is the distance between colors\[i\] and colors\[j\].

<a id="cpp-cb588a6f7fd35071934e2ef49e83dcf59ba428ad9f98021b08df43921008ab9b-documentation-template-parameters"></a>

##### Template parameters

**`ColorType`**

Any color class convertible to the required color space (e.g., [colors::RGB](<1a9e7400df83ac8262249ade4a2c007375c2d75db6ae37e8f78ca450266e8411>), [colors::HSL](<f36bc23dbb1e50e6765c182aec07a7cf7cd3d62e21fe43426fa3b6afb27490d0>), [colors::XYZ](<4d1887fdbe70c609fc0a10099309f48798368a21d082afcf2ea7968852b3bc87>), [colors::Lab](<bc5685852e488d86b4707de1ef1d606b788c0f89d090ec8c4cf03d84d1a6defd>), [colors::DIN99d](<a18b7bd442cf0552985e0348d19b68cab53705c36e10dec0d6cf914c671961d1>)). 

**`Metric`**

Color difference metric functor (defaults to [metrics::DIN99d](<27015d2beab2e4039b5bacc5eabfad002f7b2746b0445119676aada1f32a432d>)). 

 

<a id="cpp-cb588a6f7fd35071934e2ef49e83dcf59ba428ad9f98021b08df43921008ab9b-documentation-parameters"></a>

##### Parameters

**`colors`**

Vector of colors to compare. 

**`metric`**

Color difference metric to use (optional; default is DIN99d). 

**`max_memory`**

Maximum memory (in GB) allowed for the matrix (default: 1.0). 

 

<a id="cpp-cb588a6f7fd35071934e2ef49e83dcf59ba428ad9f98021b08df43921008ab9b-documentation-returns"></a>

##### Returns

[Matrix\<double\>](<5fe94dbe5eb001e79f83ec8732ccf4a60bb67506bda2c4a122d94885ebe71b3b>) Symmetric matrix of pairwise color differences \[size: n x n\]. 

 

<a id="cpp-cb588a6f7fd35071934e2ef49e83dcf59ba428ad9f98021b08df43921008ab9b-documentation-throws"></a>

##### Throws

**`std::invalid_argument`**

if fewer than one color is provided. 

**`std::runtime_error`**

if the estimated matrix size exceeds max\_memory.

 

<a id="cpp-cb588a6f7fd35071934e2ef49e83dcf59ba428ad9f98021b08df43921008ab9b-documentation-see-also"></a>

##### See also

[metrics::DIN99d](<27015d2beab2e4039b5bacc5eabfad002f7b2746b0445119676aada1f32a432d>), [metrics::CIEDE2000](<5333d0fe7760f4247a9ab5c591dde9118c40d0893b9c057884147334a8038ebd>), [metrics::CIE76](<9898a856a6f81d8ca2916b360ef9cb6ae98bbea3456e714e4c7391fdff024b9e>)
