forked from JeffOwOSun/gpu-bm3d
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdenoise.cpp
More file actions
123 lines (107 loc) · 3.16 KB
/
denoise.cpp
File metadata and controls
123 lines (107 loc) · 3.16 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
#include <stdlib.h>
#include <stdio.h>
#include <string>
#include "bm3d.h"
#define cimg_display 1
#define cimg_use_png
#include "Cimg.h"
#include <getopt.h>
#include <vector_types.h>
#include <vector_functions.h>
using namespace cimg_library;
using namespace std;
void usage(const char* progname) {
printf("Usage: %s [options] InputFile OutputFile\n", progname);
printf("Program Options:\n");
printf(" -s --sigma <INT> Noisy level\n");
printf(" -c --color Color Image\n");
printf(" -t --step <INT> Perform which step of denoise, 1: first step, 2: both step\n");
printf(" -v --verbose Print addtional infomation\n");
printf(" -? --help This message\n");
}
int main(int argc, char** argv)
{
int opt;
int channels = 1;
int step = 2;
int verbose = 0;
int sigma = 0;
string input_file, output_file;
while ((opt = getopt(argc, argv, "s:ct:v?")) != EOF) {
switch (opt) {
case 's':
sigma = atoi(optarg);
break;
case 'c':
// color image
channels = 3;
break;
case 't':
step = atoi(optarg);
break;
case 'v':
verbose = 1;
break;
case '?':
default:
usage(argv[0]);
return 1;
}
}
if (optind + 2 > argc) {
fprintf(stderr, "Error: missing File name\n");
usage(argv[0]);
return 1;
}
input_file = argv[optind];
output_file = argv[optind+1];
if (verbose) {
printf("Sigma: %d\n", sigma);
if (channels == 1) {
printf("Image: Grayscale\n");
} else {
printf("Image: Color\n");
}
printf("Steps: %d\n", step);
}
//Allocate images
CImg<unsigned char> image(input_file.c_str());
CImg<unsigned char> image2(image.width(), image.height(), 1, channels, 0);
// //Convert color image to YCbCr color space
// if (channels == 3)
// image = image.get_channels(0,2).RGBtoYCbCr();
// Check for invalid input
if(! image.data() )
{
fprintf(stderr, "Error: Could not open file\n");
return 1;
}
printf("Width: %d, Height: %d\n", image.width(), image.height());
// Launch BM3D
Bm3d bm3d;
bm3d.set_up_realtime(image.width(), image.height(), channels);
for (int i=0;i<0;i++) {
bm3d.realtime_denoise(image.data(), image2.data());
// bm3d.denoise(image.data(),
// image2.data(),
// image.width(),
// image.height(),
// sigma,
// channels,
// step,
// verbose);
image2 = image2.get_channel(0);
image2.save(output_file.c_str());
}
// testing block_matching
// bm3d.test_block_matching(image.data(), image.width(), image.height());
// image.save("test_block_matching.png");
// bm3d.test_aggregation(
// image.data(),
// image.width(),
// image.height(),
// image2.data()
// );
// image2.save("test_aggregation.png");
return 0;
}