-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathskeletonizer.h
71 lines (60 loc) · 2.65 KB
/
skeletonizer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
* Vectorix -- line-based image vectorizer
* (c) 2016 Jan Hadrava <[email protected]>
*/
#ifndef VECTORIX__SKELETONIZER_H
#define VECTORIX__SKELETONIZER_H
#include <opencv2/opencv.hpp>
#include "parameters.h"
#include "logger.h"
namespace vectorix {
class skeletonizer {
public:
skeletonizer(parameters ¶ms): par(¶ms) {
int *param_vectorizer_verbosity;
par->bind_param(param_vectorizer_verbosity, "vectorizer_verbosity", (int) log_level::warning);
log.set_verbosity((log_level) *param_vectorizer_verbosity);
par->add_comment("Phase 2: Skeletonization");
par->add_comment("Skeletonization type: 0: diamond-square, 1: square, 2: diamond, 3: circle (slow), 4: zhang-suen + diamod-square");
par->bind_param(param_skeletonization_type, "skeletonization_type", 4);
par->add_comment("Save steps to files, # will be replaced with iteration number");
par->bind_param(param_save_peeled_name, "files_steps_output", (std::string) "");
par->add_comment("Save skeleton/distance with/without normalization");
par->bind_param(param_save_skeleton_name, "file_skeleton", (std::string) "");
par->bind_param(param_save_distance_name, "file_distance", (std::string) "");
par->bind_param(param_save_skeleton_normalized_name, "file_skeleton_norm", (std::string) "");
par->bind_param(param_save_distance_normalized_name, "file_distance_norm", (std::string) "");
}
void run(const cv::Mat &binary_input, cv::Mat &skeleton, cv::Mat &distance);
void interactive(cv::TrackbarCallback onChange = 0, void *userdata = 0);
private:
// Add pixels from `bw' to `out'. Something like image `or', but with more information
template <typename T>
void add_to_skeleton(cv::Mat &out, const cv::Mat &bw, int iteration) {
for (int i = 0; i < out.rows; i++) {
for (int j = 0; j < out.cols; j++) {
if (!out.at<T>(i, j)) { // Non-zero pixel
out.at<T>(i, j) = (!!bw.at<uint8_t>(i, j)) * iteration;
}
}
}
}
void normalize(const cv::Mat &in, cv::Mat &out, int max);
void skeletonize_circle(const cv::Mat &input, cv::Mat &skeleton, cv::Mat &distance);
void skeletonize_diamond_square(const cv::Mat &input, cv::Mat &skeleton, cv::Mat &distance);
int sum_8_connected(const cv::Mat &img, cv::Point p);
int sum_4_connected(const cv::Mat &img, cv::Point p);
int *param_skeletonization_type;
std::string *param_save_peeled_name;
std::string *param_save_skeleton_name;
std::string *param_save_distance_name;
std::string *param_save_skeleton_normalized_name;
std::string *param_save_distance_normalized_name;
logger log;
parameters *par;
cv::Mat skeleton;
cv::Mat distance;
int iteration; // Count of iterations in skeletonization step
};
}; // namespace
#endif