From 3ff34dbdb0ad6510912fb04f8e4930c559717a30 Mon Sep 17 00:00:00 2001 From: Yongqing Liang Date: Tue, 11 Jun 2019 17:58:36 +0800 Subject: [PATCH] update greedy function --- include/stripes_solver.h | 2 +- src/solver/stripes_solver.cpp | 55 ++--------------------------------- src/utils.cpp | 12 +++----- 3 files changed, 8 insertions(+), 61 deletions(-) diff --git a/include/stripes_solver.h b/include/stripes_solver.h index 68e6398..ccd6ab1 100644 --- a/include/stripes_solver.h +++ b/include/stripes_solver.h @@ -118,7 +118,7 @@ class StripesSolver { // double m_metric_comp_eva(const cv::Mat & piece0, const cv::Mat & piece1); void m_metric_word(); - vector< vector > reassemble_greedy(bool probability_flag=false); + vector< vector > reassemble_greedy(); void reassemble_GCOM(); void compute_mutual_graph(vector< vector > & mutual_graph); diff --git a/src/solver/stripes_solver.cpp b/src/solver/stripes_solver.cpp index c8a57b0..d2ca61f 100644 --- a/src/solver/stripes_solver.cpp +++ b/src/solver/stripes_solver.cpp @@ -603,7 +603,7 @@ void StripesSolver::m_metric() { } -vector< vector > StripesSolver::reassemble_greedy(bool probability_flag) { +vector< vector > StripesSolver::reassemble_greedy() { random_device rand_device; default_random_engine rand_engine(rand_device()); @@ -613,41 +613,14 @@ vector< vector > StripesSolver::reassemble_greedy(bool probability_flag) { vector stripe_right(stripes_n, -1); int merged_cnt = 0; - vector stripe_pairs_rest; - - double thres_score = 0; - if (composition_mode == Composition::GCOM) { - if (metric_mode == Metric::PIXEL || metric_mode == Metric::CHAR) { - thres_score = 0.8 * stripe_pairs.back().m_score; - } -#ifdef DEBUG - cout << "Threshold score: " << thres_score << endl; -#endif - } for (const StripePair & sp: stripe_pairs) { - if (sp.m_score < -eps) continue; - - if (abs(thres_score) > eps) { - if (composition_mode == Composition::GCOM) { - if (metric_mode == Metric::PIXEL || metric_mode == Metric::CHAR) { - if (sp.m_score > thres_score) break; - } - } - } + if (composition_mode == Composition::GREEDY && sp.m_score > 2) continue; if (stripe_right[sp.stripe_idx0] != -1) continue; if (stripe_left[sp.stripe_idx1] != -1) continue; - if (probability_flag) { - double rand_f = uniform_unit_dist(rand_engine); - if (rand_f > sp.ac_prob) { - stripe_pairs_rest.push_back(sp); - continue; - } - } - int left_most = sp.stripe_idx0; while (stripe_left[left_most] != -1) { left_most = stripe_left[left_most]; @@ -663,27 +636,6 @@ vector< vector > StripesSolver::reassemble_greedy(bool probability_flag) { } - if (probability_flag && merged_cnt < stripes_n - 1) { - for (const StripePair & sp: stripe_pairs_rest) { - - if (stripe_right[sp.stripe_idx0] != -1) continue; - if (stripe_left[sp.stripe_idx1] != -1) continue; - - int left_most = sp.stripe_idx0; - while (stripe_left[left_most] != -1) { - left_most = stripe_left[left_most]; - } - - if (left_most == sp.stripe_idx1) continue; - - stripe_right[sp.stripe_idx0] = sp.stripe_idx1; - stripe_left[sp.stripe_idx1] = sp.stripe_idx0; - merged_cnt++; - - if (merged_cnt == stripes_n - 1) break; - } - } - vector< vector > fragments; vector visited(stripes_n, false); @@ -704,7 +656,6 @@ vector< vector > StripesSolver::reassemble_greedy(bool probability_flag) { while (stripe_right[cur_idx] != -1) { cur_idx = stripe_right[cur_idx]; - composition_img = merge_imgs(composition_img, stripes[cur_idx], splice_x0, splice_x1); sol.push_back(cur_idx); visited[cur_idx] = true; } @@ -719,7 +670,7 @@ vector< vector > StripesSolver::reassemble_greedy(bool probability_flag) { void StripesSolver::reassemble_GCOM() { - vector< vector > && fragments = reassemble_greedy(false); + vector< vector > && fragments = reassemble_greedy(); merge_single_sol(fragments); finetune_sols(fragments); diff --git a/src/utils.cpp b/src/utils.cpp index 5f2e5a1..54561d4 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -53,18 +53,14 @@ double m_metric_pixel(const cv::Mat & piece0, const cv::Mat & piece1, bool shift printf("IdxP: %d, metric (%d, %d), avg0: %.3lf, avg1: %.3lf\n", idx, idx / 60, idx % 60, avg_pixel_color0, avg_pixel_color1); #endif - if (abs(check_pure(avg_pixel_color0) + check_pure(avg_pixel_color1)) == 2) { + if (abs(check_pure(avg_pixel_color0) + check_pure(avg_pixel_color1)) >= 1) { return 3; - } - if (abs(check_pure(avg_pixel_color0) + check_pure(avg_pixel_color1)) == 1) { - return 2; - } - + } else { #ifdef DEBUG // cout << "pixel metric: " << m_score << endl; #endif - - return exp(-max(0.0, m_score / 20 - 1.5)); + return exp(-max(0.0, m_score / 20 - 1.5)); + } }