Merge evaluate() functionnality into find_edges(), get delta for missed edges.
[goir.git] / ImageInfo.hh
blob7f56cecb51b3ad8000fc49f9a7dfa49cd9b412da
1 #ifndef _GOIR_IMAGEINFO_HH
2 #define _GOIR_IMAGEINFO_HH
4 #include "sImLib/Image.hh"
6 #include "histogram.hh"
7 #include "util.hh"
8 #include "uvector.hh"
10 #include <cstdio>
11 #include <vector>
13 namespace goir {
15 class ImageInfo {
17 class LineData;
19 public:
20 enum { ALGO_1PIX_PERCOMP,
21 ALGO_1PIX_COMPSUM,
22 ALGO_1PIX_COMPSUM_FILTERED,
23 // ALGO_1PIX_COMBINED,
24 ALGO_2PIX_PERCOMP,
25 ALGO_2PIX_COMPSUM,
26 // ALGO_2PIX_COMBINED,
28 NB_ALGOS
31 private:
33 class AlgoResults {
34 public:
35 struct MatchData {
36 unsigned x,y;
37 unsigned delta;
38 bool false_match;
40 MatchData(unsigned _x, unsigned _y, unsigned _delta, bool _is_known = true)
41 : x(_x), y(_y), delta(_delta), false_match(!_is_known) {};
42 MatchData(const std::pair<unsigned,unsigned> p)
43 : x(p.first), y(p.second), delta(0), false_match(false) {};
46 // results of algorithm
47 std::vector<MatchData> found_edges;
49 /*** everything below is for analysis only ***/
51 const LineData* linedata;
53 // watermarks for calibration
54 unsigned min_positive, max_negative;
56 std::vector<MatchData> missed;
58 AlgoResults(unsigned maxvalue, const LineData* _linedata)
59 : linedata(_linedata)
60 , min_positive(maxvalue), max_negative(0)
63 void update_watermarks(bool is_edge, unsigned value);
64 void fprint(FILE* outf);
65 void draw_on(sImLib::Image & img);
68 class LineData {
69 private:
70 ImageInfo* ii; // line lives in this image
71 bool _edges_are_known;
73 public:
74 unsigned x0, y0, x1, y1;
75 UVector known_edges;
76 std::vector<AlgoResults> results;
78 LineData(ImageInfo* _ii, unsigned _x0, unsigned _y0, unsigned _x1, unsigned _y1)
79 : ii(_ii)
80 , _edges_are_known(false)
81 , x0(_x0), y0(_y0), x1(_x1), y1(_y1)
83 // FIXME: I hate that way of initializing a vector...
84 results.push_back(AlgoResults(255, this)); // 1PIX_PERCOMP
85 results.push_back(AlgoResults(3*255, this)); // 1PIX_COMPSUM
86 results.push_back(AlgoResults(3*255, this)); // 1PIX_COMPSUM_FILTER
87 results.push_back(AlgoResults(255, this)); // 2PIX_PERCOMP
88 results.push_back(AlgoResults(3*255, this)); // 2PIX_COMPSUM
89 assert(NB_ALGOS == 5);
92 // Read a list of unsigned values as coords of edges along the line
93 void read_edges(FILE* f);
95 bool edges_are_known() const {
96 return _edges_are_known;
99 void add_to_histo() {
100 ii->add_to_histo(x0, y0, x1, y1, &known_edges);
103 void find_edges();
104 void fprint(FILE* outf);
106 private:
107 void maybe_update_watermarks(int algo_id, unsigned x,
108 bool is_edge, unsigned value);
111 private:
112 const sImLib::Image * const imgp;
114 std::vector<Histogram> histos;
115 std::vector< std::vector<Histogram> > histos_c;
116 std::vector<Histogram> histos_allc;
118 public:
119 std::vector<LineData*> lines;
120 enum { NONEDGES, EDGES };
122 ImageInfo(const sImLib::Image* const _imgp)
123 : imgp(_imgp)
124 , histos(2, Histogram(3*256, 3*256))
125 , histos_c (2, std::vector<Histogram>(3, Histogram(256,256)))
126 , histos_allc(2, Histogram(256, 256))
129 void maybe_read_edge_data();
131 void add_line(unsigned x0, unsigned y0, unsigned x1, unsigned y1) {
132 lines.push_back(new LineData(this, x0, y0, x1, y1));
135 void collect_histo_from_lines() {
136 const_foreach(i, lines)
137 (*i)->add_to_histo();
140 void display_histo();
142 void look_for_edges() const {
143 const_foreach(i, lines)
144 (*i)->find_edges();
147 void fprint(FILE* outf) const {
148 fprintf(outf, "# GoIR data\n");
149 const_foreach(i, lines)
150 (*i)->fprint(outf);
153 private:
154 void add_to_histo(unsigned x0, unsigned y0, unsigned x1, unsigned y1,
155 UVector *known_edges = NULL);
160 #endif // _GOIR_IMAGEINFO_HH