1 #ifndef _GOIR_IMAGEINFO_HH
2 #define _GOIR_IMAGEINFO_HH
4 #include "sImLib/Image.hh"
6 #include "histogram.hh"
20 enum { ALGO_1PIX_PERCOMP
,
22 ALGO_1PIX_COMPSUM_FILTERED
,
23 // ALGO_1PIX_COMBINED,
26 // ALGO_2PIX_COMBINED,
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
)
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
);
70 ImageInfo
* ii
; // line lives in this image
71 bool _edges_are_known
;
74 unsigned x0
, y0
, x1
, y1
;
76 std::vector
<AlgoResults
> results
;
78 LineData(ImageInfo
* _ii
, unsigned _x0
, unsigned _y0
, unsigned _x1
, unsigned _y1
)
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
;
100 ii
->add_to_histo(x0
, y0
, x1
, y1
, &known_edges
);
104 void fprint(FILE* outf
);
107 void maybe_update_watermarks(int algo_id
, unsigned x
,
108 bool is_edge
, unsigned value
);
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
;
119 std::vector
<LineData
*> lines
;
120 enum { NONEDGES
, EDGES
};
122 ImageInfo(const sImLib::Image
* const _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
)
147 void fprint(FILE* outf
) const {
148 fprintf(outf
, "# GoIR data\n");
149 const_foreach(i
, lines
)
154 void add_to_histo(unsigned x0
, unsigned y0
, unsigned x1
, unsigned y1
,
155 UVector
*known_edges
= NULL
);
160 #endif // _GOIR_IMAGEINFO_HH