-
Notifications
You must be signed in to change notification settings - Fork 24
/
utilities.h
134 lines (115 loc) · 2.71 KB
/
utilities.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
#ifndef UTILITIES_H_INCLUDED
#define UTILITIES_H_INCLUDED
#include <vector>
#include <fftw3.h>
//! Read image and check number of channels
int load_image(
char* name
, std::vector<float> &img
, unsigned * width
, unsigned * height
, unsigned * chnls
);
//! Write image
int save_image(
char* name
, std::vector<float> &img
, const unsigned width
, const unsigned height
, const unsigned chnls
);
//! Check if a number is a power of 2
bool power_of_2(
const unsigned n
);
//! Add boundaries by symetry
void symetrize(
const std::vector<float> &img
, std::vector<float> &img_sym
, const unsigned width
, const unsigned height
, const unsigned chnls
, const unsigned N
);
//! Subdivide an image into small sub-images
void sub_divide(
std::vector<float> &img
, std::vector<std::vector<float> > &sub_img
, std::vector<unsigned> &w_table
, std::vector<unsigned> &h_table
, const unsigned width
, const unsigned height
, const unsigned chnls
, const unsigned N
, bool divide
);
//! Compute the PSNR and RMSE between img_1 and img_2
int compute_psnr(
const std::vector<float> &img_1
, const std::vector<float> &img_2
, float *psnr
, float *rmse
);
//! Compute the difference images between img_1 and img_2
int compute_diff(
const std::vector<float> &img_1
, const std::vector<float> &img_2
, std::vector<float> &img_diff
, const float sigma
);
//! Transform the color space of the image
int color_space_transform(
std::vector<float> &img
, const unsigned color_space
, const unsigned width
, const unsigned height
, const unsigned chnls
, const bool rgb2yuv
);
//! Look for the closest power of 2 number
int closest_power_of_2(
const unsigned n
);
//! Estimate sigma on each channel according to the choice of the color_space
int estimate_sigma(
const float sigma
, std::vector<float> &sigma_table
, const unsigned chnls
, const unsigned color_space
);
//! Initialize a set of indices
void ind_initialize(
std::vector<unsigned> &ind_set
, const unsigned max_size
, const unsigned N
, const unsigned step
);
//! For convenience
unsigned ind_size(
const unsigned max_size
, const unsigned N
, const unsigned step
);
//! Initialize a 2D fftwf_plan with some parameters
void allocate_plan_2d(
fftwf_plan* plan
, const unsigned N
, const fftwf_r2r_kind kind
, const unsigned nb
);
//! Initialize a 1D fftwf_plan with some parameters
void allocate_plan_1d(
fftwf_plan* plan
, const unsigned N
, const fftwf_r2r_kind kind
, const unsigned nb
);
//! Tabulated values of log2(2^n)
unsigned ind_log2(
const unsigned N
);
//! Tabulated values of 2^N
unsigned ind_pow2(
const unsigned N
);
#endif // UTILITIES_H_INCLUDED