-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecompose.cpp
59 lines (49 loc) · 1.67 KB
/
recompose.cpp
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
#include <string>
#include <iostream>
#include "multiscaler.hpp"
using namespace multiscaler;
using std::string;
using std::to_string;
using std::cerr;
using std::endl;
int main(int argc, char *argv[]) {
float recompose_factor = atof(pick_option(&argc, argv, "c", ".8"));
bool usage = pick_option(&argc, argv, "h", nullptr);
if ((argc != 5) || usage) {
cerr << "Usage: " << argv[0] << " prefix levels suffix output [-c factor]" << endl;
exit(EXIT_FAILURE);
}
string input_prefix = argv[1];
int levels = atoi(argv[2]);
string input_suffix = argv[3];
string output_name = argv[4];
// Use the bigger image to determine width, height and number of channels
Image output = read_image(input_prefix + "0" + input_suffix);
// Perform the DCT
dct_inplace(output);
for (int i = 1; i < levels; ++i) {
// Read level i of the pyramid
Image image = read_image(input_prefix + to_string(i) + input_suffix);
// Perform the DCT
dct_inplace(image);
#ifdef ISOMETRIC_DCT
//> isometric normalization DCT scaling (not active in dct_inplace)
const double scaling = std::sqrt((double)(output.rows()*output.columns())/((double)(image.rows()*image.columns())));
#else
const double scaling = 1.0;
#endif
// Copy data (selected by recompose_factor)
for (int j = 0; j < image.rows() * recompose_factor; ++j) {
for (int k = 0; k < image.columns() * recompose_factor; ++k) {
for (int l = 0; l < image.channels(); ++l) {
output.val(k, j, l) = image.val(k, j, l) * scaling;
}
}
}
}
// IDCT of the output image
idct_inplace(output);
// Save the output image
save_image(output, output_name);
return EXIT_SUCCESS;
}