-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
88 lines (68 loc) · 3.42 KB
/
main.cpp
File metadata and controls
88 lines (68 loc) · 3.42 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
#include "utilities/error_handler.h"
#include "utilities/code_tester.h"
#include "demake_cv/stb_img.h"
#include "demake_cv/demake_cv.h"
#include <iostream>
#include <filesystem>
#include <string>
using namespace std;
#define INPUT_FOLDER "./test_images"
#define OUTPUT_FOLDER "./outputs"
int main(void) {
// read all .bmp & .tif in INPUT_FOLDER. Process them one by one.
try {
for (const filesystem::directory_entry &entry : filesystem::directory_iterator(INPUT_FOLDER)) {
// open image & preprocess file name
STB_Img image(entry.path().string());
filesystem::path origin_path = entry.path();
string origin_file_name = origin_path.replace_extension().filename().string();
// calculate
// float kernel[9] = {0, 1, 0, 1, -4, 1, 0, 1, 0}; // origin Laplacian, extract changes "away" from pixel
float kernel[9] = {0, -1, 0, -1, 5, -1, 0, -1, 0}; // reverse sign to enhance changes "toward" pixel
// int kernel[9] = {1, 1, 1, 1, -8, 1, 1, 1, };
cout << "\nSharpening by Laplacian operator (clamp)..." << endl;
STB_Img result(DemakeCV::convolution_range_clamp<float>(image, kernel, 3));
ErrorHandler::success_notice("Laplacian operator (clamp)");
// result += image;
result.store("laplacian_clamp_" + origin_file_name + ".png", OUTPUT_FOLDER);
result += 0.5f * image;
result.store("laplacian_clamp_boost_" + origin_file_name + ".png", OUTPUT_FOLDER);
cout << "\nnSharpening by Laplacian operator (scale)..." << endl;
result = STB_Img(DemakeCV::convolution_range_scale<float>(image, kernel, 3));
ErrorHandler::success_notice("Laplacian operator (scale)");
// result += image;
result.store("laplacian_scale_" + origin_file_name + ".png", OUTPUT_FOLDER);
float val = -1.f / 5.f;
// float average_kernel[9] = {val, val, val, val, val, val, val, val, val};
float average_kernel[9] = {0, val, 0, val, 2.f + val, val, 0, val, 0};
cout << "\nSharpening by Deblurring (clamp)..." << endl;
result = DemakeCV::convolution_range_clamp<float>(image, average_kernel, 3);
ErrorHandler::success_notice("Deblurring (clamp)");
result.store("deblurr_clamp_" + origin_file_name + ".png", OUTPUT_FOLDER);
result += 0.5f * image;
result.store("deblurr_clamp_boost_" + origin_file_name + ".png", OUTPUT_FOLDER);
cout << "\nSharpening by Deblurring (scale)..." << endl;
result = DemakeCV::convolution_range_scale<float>(image, average_kernel, 3);
ErrorHandler::success_notice("Deblurring (scale)");
result.store("deblurr_scale_" + origin_file_name + ".png", OUTPUT_FOLDER);
// close image by destructor
}
} catch (const filesystem::filesystem_error& err) {
ErrorHandler::fatal_error(err.what(), __FILE__, __LINE__);
}
return 0;
}
//TODO:
// [V] read .tif file: need TinyTiff https://jkriege2.github.io/TinyTIFF/page_useinstructions.html
// [V] convolution
// [V] hard clamp
// [V] clamp range by scaling
// [V] Laplacian operator sharpening
// [V] image addition
// [V] blur
// [V] high-boost filtering
// [?] FFT
// [] DFT
// [] mask
// [] inverse DFFT
// [?] to GLSL (faster only in creating new pic)