| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "lopatin_a_sobel_operator/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include <array> | ||
| 4 | #include <cmath> | ||
| 5 | #include <cstddef> | ||
| 6 | #include <cstdint> | ||
| 7 | |||
| 8 | #include "lopatin_a_sobel_operator/common/include/common.hpp" | ||
| 9 | |||
| 10 | namespace lopatin_a_sobel_operator { | ||
| 11 | |||
| 12 | const std::array<std::array<int, 3>, 3> kSobelX = {std::array<int, 3>{-1, 0, 1}, std::array<int, 3>{-2, 0, 2}, | ||
| 13 | std::array<int, 3>{-1, 0, 1}}; | ||
| 14 | |||
| 15 | const std::array<std::array<int, 3>, 3> kSobelY = {std::array<int, 3>{-1, -2, -1}, std::array<int, 3>{0, 0, 0}, | ||
| 16 | std::array<int, 3>{1, 2, 1}}; | ||
| 17 | |||
| 18 |
1/2✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
|
24 | LopatinASobelOperatorSEQ::LopatinASobelOperatorSEQ(const InType &in) : h_(in.height), w_(in.width) { |
| 19 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 20 | GetInput() = in; | ||
| 21 | GetOutput().clear(); | ||
| 22 | 24 | } | |
| 23 | |||
| 24 | 24 | bool LopatinASobelOperatorSEQ::ValidationImpl() { | |
| 25 | const auto &input = GetInput(); | ||
| 26 | 24 | return h_ * w_ == input.pixels.size(); | |
| 27 | } | ||
| 28 | |||
| 29 | 24 | bool LopatinASobelOperatorSEQ::PreProcessingImpl() { | |
| 30 | 24 | GetOutput().resize(h_ * w_); | |
| 31 | 24 | return true; | |
| 32 | } | ||
| 33 | |||
| 34 | 24 | bool LopatinASobelOperatorSEQ::RunImpl() { | |
| 35 | const auto &input = GetInput(); | ||
| 36 | const auto &input_data = input.pixels; | ||
| 37 | auto &output = GetOutput(); | ||
| 38 | |||
| 39 |
2/2✓ Branch 0 taken 72 times.
✓ Branch 1 taken 24 times.
|
96 | for (std::size_t j = 1; j < h_ - 1; ++j) { // processing only pixels with a full 3 x 3 neighborhood size |
| 40 |
2/2✓ Branch 0 taken 280 times.
✓ Branch 1 taken 72 times.
|
352 | for (std::size_t i = 1; i < w_ - 1; ++i) { |
| 41 | int gx = 0; | ||
| 42 | int gy = 0; | ||
| 43 | |||
| 44 |
2/2✓ Branch 0 taken 840 times.
✓ Branch 1 taken 280 times.
|
1120 | for (int ky = -1; ky <= 1; ++ky) { |
| 45 |
2/2✓ Branch 0 taken 2520 times.
✓ Branch 1 taken 840 times.
|
3360 | for (int kx = -1; kx <= 1; ++kx) { |
| 46 | 2520 | std::uint8_t pixel = input_data[((j + ky) * w_) + (i + kx)]; | |
| 47 | 2520 | gx += pixel * kSobelX.at(ky + 1).at(kx + 1); | |
| 48 | 2520 | gy += pixel * kSobelY.at(ky + 1).at(kx + 1); | |
| 49 | } | ||
| 50 | } | ||
| 51 | |||
| 52 |
2/2✓ Branch 0 taken 96 times.
✓ Branch 1 taken 184 times.
|
280 | auto magnitude = static_cast<int>(round(std::sqrt((gx * gx) + (gy * gy)))); |
| 53 |
2/2✓ Branch 0 taken 96 times.
✓ Branch 1 taken 184 times.
|
376 | output[(j * w_) + i] = (magnitude > input.threshold) ? magnitude : 0; |
| 54 | } | ||
| 55 | } | ||
| 56 | |||
| 57 | 24 | return true; | |
| 58 | } | ||
| 59 | |||
| 60 | 24 | bool LopatinASobelOperatorSEQ::PostProcessingImpl() { | |
| 61 | 24 | return true; | |
| 62 | } | ||
| 63 | |||
| 64 | } // namespace lopatin_a_sobel_operator | ||
| 65 |