-
Notifications
You must be signed in to change notification settings - Fork 8
/
image_utility.h
93 lines (78 loc) · 2.14 KB
/
image_utility.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#ifndef IMAGE_UTILITY_H
#define IMAGE_UTILITY_H
#include <list>
namespace sift {
/**********************************************
******** 对象定义 ***********
***********************************************/
struct SiftKeypoint;
struct MatchPair;
template <typename T>
class Image;
struct ImagePPM {
int w;
int h;
unsigned char *img_r;
unsigned char *img_g;
unsigned char *img_b;
};
/**********************************************
******** 可视化函数 ***********
***********************************************/
// SIFT关键点可视化
void draw_keypoints_to_ppm_file(const char *out_filename, const Image<unsigned char> &image, std::list<SiftKeypoint> kpt_list);
// 可视化SIFT关键点匹配对
int draw_match_lines_to_ppm_file(const char *filename, Image<unsigned char> &image1, Image<unsigned char> &image2, std::list<MatchPair> &match_list);
/**********************************************
******** 图像基础函数 ***********
***********************************************/
// 获取像素值(unsigned char)
inline unsigned char get_pixel(unsigned char *imageData, int w, int h, int r, int c)
{
unsigned char val;
if (c >= 0 && c < w && r >= 0 && r < h) {
val = imageData[r * w + c];
}
else if (c < 0) {
val = imageData[r * w];
}
else if (c >= w) {
val = imageData[r * w + w - 1];
}
else if (r < 0) {
val = imageData[c];
}
else if (r >= h) {
val = imageData[(h - 1) * w + c];
}
else {
val = 0;
}
return val;
}
// 获取像素值(float)
inline float get_pixel_f(float *imageData, int w, int h, int r, int c)
{
float val;
if (c >= 0 && c < w && r >= 0 && r < h) {
val = imageData[r * w + c];
}
else if (c < 0) {
val = imageData[r * w];
}
else if (c >= w) {
val = imageData[r * w + w - 1];
}
else if (r < 0) {
val = imageData[c];
}
else if (r >= h) {
val = imageData[(h - 1) * w + c];
}
else {
val = 0.0f;
}
return val;
}
} // end namespace sift
#endif // IMAGE_UTILITY_H