-
Notifications
You must be signed in to change notification settings - Fork 3
/
image.h
125 lines (98 loc) · 2.4 KB
/
image.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
/**
*@author Wan-Lei Zhao
*@version 1.30
*All rights reserved by Wanlei Zhao
*
**/
#ifndef IMAGE_H
#define IMAGE_H
#include "abstractimage.h"
#include <vector>
using namespace std;
class Image: public AbstractImage
{
public:
Image(const int width, const int height);
Image(const int width, const int height, const float *new_data);
Image(const char *srcFn, const float norm);
Image(const char *srcFn);
virtual ~Image(){}
/**
*
*pix = pix * val;
* val multiply with each pixel in that image
*/
void multiply(const float val);
/**
*
*make each pixel exponentialized with a cerntain value
*pix = pix^val
*/
void exp(const int val);
inline void setPixel(const int x, const int y, const float val)
{
if(y >= this->height || y < 0)
return ;
if(x < 0||x >= this->width)
return ;
pix[y*width+x] = val;
}
inline void setPixel(const int x, const int y, const float *gray)
{
assert(gray);
if(y >= this->height||y < 0)
return ;
if(x < 0|| x >= this->width)
return ;
pix[y*width+x] = *gray;
}
inline float getPixel(const int x, const int y) const
{
if(y>=this->height||y<0)
{
return 0;
}
if(x<0||x>=this->width)
{
return 0;
}
return pix[y*width+x];
}
inline void getPixel(const int x, const int y, float *val)
{
if(y>=this->height||y<0)
{
*val = 0;
return ;
}
if(x<0||x>=this->width)
{
*val = 0;
return ;
}
*val = pix[y*width+x];
}
/**/
/**
*get halfsized image of the original image
*/
static Image * halfSizeImage(Image *im);
/**
* get double sized image of the orignial image
*/
static Image *doubleSizeImage(Image *srcImg);
/**
* Clones a copy of the image.
* @return Cloned copy.
*/
Image * clone();
/**
*substract image with im2 and store it to 'dst' image
**/
void sub(Image * im2, Image * dst);
float getConValWidth(const int x, const int y, vector<float> &dkern);
float getConValHeight(const int x, const int y, vector<float> &dkern);
Image *getPatch(const int x, const int y, const int win, float *umatrix);
static void test();
};
#endif