| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "posternak_a_increase_contrast/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include <algorithm> | ||
| 4 | #include <cmath> | ||
| 5 | #include <cstddef> | ||
| 6 | #include <vector> | ||
| 7 | |||
| 8 | #include "posternak_a_increase_contrast/common/include/common.hpp" | ||
| 9 | |||
| 10 | namespace posternak_a_increase_contrast { | ||
| 11 | |||
| 12 |
1/2✓ Branch 1 taken 80 times.
✗ Branch 2 not taken.
|
80 | PosternakAIncreaseContrastSEQ::PosternakAIncreaseContrastSEQ(const InType &in) { |
| 13 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 14 |
1/2✓ Branch 1 taken 80 times.
✗ Branch 2 not taken.
|
80 | GetInput() = in; |
| 15 |
1/2✓ Branch 1 taken 80 times.
✗ Branch 2 not taken.
|
80 | GetOutput().resize(in.size()); |
| 16 | 80 | } | |
| 17 | |||
| 18 | 80 | bool PosternakAIncreaseContrastSEQ::ValidationImpl() { | |
| 19 | 80 | return !GetInput().empty(); | |
| 20 | } | ||
| 21 | |||
| 22 | 80 | bool PosternakAIncreaseContrastSEQ::PreProcessingImpl() { | |
| 23 | 80 | return true; | |
| 24 | } | ||
| 25 | |||
| 26 |
1/2✓ Branch 0 taken 80 times.
✗ Branch 1 not taken.
|
80 | bool PosternakAIncreaseContrastSEQ::RunImpl() { |
| 27 | const std::vector<unsigned char> &input = GetInput(); | ||
| 28 | std::vector<unsigned char> &output = GetOutput(); | ||
| 29 | |||
| 30 |
1/2✓ Branch 0 taken 80 times.
✗ Branch 1 not taken.
|
80 | unsigned char min_val = *std::ranges::min_element(input); |
| 31 | 80 | unsigned char max_val = *std::ranges::max_element(input); | |
| 32 | |||
| 33 |
2/2✓ Branch 0 taken 32 times.
✓ Branch 1 taken 48 times.
|
80 | if (min_val == max_val) { |
| 34 | std::ranges::fill(output, 128); | ||
| 35 | 32 | return true; | |
| 36 | } | ||
| 37 | |||
| 38 | 48 | double scale = 255.0 / static_cast<double>(max_val - min_val); | |
| 39 | |||
| 40 |
2/2✓ Branch 0 taken 216 times.
✓ Branch 1 taken 48 times.
|
264 | for (size_t i = 0; i < input.size(); ++i) { |
| 41 | 216 | double new_pixel = static_cast<double>(input[i] - min_val) * scale; | |
| 42 | 216 | new_pixel = std::round(new_pixel); | |
| 43 | new_pixel = std::max(new_pixel, 0.0); | ||
| 44 | new_pixel = std::min(new_pixel, 255.0); | ||
| 45 | |||
| 46 | 216 | output[i] = static_cast<unsigned char>(new_pixel); | |
| 47 | } | ||
| 48 | |||
| 49 | return true; | ||
| 50 | } | ||
| 51 | |||
| 52 | 80 | bool PosternakAIncreaseContrastSEQ::PostProcessingImpl() { | |
| 53 | 80 | return true; | |
| 54 | } | ||
| 55 | |||
| 56 | } // namespace posternak_a_increase_contrast | ||
| 57 |