Skip to content

Commit

Permalink
update greedy function
Browse files Browse the repository at this point in the history
  • Loading branch information
xmlyqing00 committed Jun 11, 2019
1 parent 59b768b commit 3ff34db
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 61 deletions.
2 changes: 1 addition & 1 deletion include/stripes_solver.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> > reassemble_greedy(bool probability_flag=false);
vector< vector<int> > reassemble_greedy();
void reassemble_GCOM();

void compute_mutual_graph(vector< vector<double> > & mutual_graph);
Expand Down
55 changes: 3 additions & 52 deletions src/solver/stripes_solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ void StripesSolver::m_metric() {

}

vector< vector<int> > StripesSolver::reassemble_greedy(bool probability_flag) {
vector< vector<int> > StripesSolver::reassemble_greedy() {

random_device rand_device;
default_random_engine rand_engine(rand_device());
Expand All @@ -613,41 +613,14 @@ vector< vector<int> > StripesSolver::reassemble_greedy(bool probability_flag) {
vector<int> stripe_right(stripes_n, -1);

int merged_cnt = 0;
vector<StripePair> 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];
Expand All @@ -663,27 +636,6 @@ vector< vector<int> > 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<int> > fragments;
vector<bool> visited(stripes_n, false);

Expand All @@ -704,7 +656,6 @@ vector< vector<int> > 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;
}
Expand All @@ -719,7 +670,7 @@ vector< vector<int> > StripesSolver::reassemble_greedy(bool probability_flag) {

void StripesSolver::reassemble_GCOM() {

vector< vector<int> > && fragments = reassemble_greedy(false);
vector< vector<int> > && fragments = reassemble_greedy();

merge_single_sol(fragments);
finetune_sols(fragments);
Expand Down
12 changes: 4 additions & 8 deletions src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

}

Expand Down

0 comments on commit 3ff34db

Please sign in to comment.