| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "balchunayte_z_sobel/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include <cstddef> | ||
| 4 | #include <cstdlib> | ||
| 5 | #include <vector> | ||
| 6 | |||
| 7 | #include "balchunayte_z_sobel/common/include/common.hpp" | ||
| 8 | |||
| 9 | namespace balchunayte_z_sobel { | ||
| 10 | |||
| 11 | namespace { | ||
| 12 | |||
| 13 | int ConvertPixelToGray(const Pixel &pixel_value) { | ||
| 14 | 96 | return (77 * static_cast<int>(pixel_value.r) + 150 * static_cast<int>(pixel_value.g) + | |
| 15 | 96 | 29 * static_cast<int>(pixel_value.b)) >> | |
| 16 | 96 | 8; | |
| 17 | } | ||
| 18 | |||
| 19 | } // namespace | ||
| 20 | |||
| 21 |
1/2✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
|
24 | BalchunayteZSobelOpSEQ::BalchunayteZSobelOpSEQ(const InType &input_image) { |
| 22 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 23 | GetInput() = input_image; | ||
| 24 | GetOutput().clear(); | ||
| 25 | 24 | } | |
| 26 | |||
| 27 | 24 | bool BalchunayteZSobelOpSEQ::ValidationImpl() { | |
| 28 | const auto &input_image = GetInput(); | ||
| 29 | |||
| 30 |
2/4✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
|
24 | if (input_image.width <= 0 || input_image.height <= 0) { |
| 31 | return false; | ||
| 32 | } | ||
| 33 | |||
| 34 |
1/2✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
|
24 | const size_t expected_size = static_cast<size_t>(input_image.width) * static_cast<size_t>(input_image.height); |
| 35 | |||
| 36 |
1/2✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
|
24 | if (input_image.data.size() != expected_size) { |
| 37 | return false; | ||
| 38 | } | ||
| 39 | |||
| 40 | 24 | return GetOutput().empty(); | |
| 41 | } | ||
| 42 | |||
| 43 | 24 | bool BalchunayteZSobelOpSEQ::PreProcessingImpl() { | |
| 44 | const auto &input_image = GetInput(); | ||
| 45 | 24 | GetOutput().assign(static_cast<size_t>(input_image.width) * static_cast<size_t>(input_image.height), 0); | |
| 46 | 24 | return true; | |
| 47 | } | ||
| 48 | |||
| 49 | 24 | bool BalchunayteZSobelOpSEQ::RunImpl() { | |
| 50 | const auto &input_image = GetInput(); | ||
| 51 | |||
| 52 | 24 | const int image_width = input_image.width; | |
| 53 | 24 | const int image_height = input_image.height; | |
| 54 | |||
| 55 |
1/2✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
|
24 | if (image_width < 3 || image_height < 3) { |
| 56 | return true; | ||
| 57 | } | ||
| 58 | |||
| 59 |
2/2✓ Branch 0 taken 48 times.
✓ Branch 1 taken 24 times.
|
72 | for (int row_index = 1; row_index < image_height - 1; ++row_index) { |
| 60 |
2/2✓ Branch 0 taken 96 times.
✓ Branch 1 taken 48 times.
|
144 | for (int col_index = 1; col_index < image_width - 1; ++col_index) { |
| 61 | 96 | const int index_top_left = ((row_index - 1) * image_width) + (col_index - 1); | |
| 62 | 96 | const int index_top_middle = ((row_index - 1) * image_width) + (col_index + 0); | |
| 63 | 96 | const int index_top_right = ((row_index - 1) * image_width) + (col_index + 1); | |
| 64 | |||
| 65 | 96 | const int index_middle_left = ((row_index + 0) * image_width) + (col_index - 1); | |
| 66 | 96 | const int index_middle_right = ((row_index + 0) * image_width) + (col_index + 1); | |
| 67 | |||
| 68 | 96 | const int index_bottom_left = ((row_index + 1) * image_width) + (col_index - 1); | |
| 69 | 96 | const int index_bottom_middle = ((row_index + 1) * image_width) + (col_index + 0); | |
| 70 | 96 | const int index_bottom_right = ((row_index + 1) * image_width) + (col_index + 1); | |
| 71 | |||
| 72 | 96 | const int gray_top_left = ConvertPixelToGray(input_image.data[static_cast<size_t>(index_top_left)]); | |
| 73 | 96 | const int gray_top_middle = ConvertPixelToGray(input_image.data[static_cast<size_t>(index_top_middle)]); | |
| 74 | 96 | const int gray_top_right = ConvertPixelToGray(input_image.data[static_cast<size_t>(index_top_right)]); | |
| 75 | |||
| 76 | 96 | const int gray_middle_left = ConvertPixelToGray(input_image.data[static_cast<size_t>(index_middle_left)]); | |
| 77 | 96 | const int gray_middle_right = ConvertPixelToGray(input_image.data[static_cast<size_t>(index_middle_right)]); | |
| 78 | |||
| 79 | 96 | const int gray_bottom_left = ConvertPixelToGray(input_image.data[static_cast<size_t>(index_bottom_left)]); | |
| 80 | 96 | const int gray_bottom_middle = ConvertPixelToGray(input_image.data[static_cast<size_t>(index_bottom_middle)]); | |
| 81 | 96 | const int gray_bottom_right = ConvertPixelToGray(input_image.data[static_cast<size_t>(index_bottom_right)]); | |
| 82 | |||
| 83 | 96 | const int gradient_x = (-gray_top_left + gray_top_right) + (-2 * gray_middle_left + 2 * gray_middle_right) + | |
| 84 | 96 | (-gray_bottom_left + gray_bottom_right); | |
| 85 | |||
| 86 | 96 | const int gradient_y = (gray_top_left + 2 * gray_top_middle + gray_top_right) + | |
| 87 | 96 | (-gray_bottom_left - 2 * gray_bottom_middle - gray_bottom_right); | |
| 88 | |||
| 89 | 96 | const int magnitude = std::abs(gradient_x) + std::abs(gradient_y); | |
| 90 | |||
| 91 | 96 | const size_t output_index = | |
| 92 | 96 | (static_cast<size_t>(row_index) * static_cast<size_t>(image_width)) + static_cast<size_t>(col_index); | |
| 93 | 96 | GetOutput()[output_index] = magnitude; | |
| 94 | } | ||
| 95 | } | ||
| 96 | |||
| 97 | return true; | ||
| 98 | } | ||
| 99 | |||
| 100 | 24 | bool BalchunayteZSobelOpSEQ::PostProcessingImpl() { | |
| 101 | 24 | return true; | |
| 102 | } | ||
| 103 | |||
| 104 | } // namespace balchunayte_z_sobel | ||
| 105 |