10namespace morphology_operations {
17inline std::vector<std::vector<int32_t>> dilate(
const std::vector<std::vector<int32_t>>& image) {
20 int height = img._height();
21 int width = img._width();
22 Image resulted_img(height, width);
23 for (
int x = 1; x < height - 1; x++) {
24 for (
int y = 1; y < width - 1; y++) {
25 if (!img.get_point(x - 1, y) || !img.get_point(x + 1, y) || !img.get_point(x, y - 1) ||
26 !img.get_point(x, y + 1)) {
27 resulted_img.set_point(x, y, 255);
29 img.set_point(x, y, image[x][y]);
33 return resulted_img.get_2d_array();
42inline std::vector<std::vector<int32_t>> erote(
const std::vector<std::vector<int32_t>>& image) {
45 int height = img._height();
46 int width = img._width();
47 Image resulted_img(height, width);
48 for (
int x = 1; x < height - 1; x++) {
49 for (
int y = 1; y < width - 1; y++) {
50 if (!img.get_point(x - 1, y) || !img.get_point(x + 1, y) ||
51 !img.get_point(x, y - 1) && !img.get_point(x, y + 1)) {
52 resulted_img.set_point(x, y, 0);
54 resulted_img.set_point(x, y, image[x][y]);
58 return resulted_img.get_2d_array();
67inline std::vector<std::vector<int32_t>> open(
const std::vector<std::vector<int32_t>>& image) {
70 std::vector<std::vector<int32_t>> resulted_img = erote(image);
71 resulted_img = dilate(resulted_img);
81inline std::vector<std::vector<int32_t>> close(
const std::vector<std::vector<int32_t>>& image) {
84 std::vector<std::vector<int32_t>> resulted_img = dilate(image);
85 resulted_img = erote(resulted_img);