Skip to content

Commit

Permalink
Update Line class.
Browse files Browse the repository at this point in the history
  • Loading branch information
Samir55 committed Dec 2, 2017
1 parent 7fd6173 commit 4d819b6
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 9 deletions.
55 changes: 53 additions & 2 deletions src/LineSegmentation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,11 +455,62 @@ Chunk::find_peaks_valleys() {
return int(ceil(avg_height));
}

Line::Line(int idx, int initial_valley_id) : start_row_position(-1), height(0), points(vector<Point>()) {
this->index = idx;
Line::Line(int initial_valley_id) : min_row_position(0), max_row_position(0), points(vector<Point>()) {
valleys_ids.push_back(initial_valley_id);
}

void
Line::generate_initial_points(int chunk_width, int img_width, map<int, Valley *> map_valley) {
int c = 0, previous_row = 0;

// Sort the valleys according to their chunk number.
sort(valleys_ids.begin(), valleys_ids.end());

// Add line points in the first chunks having no valleys.
if (map_valley[valleys_ids.front()]->chunk_index > 0) {
previous_row = map_valley[valleys_ids.front()]->position;
max_row_position = min_row_position = previous_row;
for (int j = 0; j < map_valley[valleys_ids.front()]->chunk_index * chunk_width; j++) {
if (c++ == j)
points.push_back(Point(previous_row, j));
}
}

// Add line points between the valleys.
for (auto id : valleys_ids) {
int chunk_index = map_valley[id]->chunk_index;
int chunk_row = map_valley[id]->position;
int chunk_start_column = chunk_index * chunk_width;

for (int j = chunk_start_column; j < chunk_start_column + chunk_width; j++) {
min_row_position = min(min_row_position, chunk_row);
max_row_position = max(max_row_position, chunk_row);
if (c++ == j)
points.push_back(Point(chunk_row, j));
}
if (previous_row != chunk_row) {
previous_row = chunk_row;
min_row_position = min(min_row_position, chunk_row);
max_row_position = max(max_row_position, chunk_row);
}
}

// Add line points in the last chunks having no valleys.
if (CHUNKS_NUMBER - 1 > map_valley[valleys_ids.back()]->chunk_index) {
int chunk_index = map_valley[valleys_ids.back()]->chunk_index,
chunk_row = map_valley[valleys_ids.back()]->position;
for (int j = chunk_index * chunk_width + chunk_width; j < img_width; j++) {
if (c++ == j)
points.push_back(Point(chunk_row, j));
}
}
}

bool
Line::comp_min_row_position(const Line *a, const Line *b) {
return a->min_row_position < b->min_row_position;
}

bool
Peak::operator<(const Peak &p) const {
return value > p.value;
Expand Down
24 changes: 17 additions & 7 deletions src/LineSegmentation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,31 @@ class LineSegmentation;
struct Line {
friend class LineSegmentation;

friend class Region;

private:
int index;
///< Index of the line in the vector.
Region *above;
///< Region above the line.
Region *below;
///< Region below the line.
vector<valley_id> valleys_ids;
///< The ids of the valleys.
int start_row_position;
int min_row_position;
///< The row at which the region starts.
int end_row_position;
int max_row_position;
///< The row at which the region ends.
int height;
///< The height of the line region above this line separator.
vector<Point> points;
///< The points representing the line.

Line(int idx, int initial_valley_id);
Line(int initial_valley_id);

/// Generate the initial line points.
void
generate_initial_points(int chunk_width, int img_width, map<int, Valley *> map_valley);

/// Sort accendingly according to the min row position.
static bool
comp_min_row_position(const Line *a, const Line *b);
};

/// A class representing the peaks (local maximum points in the histogram).
Expand Down

0 comments on commit 4d819b6

Please sign in to comment.