Skip to content

Commit 7b6cbcd

Browse files
committed
Merge pull request #26 from Kalpanika/feature/verbosity
Feature/verbosity
2 parents 06b9aac + 2a71f76 commit 7b6cbcd

15 files changed

+350
-283
lines changed

src/makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,13 @@ else
9494

9595
-include $(BINDIR)/*.d
9696

97-
$(BINDIR)/x3f_extract$(EXE): $(addprefix $(BINDIR)/,x3f_extract.o x3f_io.o x3f_process.o x3f_meta.o x3f_image.o x3f_spatial_gain.o x3f_output_dng.o x3f_output_tiff.o x3f_output_ppm.o x3f_histogram.o x3f_print.o x3f_dump.o x3f_matrix.o x3f_dngtags.o x3f_denoise_utils.o x3f_denoise_aniso.o x3f_denoise.o $(AUXOBJS)) $(OCV_LIBS) $(TIFF_LIBS)
97+
$(BINDIR)/x3f_extract$(EXE): $(addprefix $(BINDIR)/,x3f_extract.o x3f_io.o x3f_process.o x3f_meta.o x3f_image.o x3f_spatial_gain.o x3f_output_dng.o x3f_output_tiff.o x3f_output_ppm.o x3f_histogram.o x3f_print.o x3f_dump.o x3f_matrix.o x3f_dngtags.o x3f_denoise_utils.o x3f_denoise_aniso.o x3f_denoise.o x3f_printf.o $(AUXOBJS)) $(OCV_LIBS) $(TIFF_LIBS)
9898
$(CXX) $^ -o $@ $(LDFLAGS) -lm
9999

100-
$(BINDIR)/x3f_io_test$(EXE): $(addprefix $(BINDIR)/,x3f_io_test.o x3f_io.o x3f_print.o $(AUXOBJS))
100+
$(BINDIR)/x3f_io_test$(EXE): $(addprefix $(BINDIR)/,x3f_io_test.o x3f_io.o x3f_print.o x3f_printf.o $(AUXOBJS))
101101
$(CC) $^ -o $@ $(LDFLAGS)
102102

103-
$(BINDIR)/x3f_matrix_test$(EXE): $(addprefix $(BINDIR)/,x3f_matrix_test.o x3f_matrix.o $(AUXOBJS))
103+
$(BINDIR)/x3f_matrix_test$(EXE): $(addprefix $(BINDIR)/,x3f_matrix_test.o x3f_matrix.o x3f_printf.o $(AUXOBJS))
104104
$(CC) $^ -o $@ $(LDFLAGS) -lm
105105

106106
$(BINDIR)/%.o: %.c | $(BINDIR)

src/x3f_denoise.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "x3f_denoise_utils.h"
1010
#include "x3f_denoise.h"
1111
#include "x3f_io.h"
12+
#include "x3f_printf.h"
1213

1314
using namespace cv;
1415

@@ -17,27 +18,27 @@ static void denoise_nlm(Mat& img, float h)
1718
UMat out, sub, sub_dn, sub_res, res;
1819
float h1[3] = {0.0, h, h}, h2[3] = {0.0, h/8, h/4};
1920

20-
std::cout << "BEGIN denoising\n";
21+
x3f_printf(DEBUG, "BEGIN denoising\n");
2122
fastNlMeansDenoising(img, out, std::vector<float>(h1, h1+3),
2223
3, 11, NORM_L1);
23-
std::cout << "END denoising\n";
24+
x3f_printf(DEBUG, "END denoising\n");
2425

25-
std::cout << "BEGIN V median filtering\n";
26+
x3f_printf(DEBUG, "BEGIN V median filtering\n");
2627
UMat V(out.size(), CV_16U);
2728
int get_V[2] = { 2,0 }, set_V[2] = { 0,2 };
2829
mixChannels(std::vector<UMat>(1, out), std::vector<UMat>(2, V), get_V, 1);
2930
medianBlur(V, V, 3);
3031
mixChannels(std::vector<UMat>(1, V), std::vector<UMat>(2, out), set_V, 1);
31-
std::cout << "END V median filtering\n";
32+
x3f_printf(DEBUG, "END V median filtering\n");
3233

33-
std::cout << "BEGIN low-frequency denoising\n";
34+
x3f_printf(DEBUG, "BEGIN low-frequency denoising\n");
3435
resize(out, sub, Size(), 1.0/4, 1.0/4, INTER_AREA);
3536
fastNlMeansDenoising(sub, sub_dn, std::vector<float>(h2, h2+3),
3637
3, 21, NORM_L1);
3738
subtract(sub, sub_dn, sub_res, noArray(), CV_16S);
3839
resize(sub_res, res, out.size(), 0.0, 0.0, INTER_CUBIC);
3940
subtract(out, res, out, noArray(), CV_16U);
40-
std::cout << "END low-frequency denoising\n";
41+
x3f_printf(DEBUG, "END low-frequency denoising\n");
4142

4243
out.copyTo(img);
4344
}
@@ -99,10 +100,10 @@ void x3f_expand_quattro(x3f_area16_t *image, x3f_area16_t *active,
99100
UMat out;
100101
float h[3] = {0.0, d->h, d->h*2};
101102

102-
std::cout << "BEGIN Quattro full-resolution denoising\n";
103+
x3f_printf(DEBUG, "BEGIN Quattro full-resolution denoising\n");
103104
fastNlMeansDenoising(act_exp, out, std::vector<float>(h, h+3),
104105
3, 11, NORM_L1);
105-
std::cout << "END Quattro full-resolution denoising\n";
106+
x3f_printf(DEBUG, "END Quattro full-resolution denoising\n");
106107

107108
out.copyTo(act_exp);
108109
}
@@ -117,10 +118,10 @@ void x3f_set_use_opencl(int flag)
117118
if (flag) {
118119
if (ocl::useOpenCL()) {
119120
ocl::Device dev = ocl::Device::getDefault();
120-
std::cout << "OpenCL device name: " << dev.name() << "\n";
121-
std::cout << "OpenCL device version: " << dev.version() << "\n";
121+
x3f_printf(INFO, "OpenCL device name: %s\n", dev.name().c_str());
122+
x3f_printf(INFO, "OpenCL device version: %s\n", dev.version().c_str());
122123
}
123-
else std::cerr << "WARNING: OpenCL is not available\n";
124+
else x3f_printf(WARN, "WARNING: OpenCL is not available\n");
124125
}
125-
else std::cout << "OpenCL is disabled\n";
126+
else x3f_printf(DEBUG, "OpenCL is disabled\n");
126127
}

src/x3f_denoise_aniso.cpp

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <iostream>
22
#include "x3f_denoise_aniso.h"
3+
#include "x3f_printf.h"
34
#include <algorithm> //for std::sort for the median filter
45

56
static inline float determine_pixel_difference(const float& v1_1, const float& v1_2, const float& v1_3,
@@ -30,7 +31,7 @@ void median_filter(x3f_area16_t *image)
3031
const uint32_t edgeless_rows = rows - 1;
3132
const uint32_t jump = image->channels;
3233
const uint32_t stride = image->row_stride;
33-
34+
3435
uint16_t* current_set = new uint16_t[9];
3536
memset(current_set, 0, sizeof(uint16_t)*9);
3637
uint16_t* current_ptr;
@@ -40,9 +41,9 @@ void median_filter(x3f_area16_t *image)
4041
//gonna do median filtering by channel for now, to start with.
4142
uint16_t* scratch = new uint16_t[rows * cols * jump];
4243
float avg;
43-
44+
4445
memcpy(scratch, image->data, rows*cols*jump*sizeof(uint16_t));
45-
46+
4647
for (y = 1; y < edgeless_rows; y++){
4748
for (x = 1; x < edgeless_cols; x++) {
4849
for (i = 0; i < jump; i++){
@@ -78,8 +79,8 @@ void median_filter(x3f_area16_t *image)
7879
}
7980
//copy from scratch back into the image
8081
memcpy(image->data, scratch, rows*cols*jump*sizeof(uint16_t));
81-
82-
82+
83+
8384
delete [] scratch;
8485
delete [] current_set;
8586
}
@@ -101,20 +102,20 @@ void denoise_aniso_float(const uint32_t& in_rows, const uint32_t& in_columns, fl
101102
//not ideal, because there will be noise there, but it should avoid the green boundary problem.
102103
//there are a number of ways to solve boundary problems, but none of them are efficient.
103104
memcpy(out_image, image, in_rows * in_columns * jump * sizeof(float));
104-
105+
105106
//diffusion for the first channel is different, to prevent color bleed
106107
float* h = new float[jump];
107108
h[0] = 5.0f;
108109
h[1] = 1.0f;
109110
h[2] = 1.0f;
110-
111+
111112
for (y = 1; y < edgeless_rows; y++){
112113
for (x = 1,
113114
out_ptr = (out_image + y * row_stride + jump),
114115
in_ptr = (image + y * row_stride + jump);
115116
x < edgeless_cols;
116117
x++, out_ptr += jump, in_ptr += jump){
117-
118+
118119
coeff_fwd = determine_pixel_difference(*in_ptr, *(in_ptr+1), *(in_ptr+2),
119120
*(in_ptr + jump), *(in_ptr + jump + 1), *(in_ptr + jump + 2));
120121
coeff_bkwd = determine_pixel_difference(*in_ptr, *(in_ptr+1), *(in_ptr+2),
@@ -123,12 +124,12 @@ void denoise_aniso_float(const uint32_t& in_rows, const uint32_t& in_columns, fl
123124
*(in_ptr + row_stride), *(in_ptr + row_stride + 1), *(in_ptr + row_stride + 2));
124125
coeff_up = determine_pixel_difference(*in_ptr, *(in_ptr+1), *(in_ptr+2),
125126
*(in_ptr - row_stride), *(in_ptr - row_stride + 1), *(in_ptr - row_stride + 2));
126-
127+
127128
//uncomment out this line to do isotropic noise reduction
128129
//coeff_fwd = coeff_up = coeff_down = coeff_bkwd = -1.0f;
129130
lambda1 = coeff_fwd + coeff_bkwd + coeff_down + coeff_up;
130131
lambda2 = fabs(lambda1);
131-
132+
132133
for (i = 0; i < jump; i++)
133134
{
134135
*(out_ptr + i) = *(in_ptr + i) - (lambda2 * *(in_ptr + i) + coeff_fwd * *(in_ptr + jump + i)
@@ -139,7 +140,7 @@ void denoise_aniso_float(const uint32_t& in_rows, const uint32_t& in_columns, fl
139140
}
140141
}
141142
}
142-
143+
143144
memcpy(image, out_image, in_rows * in_columns * jump * sizeof(float));
144145
delete [] out_image;
145146
delete [] h;
@@ -153,7 +154,7 @@ void denoise_aniso(x3f_area16_t *image, const int& in_iterations)
153154
float* float_image = convert_to_float_image(image);
154155
for (int i = 0; i < in_iterations; i++){
155156
denoise_aniso_float(image->rows, image->columns, float_image);
156-
std::cout << "iteration: " << i << std::endl;
157+
x3f_printf(DEBUG, "iteration: %d\n", i);
157158
}
158159
convert_from_float_image(image, float_image);
159160
delete [] float_image;
@@ -178,36 +179,36 @@ void denoise_iso_float(const uint32_t& in_rows, const uint32_t& in_columns, floa
178179
//not ideal, because there will be noise there, but it should avoid the green boundary problem.
179180
//there are a number of ways to solve boundary problems, but none of them are efficient.
180181
memcpy(out_image, image, in_rows * in_columns * jump * sizeof(float));
181-
182+
182183
//diffusion for the first channel is different, to prevent color bleed
183184
float* h = new float[jump];
184185
h[0] = 5.0f;
185186
h[1] = 1.0f;
186187
h[2] = 1.0f;
187-
188+
188189
coeff_fwd = coeff_up = coeff_down = coeff_bkwd = -1.0f;
189190
lambda1 = coeff_fwd + coeff_bkwd + coeff_down + coeff_up;
190191
lambda2 = fabs(lambda1);
191-
192+
192193
for (y = 1; y < edgeless_rows; y++){
193194
for (x = 1,
194195
out_ptr = (out_image + y * row_stride + jump),
195196
in_ptr = (image + y * row_stride + jump);
196197
x < edgeless_cols;
197198
x++, out_ptr += jump, in_ptr += jump){
198-
199-
199+
200+
200201
for (i = 0; i < jump; i++)
201202
{
202203
*(out_ptr + i) = *(in_ptr + i) - (lambda2 * *(in_ptr + i) + coeff_fwd * *(in_ptr + jump + i)
203204
+ coeff_bkwd * *(in_ptr - jump + i)
204205
+ coeff_down * *(in_ptr + row_stride + i)
205206
+ coeff_up * *(in_ptr - row_stride + i))/(h[i] *lambda2);
206-
207+
207208
}
208209
}
209210
}
210-
211+
211212
memcpy(image, out_image, in_rows * in_columns * jump * sizeof(float));
212213
delete [] out_image;
213214
delete [] h;
@@ -221,7 +222,7 @@ void denoise_iso(x3f_area16_t *image, const int& in_iterations)
221222
float* float_image = convert_to_float_image(image);
222223
for (int i = 0; i < in_iterations; i++){
223224
denoise_iso_float(image->rows, image->columns, float_image);
224-
std::cout << "iteration: " << i << std::endl;
225+
x3f_printf(DEBUG, "iteration: %d\n", i);
225226
}
226227
convert_from_float_image(image, float_image);
227228
delete [] float_image;
@@ -244,19 +245,19 @@ void morphological_op(x3f_area16_t *image, const int& in_radius, const bool& ero
244245
{
245246
const int ysize = image->rows; //forcing a cast to signed for boundary conditions
246247
const int xsize = image->columns;
247-
248+
248249
uint16_t (*determinant)(const uint16_t&, const uint16_t&);
249250
determinant = &give_max;
250251
uint16_t seed = 0;
251252
if (erode){
252253
determinant = &give_min;
253254
seed = 65535;
254255
}
255-
256+
256257
const int the_edge = in_radius*2 + 1;
257258
bool** theMask = new bool*[the_edge];
258259
const int sqrRad = in_radius*in_radius;
259-
260+
260261
int x, y;
261262
for (y = -in_radius; y <= in_radius; y++){
262263
theMask[y + in_radius] = new bool[the_edge];
@@ -268,7 +269,7 @@ void morphological_op(x3f_area16_t *image, const int& in_radius, const bool& ero
268269
}
269270
}
270271
}
271-
272+
272273
int dx, dy, i;
273274
const int jump = image->channels;
274275
uint16_t* outPixelData = new uint16_t[ysize*xsize*jump];
@@ -296,11 +297,11 @@ void morphological_op(x3f_area16_t *image, const int& in_radius, const bool& ero
296297
}
297298
}
298299
}
299-
300+
300301
//memcpy(image->data, outPixelData, ysize*xsize*jump*sizeof(uint16_t));
301302
delete [] outPixelData;
302303
delete [] maxes;
303-
304+
304305
for (y = -in_radius; y <= in_radius; y++){
305306
delete [] theMask[y + in_radius];
306307
}
@@ -319,10 +320,10 @@ void denoise_splotchify(x3f_area16_t *image, const int& in_radius)
319320
uint16_t* channel = new uint16_t[channel_size];
320321
uint16_t* chan_ptr = channel;
321322
uint16_t* image_ptr;
322-
323+
323324
int morph_elem = 2; //ellipse
324325
int morph_size = in_radius;
325-
326+
326327
cv::Mat element = cv::getStructuringElement( morph_elem, cv::Size( 2*morph_size + 1, 2*morph_size+1 ), cv::Point( morph_size, morph_size ) );
327328
for (i = 0; i < image->channels; i++){
328329
//first, get the data, one channel at a time.
@@ -332,16 +333,16 @@ void denoise_splotchify(x3f_area16_t *image, const int& in_radius)
332333
*chan_ptr = *image_ptr;
333334
}
334335
}
335-
336+
336337
if (i>0){//skipping the first channel
337338
cv::Mat img(image->rows, image->columns, CV_16U, //apparently doesn't work on color images
338339
channel, sizeof(uint16_t)*xsize);
339-
340+
340341
cv::UMat out;
341342
cv::morphologyEx( img, out, 3, element );
342343
cv::morphologyEx( out, img, 2, element );
343-
344-
344+
345+
345346
for (y = 0; y < ysize; y++){
346347
for (x = 0, chan_ptr = &(channel[y*xsize]), image_ptr = &(image->data[y*image->row_stride + i]);
347348
x < xsize; x++, chan_ptr++, image_ptr+=3){
@@ -351,5 +352,5 @@ void denoise_splotchify(x3f_area16_t *image, const int& in_radius)
351352
}
352353
}
353354
delete [] channel;
354-
355+
355356
}

0 commit comments

Comments
 (0)