| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "vlasova_a_image_smoothing/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include <algorithm> | ||
| 4 | #include <cstddef> | ||
| 5 | #include <cstdint> | ||
| 6 | #include <iterator> | ||
| 7 | #include <vector> | ||
| 8 | |||
| 9 | #include "vlasova_a_image_smoothing/common/include/common.hpp" | ||
| 10 | |||
| 11 | namespace vlasova_a_image_smoothing { | ||
| 12 | |||
| 13 |
1/2✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
|
24 | VlasovaAImageSmoothingSEQ::VlasovaAImageSmoothingSEQ(const InType &in) { |
| 14 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 15 | GetInput() = in; | ||
| 16 | 24 | } | |
| 17 | |||
| 18 | 24 | bool VlasovaAImageSmoothingSEQ::ValidationImpl() { | |
| 19 | const auto &input = GetInput(); | ||
| 20 | |||
| 21 |
2/4✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
|
24 | if (input.width <= 0 || input.height <= 0) { |
| 22 | return false; | ||
| 23 | } | ||
| 24 | |||
| 25 |
1/2✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
|
24 | if (input.data.empty()) { |
| 26 | return false; | ||
| 27 | } | ||
| 28 | |||
| 29 | 24 | const std::size_t expected_size = static_cast<std::size_t>(input.width) * input.height; | |
| 30 | 24 | return input.data.size() == expected_size; | |
| 31 | } | ||
| 32 | |||
| 33 | 24 | bool VlasovaAImageSmoothingSEQ::PreProcessingImpl() { | |
| 34 | const auto &input = GetInput(); | ||
| 35 | |||
| 36 | 24 | width_ = input.width; | |
| 37 | 24 | height_ = input.height; | |
| 38 | 24 | input_image_ = input.data; | |
| 39 | 24 | output_image_.resize(input_image_.size()); | |
| 40 | |||
| 41 | 24 | return true; | |
| 42 | } | ||
| 43 | |||
| 44 | 24 | bool VlasovaAImageSmoothingSEQ::RunImpl() { | |
| 45 | 98304 | auto calculate_pixel_median = [this](int col_idx, int row_idx) -> std::uint8_t { | |
| 46 | 98304 | const int radius = window_size_ / 2; | |
| 47 | 98304 | std::vector<std::uint8_t> neighbors; | |
| 48 |
1/2✓ Branch 1 taken 98304 times.
✗ Branch 2 not taken.
|
98304 | neighbors.reserve(static_cast<std::size_t>(window_size_) * window_size_); |
| 49 | |||
| 50 |
2/2✓ Branch 0 taken 294912 times.
✓ Branch 1 taken 98304 times.
|
393216 | for (int dy = -radius; dy <= radius; ++dy) { |
| 51 |
2/2✓ Branch 0 taken 884736 times.
✓ Branch 1 taken 294912 times.
|
1179648 | for (int dx = -radius; dx <= radius; ++dx) { |
| 52 | 884736 | const int neighbor_x = col_idx + dx; | |
| 53 | 884736 | const int neighbor_y = row_idx + dy; | |
| 54 | |||
| 55 |
8/8✓ Branch 0 taken 880128 times.
✓ Branch 1 taken 4608 times.
✓ Branch 2 taken 875520 times.
✓ Branch 3 taken 4608 times.
✓ Branch 4 taken 870960 times.
✓ Branch 5 taken 4560 times.
✓ Branch 6 taken 866400 times.
✓ Branch 7 taken 4560 times.
|
884736 | if (neighbor_x >= 0 && neighbor_x < width_ && neighbor_y >= 0 && neighbor_y < height_) { |
| 56 |
1/2✓ Branch 0 taken 866400 times.
✗ Branch 1 not taken.
|
866400 | const std::size_t index = (static_cast<std::size_t>(neighbor_y) * width_) + neighbor_x; |
| 57 | neighbors.push_back(input_image_[index]); | ||
| 58 | } | ||
| 59 | } | ||
| 60 | } | ||
| 61 | |||
| 62 |
1/2✓ Branch 0 taken 98304 times.
✗ Branch 1 not taken.
|
98304 | if (!neighbors.empty()) { |
| 63 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 98304 times.
|
98304 | auto middle = std::next(neighbors.begin(), static_cast<std::ptrdiff_t>(neighbors.size() / 2)); |
| 64 | 98304 | std::nth_element(neighbors.begin(), middle, neighbors.end()); | |
| 65 | 98304 | return *middle; | |
| 66 | } | ||
| 67 | |||
| 68 | ✗ | const std::size_t index = (static_cast<std::size_t>(row_idx) * width_) + col_idx; | |
| 69 | ✗ | return input_image_[index]; | |
| 70 | 24 | }; | |
| 71 | |||
| 72 |
2/2✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 24 times.
|
1560 | for (int row_idx = 0; row_idx < height_; ++row_idx) { |
| 73 |
2/2✓ Branch 0 taken 98304 times.
✓ Branch 1 taken 1536 times.
|
99840 | for (int col_idx = 0; col_idx < width_; ++col_idx) { |
| 74 | 98304 | const std::size_t output_index = (static_cast<std::size_t>(row_idx) * width_) + col_idx; | |
| 75 | 98304 | output_image_[output_index] = calculate_pixel_median(col_idx, row_idx); | |
| 76 | } | ||
| 77 | } | ||
| 78 | |||
| 79 | 24 | return true; | |
| 80 | } | ||
| 81 | |||
| 82 | 24 | bool VlasovaAImageSmoothingSEQ::PostProcessingImpl() { | |
| 83 | 24 | GetOutput().width = width_; | |
| 84 | 24 | GetOutput().height = height_; | |
| 85 | 24 | GetOutput().data = output_image_; | |
| 86 | |||
| 87 |
1/2✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
|
24 | if (GetOutput().data.empty()) { |
| 88 | return false; | ||
| 89 | } | ||
| 90 | |||
| 91 | 24 | const std::size_t expected_size = static_cast<std::size_t>(width_) * height_; | |
| 92 | 24 | return GetOutput().data.size() == expected_size; | |
| 93 | } | ||
| 94 | |||
| 95 | } // namespace vlasova_a_image_smoothing | ||
| 96 |