From d238bb26937a5f3745e9b5b705e9fa01fbc2e597 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Suonp=C3=A4=C3=A4?= Date: Thu, 17 Oct 2019 10:16:54 +0300 Subject: [PATCH] Added histogram EMD comparison support for image_diff. --- samples/image_diff.cc | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/samples/image_diff.cc b/samples/image_diff.cc index a69f6a9aa..7c8db6994 100644 --- a/samples/image_diff.cc +++ b/samples/image_diff.cc @@ -26,9 +26,7 @@ namespace { -enum class CompareAlgorithm { - kRMSE = 0, -}; +enum class CompareAlgorithm { kRMSE = 0, kHISTOGRAM_EMD = 1 }; struct Options { std::vector input_filenames; @@ -41,7 +39,8 @@ const char kUsage[] = R"(Usage: image_diff [options] image1.png image2.png options: --rmse -- Compare using RMSE algorithm (default). - -t | --tolerance -- Tolerance value for RMSE comparison. + --histogram_emd -- Compare using histogram EMD algorithm. + -t | --tolerance -- Tolerance value for comparison. -h | --help -- This help text. )"; @@ -53,6 +52,8 @@ bool ParseArgs(const std::vector& args, Options* opts) { return true; } else if (arg == "--rmse") { opts->compare_algorithm = CompareAlgorithm::kRMSE; + } else if (arg == "--histogram_emd") { + opts->compare_algorithm = CompareAlgorithm::kHISTOGRAM_EMD; } else if (arg == "-t" || arg == "--tolerance") { ++i; if (i >= args.size()) { @@ -136,6 +137,8 @@ int main(int argc, const char** argv) { amber::Result res; if (options.compare_algorithm == CompareAlgorithm::kRMSE) res = buffers[0].CompareRMSE(&buffers[1], options.tolerance); + else if (options.compare_algorithm == CompareAlgorithm::kHISTOGRAM_EMD) + res = buffers[0].CompareHistogramEMD(&buffers[1], options.tolerance); if (res.IsSuccess()) std::cout << "Images similar" << std::endl;