AlgoPlus v0.1.0
Loading...
Searching...
No Matches
laplacian_point_detect.h
1#ifndef LAPLACIAN_POINT_DETECT_H
2#define LAPLACIAN_POINT_DETECT_H
3
4#ifdef __cplusplus
5#include <iostream>
6#include <vector>
7#include "../image.h"
8#endif
9
10namespace laplacian_detection {
19inline std::vector<std::vector<int32_t>>
20apply_point_detection(const std::vector<std::vector<int32_t>> img, const double threshold) {
21 int height = img.size();
22 int width = img[0].size();
23 std::vector<std::vector<int32_t>> kernel = {{-1, -1, -1}, {-1, 8, -1}, {-1, -1, -1}};
24 Image resulted_img(img);
25 for (int x = 1; x < height - 1; x++) {
26 for (int y = 1; y < width - 1; y++) {
27 int padding = img[x - 1][y - 1] + img[x][y - 1] + img[x + 1][y + 1] + img[x][y + 1] +
28 img[x + 1][y] + img[x + 1][y - 1] + img[x - 1][y];
29 if (8 * img[x][y] - padding >= threshold) {
30 resulted_img.add_2_point(x, y, img[x][y] * kernel[1][1]);
31 if (y - 1 >= 0) {
32 resulted_img.add_2_point(x, y, img[x][y - 1] * kernel[1][0]);
33 }
34 if (y + 1 < width) {
35 resulted_img.add_2_point(x, y, img[x][y + 1] * kernel[1][2]);
36 if (x + 1 < height) {
37 resulted_img.add_2_point(x, y, img[x + 1][y + 1] * kernel[2][2]);
38 }
39 }
40 if (x - 1 >= 0) {
41 resulted_img.add_2_point(x, y, img[x - 1][y] * kernel[0][1]);
42 if (y + 1 < width) {
43 resulted_img.add_2_point(x, y, img[x - 1][y + 1] * kernel[0][2]);
44 }
45 if (y - 1 >= 0) {
46 resulted_img.add_2_point(x, y, img[x - 1][y - 1] * kernel[0][0]);
47 }
48 }
49 if (x + 1 < height) {
50 resulted_img.add_2_point(x, y, img[x + 1][y] * kernel[2][1]);
51 if (y - 1 >= 0) {
52 resulted_img.add_2_point(x, y, img[x + 1][y - 1] * kernel[2][0]);
53 }
54 }
55 } else {
56 resulted_img.set_point(x, y, 255);
57 }
58 }
59 }
60 return resulted_img.get_2d_array();
61}
62} // namespace laplacian_detection
63
64#endif
std::pair< std::vector< std::vector< int32_t > >, std::vector< std::vector< int32_t > > > kernel()
Definition sobel_operator.h:24