-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.h
More file actions
74 lines (65 loc) · 2.13 KB
/
test.h
File metadata and controls
74 lines (65 loc) · 2.13 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
#pragma once
#include <omp.h>
#include "otsuFuncs.h"
#include "PnmImage.h"
inline std::vector<int> testImageThresholds(const int thresholdsCount, const std::string& inputPath,
const std::string& outputPath = "")
{
std::vector<int> thresholds;
try
{
PnmImage image;
image.loadFromFile(inputPath);
thresholds = calculateOtsuThresholds(image);
if (!outputPath.empty())
{
PnmImage copyOfImage(image);
copyOfImage.applyThresholds(thresholds);
copyOfImage.saveToFile(outputPath);
}
}
catch (std::ios_base::failure& e)
{
std::cout << "IOError in threads test: " << e.what() << std::endl;
}
catch (std::runtime_error& e)
{
std::cout << "RuntimeError in threads test: " << e.what() << std::endl;
}
return thresholds;
}
inline double threadsTimeTest(const int thresholdsCount, const int threadsCount, const std::string& inputPath,
const std::string& outputPath = "")
{
double sum = 0.0;
constexpr int iterations = 5;
try
{
PnmImage image;
image.loadFromFile(inputPath);
omp_set_num_threads(threadsCount);
calculateOtsuThresholds(image);
for (int i = 0; i < iterations; ++i)
{
const double start = omp_get_wtime();
std::vector<int> thresholds = calculateOtsuThresholds(image);
const double end = omp_get_wtime();
sum += end - start;
if (outputPath != "")
{
PnmImage copyOfImage(image);
copyOfImage.applyThresholds(thresholds);
copyOfImage.saveToFile(outputPath + "_" + std::to_string(i) + ".pnm");
}
}
}
catch (std::ios_base::failure& e)
{
std::cout << "IOError in threads test: " << e.what() << std::endl;
}
catch (std::runtime_error& e)
{
std::cout << "RuntimeError in threads test: " << e.what() << std::endl;
}
return sum / iterations;
}