-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathR2Image.h
executable file
·206 lines (153 loc) · 4.04 KB
/
R2Image.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
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
// Include file for image class
#ifndef R2_IMAGE_INCLUDED
#define R2_IMAGE_INCLUDED
// 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);
// 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 Translate(double dx, double dy);
void Crop(int lx, int rx, int ty, int by);
// show how SVD works
void svdTest();
// Linear filtering operations
void SobelX();
void SobelY();
void LoG();
void Blur(double sigma);
void Harris(double sigma);
void Sharpen(void);
//non-linear filtering
void MedianFilter();
void BilateralFilter();
void featureDetect(double feature[5][300],int fsize);
// further operations
void Ransac(R2Image * otherImage);
void RansacP(R2Image * otherImage, double feature[5][300], int fsize);
void PMatrix(R2Image * otherImage, double result[3][3],double feature[5][300], int fsize);
void RansacT(R2Image * otherImage, double result[2]);
void blendOtherImageTranslated(R2Image * otherImage);
void blendOtherImageHomography(R2Image * otherImage);
void warp(R2Image * otherImage, double H[3][3]);
// 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);
void line(int x0,int x1,int y0, int y1,float r,float g,float b);
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