Checkpoint

This commit is contained in:
Ian Gulliver
2017-08-10 13:51:39 -07:00
parent 06ce954bef
commit c9024d3d63
11 changed files with 165 additions and 65 deletions

View File

@@ -1,6 +1,7 @@
#pragma once
#include <array>
#include <cstdint>
#include <numeric>
#include "color.h"
@@ -8,35 +9,36 @@
#include "coord.h"
#include "image.h"
#include "lut.h"
#include "minimum.h"
// Maximum LUT size that has each point adjacent to at least one ColorChecker color.
typedef Lut3d<4, 3, 3> ColorCheckerLut3d;
constexpr std::array<Color, 24> kColorCheckerSrgb = {{
{0x7300, 0x5200, 0x4400},
{0xc200, 0x9600, 0x8200},
{0x6200, 0x7a00, 0x9d00},
{0x5700, 0x6c00, 0x4300},
{0x8500, 0x8000, 0xb100},
{0x6700, 0xbd00, 0xaa00},
{0xd600, 0x7e00, 0x2c00},
{0x5000, 0x5b00, 0xa600},
{0xc100, 0x5a00, 0x6300},
{0x5e00, 0x3c00, 0x6c00},
{0x9d00, 0xbc00, 0x4000},
{0xe000, 0xa300, 0x2e00},
{0x3800, 0x3d00, 0x9600},
{0x4600, 0x9400, 0x4900},
{0xaf00, 0x3600, 0x3c00},
{0xe700, 0xc700, 0x1f00},
{0xbb00, 0x5600, 0x9500},
{0x0800, 0x8500, 0xa100},
{0xf300, 0xf300, 0xf200},
{0xc800, 0xc800, 0xc800},
{0xa000, 0xa000, 0xa000},
{0x7a00, 0x7a00, 0x7900},
{0x5500, 0x5500, 0x5500},
{0x3400, 0x3400, 0x3400},
{{{0x7300, 0x5200, 0x4400}}},
{{{0xc200, 0x9600, 0x8200}}},
{{{0x6200, 0x7a00, 0x9d00}}},
{{{0x5700, 0x6c00, 0x4300}}},
{{{0x8500, 0x8000, 0xb100}}},
{{{0x6700, 0xbd00, 0xaa00}}},
{{{0xd600, 0x7e00, 0x2c00}}},
{{{0x5000, 0x5b00, 0xa600}}},
{{{0xc100, 0x5a00, 0x6300}}},
{{{0x5e00, 0x3c00, 0x6c00}}},
{{{0x9d00, 0xbc00, 0x4000}}},
{{{0xe000, 0xa300, 0x2e00}}},
{{{0x3800, 0x3d00, 0x9600}}},
{{{0x4600, 0x9400, 0x4900}}},
{{{0xaf00, 0x3600, 0x3c00}}},
{{{0xe700, 0xc700, 0x1f00}}},
{{{0xbb00, 0x5600, 0x9500}}},
{{{0x0800, 0x8500, 0xa100}}},
{{{0xf300, 0xf300, 0xf200}}},
{{{0xc800, 0xc800, 0xc800}}},
{{{0xa000, 0xa000, 0xa000}}},
{{{0x7a00, 0x7a00, 0x7900}}},
{{{0x5500, 0x5500, 0x5500}}},
{{{0x3400, 0x3400, 0x3400}}},
}};
template <uint32_t X, uint32_t Y>
@@ -103,3 +105,37 @@ std::unique_ptr<Image<X, Y>> HighlightClosest(const Image<X, Y>& image) {
}
return out;
}
template <uint32_t P, uint32_t R, uint32_t G, uint32_t B, uint32_t X, uint32_t Y>
uint32_t OptimizeLut(const Image<X, Y>& image, Lut3d<R, G, B>* lut) {
uint32_t diff = 0;
for (uint32_t r = 0; r < R; ++r) {
auto& rect = lut->at(r);
for (uint32_t g = 0; g < G; ++g) {
auto& row = rect.at(g);
for (uint32_t b = 0; b < B; ++b) {
auto& color = row.at(b);
std::cout << "(" << r << ", " << g << ", " << b << ")" << std::endl;
for (uint32_t c = 0; c < color.size(); ++c) {
auto min = FindPossibleMinimum<uint32_t, uint32_t, 4>(
0, UINT16_MAX,
[&image, &lut, r, g, b, c](uint32_t val) {
auto test_lut = *lut;
test_lut[r][g][b].at(c) = val;
return ScoreImage(*test_lut.MapImage(image));
});
std::cout << "\tC" << c << ": " << color.at(c) << " -> " << min << std::endl;
diff += AbsDiff(color.at(c), min);
color.at(c) = min;
}
}
}
}
return diff;
}