-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathR2Image.h
More file actions
executable file
·207 lines (153 loc) · 4.22 KB
/
Copy pathR2Image.h
File metadata and controls
executable file
·207 lines (153 loc) · 4.22 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
// Include file for image class
#ifndef R2_IMAGE_INCLUDED
#define R2_IMAGE_INCLUDED
#include <vector>
// Constant definitions
typedef enum {
R2_IMAGE_RED_CHANNEL,
R2_IMAGE_GREEN_CHANNEL,
R2_IMAGE_BLUE_CHANNEL,
R2_IMAGE_ALPHA_CHANNEL,
R2_IMAGE_NUM_CHANNELS
} R2ImageChannel;
typedef enum {
R2_IMAGE_POINT_SAMPLING,
R2_IMAGE_BILINEAR_SAMPLING,
R2_IMAGE_GAUSSIAN_SAMPLING,
R2_IMAGE_NUM_SAMPLING_METHODS
} R2ImageSamplingMethod;
typedef enum {
R2_IMAGE_OVER_COMPOSITION,
R2_IMAGE_IN_COMPOSITION,
R2_IMAGE_OUT_COMPOSITION,
R2_IMAGE_ATOP_COMPOSITION,
R2_IMAGE_XOR_COMPOSITION,
} R2ImageCompositeOperation;
// Class definition
class R2Image {
public:
// Constructors/destructor
R2Image(void);
R2Image(const char *filename);
R2Image(int width, int height);
R2Image(int width, int height, const R2Pixel *pixels);
R2Image(const R2Image& image);
~R2Image(void);
void Feature(double sigma, int* prevPointList, int nselected);
void SelectPoints(int* pm, int* out, int n);
void QuickSort(int* pm, int lo, int hi);
int Partition(int* pm, int lo, int hi);
// Image properties
int NPixels(void) const;
int Width(void) const;
int Height(void) const;
// Pixel access/update
R2Pixel& Pixel(int x, int y);
R2Pixel *Pixels(void);
R2Pixel *Pixels(int row);
R2Pixel *operator[](int row);
const R2Pixel *operator[](int row) const;
void SetPixel(int x, int y, const R2Pixel& pixel);
// Image processing
R2Image& operator=(const R2Image& image);
// Per-pixel operations
void Brighten(double factor);
void ChangeSaturation(double factor);
void BinaryThreshold();
// show how SVD works
void svdTest();
double* constructHomographyMat(double** A, double** AMatch, double** M, double** nullspaceMatrix);
// Linear filtering operations
void SobelX();
void SobelY();
void LoG();
void Blur(double sigma);
static void BlurXThread(R2Image* input, R2Image* output, double* kern, int size, int startRow, int endRow);
static void BlurYThread(R2Image* input, R2Image* output, double* kern, int size, int startCol, int endCol);
void Harris(double sigma);
void Sharpen(void);
void SkyReplace(std::vector<R2Image*>* imageList);
double* TrackPoints(int* points, int size, R2Image* otherImage, int* outPoints);
double* HomogRANSAC(int* selectedPoints, int* foundPoints, int NSELECTED);
// further operations
void blendOtherImageTranslated(R2Image * otherImage);
void blendOtherImageHomography(R2Image * otherImage);
// File reading/writing
int Read(const char *filename);
int ReadBMP(const char *filename);
int ReadPPM(const char *filename);
int ReadJPEG(const char *filename);
int Write(const char *filename) const;
int WriteBMP(const char *filename) const;
int WritePPM(const char *filename, int ascii = 0) const;
int WriteJPEG(const char *filename) const;
private:
// Utility functions
void Resize(int width, int height);
R2Pixel Sample(double u, double v, int sampling_method);
private:
R2Pixel *pixels;
int npixels;
int width;
int height;
};
// Inline functions
inline int R2Image::
NPixels(void) const
{
// Return total number of pixels
return npixels;
}
inline int R2Image::
Width(void) const
{
// Return width
return width;
}
inline int R2Image::
Height(void) const
{
// Return height
return height;
}
inline R2Pixel& R2Image::
Pixel(int x, int y)
{
// Return pixel value at (x,y)
// (pixels start at lower-left and go in row-major order)
return pixels[x*height + y];
}
inline R2Pixel *R2Image::
Pixels(void)
{
// Return pointer to pixels for whole image
// (pixels start at lower-left and go in row-major order)
return pixels;
}
inline R2Pixel *R2Image::
Pixels(int x)
{
// Return pixels pointer for row at x
// (pixels start at lower-left and go in row-major order)
return &pixels[x*height];
}
inline R2Pixel *R2Image::
operator[](int x)
{
// Return pixels pointer for row at x
return Pixels(x);
}
inline const R2Pixel *R2Image::
operator[](int x) const
{
// Return pixels pointer for row at x
// (pixels start at lower-left and go in row-major order)
return &pixels[x*height];
}
inline void R2Image::
SetPixel(int x, int y, const R2Pixel& pixel)
{
// Set pixel
pixels[x*height + y] = pixel;
}
#endif