| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "badanov_a_select_edge_sobel_seq/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include <algorithm> | ||
| 4 | #include <cmath> | ||
| 5 | #include <cstddef> | ||
| 6 | #include <cstdint> | ||
| 7 | #include <vector> | ||
| 8 | |||
| 9 | #include "badanov_a_select_edge_sobel_seq/common/include/common.hpp" | ||
| 10 | |||
| 11 | namespace badanov_a_select_edge_sobel_seq { | ||
| 12 | |||
| 13 |
1/2✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
|
40 | BadanovASelectEdgeSobelSEQ::BadanovASelectEdgeSobelSEQ(const InType &in) { |
| 14 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 15 |
1/2✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
|
40 | GetInput() = in; |
| 16 | 40 | GetOutput() = std::vector<uint8_t>(); | |
| 17 | 40 | } | |
| 18 | |||
| 19 | 40 | bool BadanovASelectEdgeSobelSEQ::ValidationImpl() { | |
| 20 | const auto &input = GetInput(); | ||
| 21 | 40 | return !input.empty(); | |
| 22 | } | ||
| 23 | |||
| 24 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
|
40 | bool BadanovASelectEdgeSobelSEQ::PreProcessingImpl() { |
| 25 | const auto &input = GetInput(); | ||
| 26 | |||
| 27 | 40 | width_ = static_cast<int>(std::sqrt(input.size())); | |
| 28 | 40 | height_ = width_; | |
| 29 | |||
| 30 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
|
40 | if (width_ * height_ != static_cast<int>(input.size())) { |
| 31 | ✗ | width_ = static_cast<int>(input.size()); | |
| 32 | ✗ | height_ = 1; | |
| 33 | } | ||
| 34 | |||
| 35 | 40 | GetOutput() = std::vector<uint8_t>(input.size(), 0); | |
| 36 | |||
| 37 | 40 | return true; | |
| 38 | } | ||
| 39 | |||
| 40 | 40 | void BadanovASelectEdgeSobelSEQ::ApplySobelOperator(const std::vector<uint8_t> &input, std::vector<float> &magnitude, | |
| 41 | float &max_magnitude) { | ||
| 42 | 40 | max_magnitude = 0.0F; | |
| 43 | |||
| 44 |
2/2✓ Branch 0 taken 336 times.
✓ Branch 1 taken 40 times.
|
376 | for (int row = 1; row < height_ - 1; ++row) { |
| 45 |
2/2✓ Branch 0 taken 3744 times.
✓ Branch 1 taken 336 times.
|
4080 | for (int col = 1; col < width_ - 1; ++col) { |
| 46 | 3744 | float gradient_x = 0.0F; | |
| 47 | 3744 | float gradient_y = 0.0F; | |
| 48 | |||
| 49 | 3744 | ComputeGradientAtPixel(input, row, col, gradient_x, gradient_y); | |
| 50 | |||
| 51 |
2/2✓ Branch 0 taken 2744 times.
✓ Branch 1 taken 1000 times.
|
3744 | const float magnitude_value = std::sqrt((gradient_x * gradient_x) + (gradient_y * gradient_y)); |
| 52 |
2/2✓ Branch 0 taken 2744 times.
✓ Branch 1 taken 1000 times.
|
3744 | const size_t idx = (static_cast<size_t>(row) * static_cast<size_t>(width_)) + static_cast<size_t>(col); |
| 53 |
2/2✓ Branch 0 taken 2744 times.
✓ Branch 1 taken 1000 times.
|
3744 | magnitude[idx] = magnitude_value; |
| 54 | |||
| 55 | 3744 | max_magnitude = std::max(magnitude_value, max_magnitude); | |
| 56 | } | ||
| 57 | } | ||
| 58 | 40 | } | |
| 59 | |||
| 60 | 3744 | void BadanovASelectEdgeSobelSEQ::ComputeGradientAtPixel(const std::vector<uint8_t> &input, int row, int col, | |
| 61 | float &gradient_x, float &gradient_y) const { | ||
| 62 | 3744 | gradient_x = 0.0F; | |
| 63 | 3744 | gradient_y = 0.0F; | |
| 64 | |||
| 65 |
2/2✓ Branch 0 taken 11232 times.
✓ Branch 1 taken 3744 times.
|
14976 | for (int kernel_row = -1; kernel_row <= 1; ++kernel_row) { |
| 66 |
2/2✓ Branch 0 taken 33696 times.
✓ Branch 1 taken 11232 times.
|
44928 | for (int kernel_col = -1; kernel_col <= 1; ++kernel_col) { |
| 67 | 33696 | const size_t pixel_index = | |
| 68 | 33696 | (static_cast<size_t>(row + kernel_row) * static_cast<size_t>(width_)) + static_cast<size_t>(col + kernel_col); | |
| 69 | 33696 | const uint8_t pixel = input[pixel_index]; | |
| 70 | |||
| 71 | 33696 | const int kx_idx = kernel_row + 1; | |
| 72 | 33696 | const int ky_idx = kernel_col + 1; | |
| 73 | 33696 | const int kernel_x_value = kKernelX.at(static_cast<size_t>(kx_idx)).at(static_cast<size_t>(ky_idx)); | |
| 74 | 33696 | const int kernel_y_value = kKernelY.at(static_cast<size_t>(kx_idx)).at(static_cast<size_t>(ky_idx)); | |
| 75 | |||
| 76 | 33696 | gradient_x += static_cast<float>(pixel) * static_cast<float>(kernel_x_value); | |
| 77 | 33696 | gradient_y += static_cast<float>(pixel) * static_cast<float>(kernel_y_value); | |
| 78 | } | ||
| 79 | } | ||
| 80 | 3744 | } | |
| 81 | |||
| 82 | 40 | void BadanovASelectEdgeSobelSEQ::ApplyThreshold(const std::vector<float> &magnitude, float max_magnitude, | |
| 83 | std::vector<uint8_t> &output) const { | ||
| 84 |
2/2✓ Branch 0 taken 32 times.
✓ Branch 1 taken 8 times.
|
40 | if (max_magnitude > 0.0F) { |
| 85 | 32 | const float scale = 255.0F / max_magnitude; | |
| 86 |
2/2✓ Branch 0 taken 4736 times.
✓ Branch 1 taken 32 times.
|
4768 | for (size_t i = 0; i < magnitude.size(); ++i) { |
| 87 |
2/2✓ Branch 0 taken 3288 times.
✓ Branch 1 taken 1448 times.
|
8024 | output[i] = (magnitude[i] * scale > static_cast<float>(threshold_)) ? 255 : 0; |
| 88 | } | ||
| 89 | } else { | ||
| 90 | std::ranges::fill(output, 0); | ||
| 91 | } | ||
| 92 | 40 | } | |
| 93 | |||
| 94 |
1/2✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
|
40 | bool BadanovASelectEdgeSobelSEQ::RunImpl() { |
| 95 | const auto &input = GetInput(); | ||
| 96 | auto &output = GetOutput(); | ||
| 97 | |||
| 98 |
2/4✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 40 times.
|
40 | if (height_ < 3 || width_ < 3) { |
| 99 | ✗ | output = input; | |
| 100 | ✗ | return true; | |
| 101 | } | ||
| 102 | |||
| 103 | 40 | std::vector<float> magnitude(input.size(), 0.0F); | |
| 104 | 40 | float max_magnitude = 0.0F; | |
| 105 | |||
| 106 | 40 | ApplySobelOperator(input, magnitude, max_magnitude); | |
| 107 | 40 | ApplyThreshold(magnitude, max_magnitude, output); | |
| 108 | |||
| 109 | return true; | ||
| 110 | } | ||
| 111 | |||
| 112 | 40 | bool BadanovASelectEdgeSobelSEQ::PostProcessingImpl() { | |
| 113 | 40 | return true; | |
| 114 | } | ||
| 115 | |||
| 116 | } // namespace badanov_a_select_edge_sobel_seq | ||
| 117 |