| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "krykov_e_sobel_op/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include <array> | ||
| 4 | #include <cmath> | ||
| 5 | #include <cstddef> | ||
| 6 | #include <vector> | ||
| 7 | |||
| 8 | #include "krykov_e_sobel_op/common/include/common.hpp" | ||
| 9 | |||
| 10 | namespace krykov_e_sobel_op { | ||
| 11 | |||
| 12 |
1/2✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
|
24 | KrykovESobelOpSEQ::KrykovESobelOpSEQ(const InType &in) { |
| 13 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 14 | GetInput() = in; | ||
| 15 | GetOutput().clear(); | ||
| 16 | 24 | } | |
| 17 | |||
| 18 | 24 | bool KrykovESobelOpSEQ::ValidationImpl() { | |
| 19 | const auto &img = GetInput(); | ||
| 20 |
3/6✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 24 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 24 times.
|
24 | return img.width > 2 && img.height > 2 && static_cast<int>(img.data.size()) == img.width * img.height; |
| 21 | } | ||
| 22 | |||
| 23 | 24 | bool KrykovESobelOpSEQ::PreProcessingImpl() { | |
| 24 | const auto &img = GetInput(); | ||
| 25 | |||
| 26 | 24 | width_ = img.width; | |
| 27 | 24 | height_ = img.height; | |
| 28 | |||
| 29 | 24 | grayscale_.resize(static_cast<size_t>(width_) * static_cast<size_t>(height_)); | |
| 30 | // RGB → grayscale | ||
| 31 |
2/2✓ Branch 0 taken 384 times.
✓ Branch 1 taken 24 times.
|
408 | for (int i = 0; i < width_ * height_; ++i) { |
| 32 | 384 | const Pixel &p = img.data[i]; | |
| 33 | 384 | grayscale_[i] = static_cast<int>((0.299 * p.r) + (0.587 * p.g) + (0.114 * p.b)); | |
| 34 | } | ||
| 35 | 24 | GetOutput().assign(static_cast<size_t>(width_) * static_cast<size_t>(height_), 0); | |
| 36 | 24 | return true; | |
| 37 | } | ||
| 38 | |||
| 39 | 24 | bool KrykovESobelOpSEQ::RunImpl() { | |
| 40 | 24 | const std::array<std::array<int, 3>, 3> gx_kernel = {{{-1, 0, 1}, {-2, 0, 2}, {-1, 0, 1}}}; | |
| 41 | |||
| 42 | 24 | const std::array<std::array<int, 3>, 3> gy_kernel = {{{-1, -2, -1}, {0, 0, 0}, {1, 2, 1}}}; | |
| 43 | |||
| 44 |
2/2✓ Branch 0 taken 48 times.
✓ Branch 1 taken 24 times.
|
72 | for (int row = 1; row < height_ - 1; ++row) { |
| 45 |
2/2✓ Branch 0 taken 96 times.
✓ Branch 1 taken 48 times.
|
144 | for (int col = 1; col < width_ - 1; ++col) { |
| 46 | int gx = 0; | ||
| 47 | int gy = 0; | ||
| 48 | |||
| 49 |
2/2✓ Branch 0 taken 288 times.
✓ Branch 1 taken 96 times.
|
384 | for (int ky = -1; ky <= 1; ++ky) { |
| 50 |
2/2✓ Branch 0 taken 864 times.
✓ Branch 1 taken 288 times.
|
1152 | for (int kx = -1; kx <= 1; ++kx) { |
| 51 | 864 | int pixel = grayscale_[((row + ky) * width_) + (col + kx)]; | |
| 52 | 864 | gx += pixel * gx_kernel.at(ky + 1).at(kx + 1); | |
| 53 | 864 | gy += pixel * gy_kernel.at(ky + 1).at(kx + 1); | |
| 54 | } | ||
| 55 | } | ||
| 56 | |||
| 57 | 96 | int magnitude = static_cast<int>(std::sqrt(static_cast<double>((gx * gx) + (gy * gy)))); | |
| 58 | |||
| 59 | 96 | GetOutput()[(row * width_) + col] = magnitude; | |
| 60 | } | ||
| 61 | } | ||
| 62 | |||
| 63 | 24 | return true; | |
| 64 | } | ||
| 65 | |||
| 66 | 24 | bool KrykovESobelOpSEQ::PostProcessingImpl() { | |
| 67 | 24 | return true; | |
| 68 | } | ||
| 69 | |||
| 70 | } // namespace krykov_e_sobel_op | ||
| 71 |