66 const Metric& metric = Metric{},
67 const double max_memory = 1)
69 using namespace detail;
71 const std::size_t n_colors = colors.size();
74 throw std::invalid_argument(
"At least one color is required to compute "
75 "a color difference matrix.");
78 if (!checkMatrixSize(n_colors, max_memory)) {
79 throw std::runtime_error(
80 "Color difference matrix would require " +
81 std::to_string(estimateMatrixMemory(n_colors) /
82 (1024.0 * 1024.0 * 1024.0)) +
83 " GB, which exceeds the limit of " + std::to_string(max_memory) +
84 " GB. Reduce the number of colors or increase the memory limit.");
87 Matrix<double> result(n_colors, n_colors);
90#pragma omp parallel for num_threads(Threads::get())
92 for (std::size_t i = 0; i < n_colors; ++i) {
97 for (std::size_t j = i + 1; j < n_colors; ++j) {
98 double d = metric(colors[i], colors[j]);
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.