Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added histogram EMD comparison support for image_diff. #693

Merged
merged 1 commit into from
Oct 18, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions samples/image_diff.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@

namespace {

enum class CompareAlgorithm {
kRMSE = 0,
};
enum class CompareAlgorithm { kRMSE = 0, kHISTOGRAM_EMD = 1 };

struct Options {
std::vector<std::string> input_filenames;
Expand All @@ -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 <float> -- Tolerance value for RMSE comparison.
--histogram_emd -- Compare using histogram EMD algorithm.
-t | --tolerance <float> -- Tolerance value for comparison.
-h | --help -- This help text.
)";

Expand All @@ -53,6 +52,8 @@ bool ParseArgs(const std::vector<std::string>& 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()) {
Expand Down Expand Up @@ -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;
Expand Down