27estimateMatrixMemory(std::size_t n)
29 return n * n *
sizeof(double);
33checkMatrixSize(std::size_t n,
double max_gb = 1.0)
35 double estimated_gb = estimateMatrixMemory(n) / (1024.0 * 1024.0 * 1024.0);
36 return estimated_gb <= max_gb;
62template<
typename ColorType,
typename Metric = metrics::DIN99d>
65 const Metric& metric = Metric{},
66 const double max_memory = 1)
68 using namespace detail;
70 const std::size_t n_colors = colors.size();
73 throw std::invalid_argument(
"At least one color is required to compute "
74 "a color difference matrix.");
77 if (!checkMatrixSize(n_colors, max_memory)) {
78 throw std::runtime_error(
79 "Color difference matrix would require " +
80 std::to_string(estimateMatrixMemory(n_colors) /
81 (1024.0 * 1024.0 * 1024.0)) +
82 " GB, which exceeds the limit of " + std::to_string(max_memory) +
83 " GB. Reduce the number of colors or increase the memory limit.");
86 Matrix<double> result(n_colors, n_colors);
89#pragma omp parallel for num_threads(Threads::get())
91 for (
int i = 0; i < static_cast<int>(n_colors); ++i) {
96 for (std::size_t j =
static_cast<std::size_t
>(i) + 1; j < n_colors; ++j) {
97 double d = metric(colors[i], colors[j]);
132 const double max_memory = 1,
133 const std::array<double, 3>& white_point = { 0.95047,
Matrix classes for qualpal.
Color difference metrics for qualpal.
MetricType
Supported color difference metrics for palette generation and analysis.
Qualitative color palette generation library.
Matrix< double > colorDifferenceMatrix(const std::vector< ColorType > &colors, const Metric &metric=Metric{}, const double max_memory=1)
Generate a symmetric color difference matrix for a set of colors.
Thread management for parallel computations.