| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "batushin_i_incr_contrast_with_lhs/omp/include/ops_omp.hpp" | ||
| 2 | |||
| 3 | #include <algorithm> | ||
| 4 | #include <cmath> | ||
| 5 | #include <cstddef> | ||
| 6 | #include <utility> | ||
| 7 | #include <vector> | ||
| 8 | |||
| 9 | #include "batushin_i_incr_contrast_with_lhs/common/include/common.hpp" | ||
| 10 | |||
| 11 | namespace batushin_i_incr_contrast_with_lhs { | ||
| 12 | |||
| 13 |
1/2✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
|
40 | BatushinIIncrContrastWithLhsOMP::BatushinIIncrContrastWithLhsOMP(const InType &in) { |
| 14 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 15 |
1/2✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
|
40 | GetInput() = in; |
| 16 |
1/2✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
|
40 | GetOutput().resize(in.size()); |
| 17 | 40 | } | |
| 18 | |||
| 19 | 40 | bool BatushinIIncrContrastWithLhsOMP::ValidationImpl() { | |
| 20 | 40 | return !GetInput().empty(); | |
| 21 | } | ||
| 22 | |||
| 23 | 40 | bool BatushinIIncrContrastWithLhsOMP::PreProcessingImpl() { | |
| 24 | 40 | return true; | |
| 25 | } | ||
| 26 | |||
| 27 | namespace { | ||
| 28 | |||
| 29 | unsigned char NormalizePixel(unsigned char pixel, unsigned char min_val, double scale_factor) { | ||
| 30 | double normalized = static_cast<double>(pixel - min_val) * scale_factor; | ||
| 31 | normalized = std::floor(normalized + 0.5); | ||
| 32 | normalized = std::max(normalized, 0.0); | ||
| 33 | normalized = std::min(normalized, 255.0); | ||
| 34 | return static_cast<unsigned char>(normalized); | ||
| 35 | } | ||
| 36 | |||
| 37 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
|
40 | std::pair<unsigned char, unsigned char> FindMinMaxParallel(const std::vector<unsigned char> &data) { |
| 38 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
|
40 | if (data.empty()) { |
| 39 | ✗ | return {0, 0}; | |
| 40 | } | ||
| 41 | |||
| 42 | 40 | unsigned char minimum = data[0]; | |
| 43 | 40 | unsigned char maximum = data[0]; | |
| 44 | |||
| 45 | const size_t data_size = data.size(); | ||
| 46 | |||
| 47 | 40 | #pragma omp parallel default(none) shared(data, data_size, minimum, maximum) | |
| 48 | { | ||
| 49 | #pragma omp for reduction(min : minimum) reduction(max : maximum) | ||
| 50 | for (size_t idx = 0; idx < data_size; ++idx) { | ||
| 51 | minimum = std::min(minimum, data[idx]); | ||
| 52 | maximum = std::max(maximum, data[idx]); | ||
| 53 | } | ||
| 54 | } | ||
| 55 | |||
| 56 | 40 | return {minimum, maximum}; | |
| 57 | } | ||
| 58 | |||
| 59 | void FillUniformImage(std::vector<unsigned char> &output, size_t size) { | ||
| 60 | 16 | output.assign(size, 128); | |
| 61 | } | ||
| 62 | |||
| 63 | } // namespace | ||
| 64 | |||
| 65 | 40 | bool BatushinIIncrContrastWithLhsOMP::RunImpl() { | |
| 66 | const std::vector<unsigned char> &source = GetInput(); | ||
| 67 | std::vector<unsigned char> &destination = GetOutput(); | ||
| 68 | |||
| 69 | 40 | auto min_max = FindMinMaxParallel(source); | |
| 70 | 40 | unsigned char min_value = min_max.first; | |
| 71 | 40 | unsigned char max_value = min_max.second; | |
| 72 | |||
| 73 |
2/2✓ Branch 0 taken 16 times.
✓ Branch 1 taken 24 times.
|
40 | if (min_value == max_value) { |
| 74 | FillUniformImage(destination, source.size()); | ||
| 75 | 16 | return true; | |
| 76 | } | ||
| 77 | |||
| 78 | 24 | const double scale_coefficient = 255.0 / static_cast<double>(max_value - min_value); | |
| 79 | |||
| 80 | 24 | destination.resize(source.size()); | |
| 81 | |||
| 82 | const size_t source_size = source.size(); | ||
| 83 | |||
| 84 | 24 | #pragma omp parallel for default(none) shared(source, destination, source_size, min_value, scale_coefficient) | |
| 85 | for (size_t position = 0; position < source_size; ++position) { | ||
| 86 | destination[position] = NormalizePixel(source[position], min_value, scale_coefficient); | ||
| 87 | } | ||
| 88 | |||
| 89 | 24 | return true; | |
| 90 | } | ||
| 91 | |||
| 92 | 40 | bool BatushinIIncrContrastWithLhsOMP::PostProcessingImpl() { | |
| 93 | 40 | return true; | |
| 94 | } | ||
| 95 | |||
| 96 | } // namespace batushin_i_incr_contrast_with_lhs | ||
| 97 |