diff --git a/src/machine_learning/image/filters/average_filter.h b/src/machine_learning/image/filters/average_filter.h index 680d9ac9..146eb75f 100644 --- a/src/machine_learning/image/filters/average_filter.h +++ b/src/machine_learning/image/filters/average_filter.h @@ -23,7 +23,7 @@ namespace avg_filter { int width = img._width(); Image resulted_img(height, width); std::vector > kernel = {{1.0/9, 1.0/9, 1.0/9}, {1.0/9, 1.0/9, 1.0/9}, {1.0/9, 1.0/9, 1.0/9}}; - return img.apply_filter2d_float(kernel).get_2d_array(); + return img.apply_filter2d(kernel).get_2d_array(); } } diff --git a/src/machine_learning/image/image.h b/src/machine_learning/image/image.h index 297d1016..5c25d452 100644 --- a/src/machine_learning/image/image.h +++ b/src/machine_learning/image/image.h @@ -1,6 +1,7 @@ #ifndef img_H #define img_H +#include #ifdef __cplusplus #include #include @@ -274,11 +275,11 @@ class Image{ } /** - * @brief apply_filter2d_float function + * @brief apply_filter2d function * @param filter: 3x3 kernel with floats to be applied to the image * @return vector > the resulted image */ - Image apply_filter2d_float(std::vector > &filter) const { + Image apply_filter2d(std::vector > &filter) const { assert(filter.size() == 3 && filter[0].size() == 3); Image resulted_img(height, width); for(int x = 0; x void { + for(int i = start_at; i<=end_at && i > img = {{1,0,0}, {1,0,0}, {0,0,1}, {0,0,0}}; + std::vector > img = {{1,0,0}, {1,0,0}, {0,0,1}, {0,0,0}}; Image i(img); REQUIRE(i.get_point(0, 0) == 1); REQUIRE(i.get_point(0, 1) == 0); } TEST_CASE("Testing setting point at a 2d image") { - std::vector > img = {{1,0,0}, {1,0,0}, {0,0,1}, {0,0,0}}; + std::vector > img = {{1,0,0}, {1,0,0}, {0,0,1}, {0,0,0}}; Image i(img); REQUIRE(i.get_point(0, 0) == 1); @@ -34,7 +34,7 @@ TEST_CASE("Testing setting point at a 2d image") { } TEST_CASE("Testing adding to a point in 2d image") { - std::vector > img = {{1,0,0}, {1,0,0}, {0,0,1}, {0,0,0}}; + std::vector > img = {{1,0,0}, {1,0,0}, {0,0,1}, {0,0,0}}; Image i(img); REQUIRE(i.get_point(1, 1) == 0); @@ -74,16 +74,38 @@ TEST_CASE("Testing sub 2 2d images") { TEST_CASE("Testing multiplying 2 2d images") { std::vector > img = {{0, 0, 0}, {1, 1, 1}, {0, 0, 0}}; std::vector > img2 = {{0, 0, 0}, {1, 1, 1}, {0, 0, 0}}; - Image i1(img), i2(img2); + Image i1(img), i2(img2); i1 = i1.mul(i2); REQUIRE(i1.get_2d_array() == img2); } TEST_CASE("Testing applying 2d filter") { std::vector > img = {{1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}}; - std::vector > kernel = {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}; + std::vector > kernel = {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}; std::vector > check(img.size(), std::vector(img[0].size(), 0)); Image i(img); i = i.apply_filter2d(kernel); REQUIRE(i.get_2d_array() == check); + + std::vector > kernel2 = { {1.0/9, 1.0/9, 1.0/9}, {1.0/9, 1.0/9, 1.0/9}, {1.0/9, 1.0/9, 1.0/9} }; + + CHECK_NOTHROW(i = i.apply_filter2d(kernel2)); +} + +TEST_CASE("Testing operator << for image class") { + std::vector > img = {{1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}}; + + Image i(img); + + CHECK_NOTHROW(std::cout << i << '\n'); + + std::vector > img2(100, std::vector(100)); + + for(int i = 0; i<100; i++) { + std::iota(img2[i].begin(), img2[i].end(), 1); + } + + Image i2(img2); + + CHECK_NOTHROW(std::cout << i2 << '\n'); }