| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "batkov_f_image_smoothing/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include <algorithm> | ||
| 4 | #include <cmath> | ||
| 5 | #include <cstddef> | ||
| 6 | #include <cstdint> | ||
| 7 | #include <utility> | ||
| 8 | #include <vector> | ||
| 9 | |||
| 10 | #include "batkov_f_image_smoothing/common/include/common.hpp" | ||
| 11 | |||
| 12 | namespace batkov_f_image_smoothing { | ||
| 13 | |||
| 14 |
1/2✓ Branch 1 taken 32 times.
✗ Branch 2 not taken.
|
32 | BatkovFImageSmoothingSEQ::BatkovFImageSmoothingSEQ(const InType &in) { |
| 15 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 16 | GetInput() = in; | ||
| 17 | 32 | GetOutput() = Image(); | |
| 18 | 32 | } | |
| 19 | |||
| 20 |
1/2✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
|
32 | bool BatkovFImageSmoothingSEQ::ValidationImpl() { |
| 21 |
3/6✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 32 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 32 times.
|
32 | return (!GetInput().data.empty()) && (GetInput().width > 0) && (GetInput().height > 0); |
| 22 | } | ||
| 23 | |||
| 24 | 32 | bool BatkovFImageSmoothingSEQ::PreProcessingImpl() { | |
| 25 | size_t size = 5; | ||
| 26 | float sigma = 1.0F; | ||
| 27 | |||
| 28 | 32 | gaussian_kernel_.resize(size); | |
| 29 |
2/2✓ Branch 0 taken 160 times.
✓ Branch 1 taken 32 times.
|
192 | for (auto &v : gaussian_kernel_) { |
| 30 | 160 | v.resize(size); | |
| 31 | } | ||
| 32 | |||
| 33 | float sum = 0.0F; | ||
| 34 | size_t half = size / 2; | ||
| 35 | |||
| 36 |
2/2✓ Branch 0 taken 160 times.
✓ Branch 1 taken 32 times.
|
192 | for (size_t i = 0; i < size; i++) { |
| 37 |
2/2✓ Branch 0 taken 800 times.
✓ Branch 1 taken 160 times.
|
960 | for (size_t j = 0; j < size; j++) { |
| 38 | 800 | size_t x = i - half; | |
| 39 | 800 | size_t y = j - half; | |
| 40 | 800 | float value = std::exp((-static_cast<float>((x * x) + (y * y)) / (2 * sigma * sigma))); | |
| 41 | 800 | gaussian_kernel_[i][j] = value; | |
| 42 | 800 | sum += value; | |
| 43 | } | ||
| 44 | } | ||
| 45 | |||
| 46 |
2/2✓ Branch 0 taken 160 times.
✓ Branch 1 taken 32 times.
|
192 | for (size_t i = 0; i < size; i++) { |
| 47 |
2/2✓ Branch 0 taken 800 times.
✓ Branch 1 taken 160 times.
|
960 | for (size_t j = 0; j < size; j++) { |
| 48 | 800 | gaussian_kernel_[i][j] /= sum; | |
| 49 | } | ||
| 50 | } | ||
| 51 | |||
| 52 | 32 | return true; | |
| 53 | } | ||
| 54 | |||
| 55 | 32 | bool BatkovFImageSmoothingSEQ::RunImpl() { | |
| 56 | auto &img = GetInput(); | ||
| 57 | 32 | size_t width = img.width; | |
| 58 | 32 | size_t height = img.height; | |
| 59 | 32 | size_t channels = img.channels; | |
| 60 | const auto &img_data = img.data; | ||
| 61 | |||
| 62 | 32 | std::vector<uint8_t> temp(width * height * channels); | |
| 63 | |||
| 64 | size_t kernel_size = 5; | ||
| 65 | size_t half = kernel_size / 2; | ||
| 66 | |||
| 67 |
2/2✓ Branch 0 taken 4080 times.
✓ Branch 1 taken 32 times.
|
4112 | for (size_t y_px = 0; y_px < height; y_px++) { |
| 68 |
2/2✓ Branch 0 taken 920800 times.
✓ Branch 1 taken 4080 times.
|
924880 | for (size_t x_px = 0; x_px < width; x_px++) { |
| 69 |
2/2✓ Branch 0 taken 2762400 times.
✓ Branch 1 taken 920800 times.
|
3683200 | for (size_t ch = 0; ch < channels; ch++) { |
| 70 | float value = 0.0F; | ||
| 71 | |||
| 72 |
2/2✓ Branch 0 taken 13812000 times.
✓ Branch 1 taken 2762400 times.
|
16574400 | for (size_t ky = 0; ky < kernel_size; ky++) { |
| 73 |
2/2✓ Branch 0 taken 69060000 times.
✓ Branch 1 taken 13812000 times.
|
82872000 | for (size_t kx = 0; kx < kernel_size; kx++) { |
| 74 | 69060000 | size_t px = x_px + kx - half; | |
| 75 | 69060000 | size_t py = y_px + ky - half; | |
| 76 | |||
| 77 |
4/4✓ Branch 0 taken 367200 times.
✓ Branch 1 taken 68692800 times.
✓ Branch 2 taken 68876400 times.
✓ Branch 3 taken 183600 times.
|
69427200 | px = std::max<size_t>(0, std::min(px, width - 1)); |
| 78 |
4/4✓ Branch 0 taken 367200 times.
✓ Branch 1 taken 68692800 times.
✓ Branch 2 taken 68876400 times.
✓ Branch 3 taken 183600 times.
|
69427200 | py = std::max<size_t>(0, std::min(py, height - 1)); |
| 79 | |||
| 80 | 69060000 | uint8_t pixel_value = img_data[((py * width + px) * channels) + ch]; | |
| 81 | 69060000 | value += static_cast<float>(pixel_value) * gaussian_kernel_[ky][kx]; | |
| 82 | } | ||
| 83 | } | ||
| 84 | |||
| 85 | 2762400 | temp[((y_px * width + x_px) * channels) + ch] = static_cast<uint8_t>(value); | |
| 86 | } | ||
| 87 | } | ||
| 88 | } | ||
| 89 | |||
| 90 | 32 | GetOutput().data = std::move(temp); | |
| 91 | 32 | GetOutput().width = width; | |
| 92 | 32 | GetOutput().height = height; | |
| 93 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
|
32 | GetOutput().channels = channels; |
| 94 | 32 | return true; | |
| 95 | } | ||
| 96 | |||
| 97 | 32 | bool BatkovFImageSmoothingSEQ::PostProcessingImpl() { | |
| 98 | 32 | return true; | |
| 99 | } | ||
| 100 | |||
| 101 | } // namespace batkov_f_image_smoothing | ||
| 102 |