-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_usage.cu
More file actions
107 lines (88 loc) · 4.01 KB
/
Copy pathexample_usage.cu
File metadata and controls
107 lines (88 loc) · 4.01 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
// Simple example demonstrating library usage
#include <iostream>
#include "src/image_processing_lib.cuh"
int main(int argc, char** argv) {
// Verify CUDA devices
if (!verifyCudaDevices()) {
std::cerr << "No CUDA devices found!" << std::endl;
return -1;
}
const char* input_path = (argc > 1) ? argv[1] : "images/input.png";
const char* output_path = (argc > 2) ? argv[2] : "images/output.png";
std::cout << "Loading image: " << input_path << std::endl;
// Load input image
Image input(input_path);
if (!input.image_data) {
std::cerr << "Failed to load image!" << std::endl;
return -1;
}
std::cout << "Image size: " << input.width << "x" << input.height
<< " (" << input.channels << " channels)" << std::endl;
// Create output image
Image output(input.width, input.height, 1);
// Example 1: Low-pass filter for noise reduction
std::cout << "\nApplying Gaussian low-pass filter..." << std::endl;
{
FilterParams params;
params.type = FilterType::GAUSSIAN;
params.cutoff_freq = 50.0f;
ImageRestoration::restoreImage(input, output, RestorationMode::LOW_PASS, params);
stbi_write_png("images/example_lowpass.png", output.width, output.height, 1,
output.image_data, output.width);
std::cout << "Saved: images/example_lowpass.png" << std::endl;
}
// Example 2: High-pass filter for edge enhancement
std::cout << "\nApplying Gaussian high-pass filter..." << std::endl;
{
FilterParams params;
params.type = FilterType::GAUSSIAN;
params.cutoff_freq = 10.0f;
ImageRestoration::restoreImage(input, output, RestorationMode::HIGH_PASS, params);
stbi_write_png("images/example_highpass.png", output.width, output.height, 1,
output.image_data, output.width);
std::cout << "Saved: images/example_highpass.png" << std::endl;
}
// Example 3: Band-pass filter
std::cout << "\nApplying band-pass filter..." << std::endl;
{
FilterParams params;
params.type = FilterType::GAUSSIAN;
params.low_freq = 20.0f;
params.high_freq = 60.0f;
params.center_freq = 40.0f;
params.bandwidth = 20.0f;
ImageRestoration::restoreImage(input, output, RestorationMode::BAND_PASS, params);
stbi_write_png("images/example_bandpass.png", output.width, output.height, 1,
output.image_data, output.width);
std::cout << "Saved: images/example_bandpass.png" << std::endl;
}
// Example 4: Unsharp masking for sharpening
std::cout << "\nApplying unsharp masking..." << std::endl;
{
FilterParams params;
params.unsharp_amount = 1.5f;
params.unsharp_radius = 30.0f;
ImageRestoration::unsharpMask(input, output, params);
stbi_write_png(output_path, output.width, output.height, 1,
output.image_data, output.width);
std::cout << "Saved: " << output_path << std::endl;
}
// Example 5: Butterworth filter with custom order
std::cout << "\nApplying Butterworth low-pass filter..." << std::endl;
{
FilterParams params;
params.type = FilterType::BUTTERWORTH;
params.cutoff_freq = 50.0f;
params.butterworth_order = 4;
ImageRestoration::restoreImage(input, output, RestorationMode::LOW_PASS, params);
stbi_write_png("images/example_butterworth.png", output.width, output.height, 1,
output.image_data, output.width);
std::cout << "Saved: images/example_butterworth.png" << std::endl;
}
std::cout << "\n" << SUCCESS_GREEN << "All examples completed successfully!"
<< RESET << std::endl;
return 0;
}
// Usage:
// ./example_usage
// ./example_usage input.png output.png