| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "../include/linear_contrast_stretching_seq.hpp" | ||
| 2 | |||
| 3 | #include <algorithm> // для std::minmax_element | ||
| 4 | #include <cmath> // для std::round | ||
| 5 | #include <cstddef> | ||
| 6 | #include <vector> | ||
| 7 | |||
| 8 | #include "../../common/include/common.hpp" | ||
| 9 | |||
| 10 | namespace kutergin_v_linear_contrast_stretching { | ||
| 11 | |||
| 12 |
1/2✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
|
24 | LinearContrastStretchingSequential::LinearContrastStretchingSequential(const InType &in) { |
| 13 | SetTypeOfTask(GetStaticTypeOfTask()); // установка типа задачи | ||
| 14 | GetInput() = in; // сохранение входных данных | ||
| 15 |
1/2✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
|
24 | if (!in.data.empty()) { |
| 16 |
1/2✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
|
24 | GetOutput().resize(in.data.size()); // инициализация выходных данных |
| 17 | } | ||
| 18 | 24 | } | |
| 19 | |||
| 20 | 24 | bool LinearContrastStretchingSequential::ValidationImpl() { | |
| 21 | 24 | return !GetInput().data.empty(); // проверка, что входное изображение не пустое | |
| 22 | } | ||
| 23 | |||
| 24 | 24 | bool LinearContrastStretchingSequential::PreProcessingImpl() { | |
| 25 | 24 | return true; | |
| 26 | } | ||
| 27 | |||
| 28 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 16 times.
|
24 | bool LinearContrastStretchingSequential::RunImpl() { |
| 29 | const auto &in = GetInput(); | ||
| 30 | const auto &image_in = in.data; | ||
| 31 | auto &image_out = GetOutput(); | ||
| 32 | |||
| 33 | const auto minmax_it = std::ranges::minmax_element(image_in); // нахождение минимума и максимума за один проход | ||
| 34 | 24 | unsigned char min_in = *minmax_it.min; | |
| 35 | 24 | unsigned char max_in = *minmax_it.max; | |
| 36 | |||
| 37 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 16 times.
|
24 | if (min_in == max_in) // обработка крайнего случая (все пиксели одного цвета |
| 38 | { | ||
| 39 | std::ranges::copy(image_in, image_out.begin()); // копирование исходного изображения | ||
| 40 | return true; | ||
| 41 | } | ||
| 42 | |||
| 43 | 16 | const double scale = 255.0 / (max_in - min_in); | |
| 44 |
2/2✓ Branch 0 taken 80 times.
✓ Branch 1 taken 16 times.
|
96 | for (size_t i = 0; i < image_in.size(); i++) { |
| 45 | 80 | double p_out = (image_in[i] - min_in) * scale; // линейная растяжка интенсивности | |
| 46 | 80 | image_out[i] = static_cast<unsigned char>( | |
| 47 | 80 | std::round(p_out)); // округление до ближайшего целого с явным преобразованием к unsigned char | |
| 48 | } | ||
| 49 | |||
| 50 | return true; | ||
| 51 | } | ||
| 52 | |||
| 53 | 24 | bool LinearContrastStretchingSequential::PostProcessingImpl() { | |
| 54 | 24 | return true; | |
| 55 | } | ||
| 56 | |||
| 57 | } // namespace kutergin_v_linear_contrast_stretching | ||
| 58 |