diff --git a/src/seam-carving.cpp b/src/seam-carving.cpp index cd60c6a..4782b5f 100644 --- a/src/seam-carving.cpp +++ b/src/seam-carving.cpp @@ -171,7 +171,7 @@ std::vector optimal_seam(std::vector energy, int width, int height, //* Find an end of the minimal connected vertical/horizontal seam for (auto i = 0; i < dim_large; i++) { - dyn_energy[i] = energy[i]; + dyn_energy[i] = energy[vertical ? i : i*width]; } for (auto i = 1; i < dim_long; i++) { // Propagate dyn_energy @@ -446,7 +446,7 @@ auto seam_carving(unsigned char *source, int width, int height, int nbChannels, nbChannels, nbColorChannels, vertical); if (until_mask_removal && - !does_seam_remove_mask(masked_energy, width, height, nbChannels, opt_seam, + !does_seam_remove_mask(masked_energy, curWidth, curHeight, nbChannels, opt_seam, vertical)) break; diff --git a/src/utils.cpp b/src/utils.cpp index 357b4d5..7853250 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -22,7 +22,7 @@ bool does_seam_remove_mask(std::vector> energy, int width, int dim_long = vertical ? height : width; for (int i=0; i < dim_long; i++) { - if (std::get<0>(energy[im_index(i, opt_seam[i])]) == 0) return true; + if (energy[im_index(i, opt_seam[i])].first == 0) return true; } return false; } @@ -50,6 +50,9 @@ std::pair operator+(std::pair& p1, std::pair void operator+=(std::pair& p1, std::pair& p2) { p1 = p1+p2; } +bool operator==(std::pair& p1, std::pair& p2) { + return (p1.first==p2.first && p1.second == p2.second); +} std::string str_of_e(std::pair energy) { std::stringstream ss; diff --git a/src/utils.hpp b/src/utils.hpp index 04be50a..588661a 100644 --- a/src/utils.hpp +++ b/src/utils.hpp @@ -4,12 +4,9 @@ // : dim_long, b : dim_large #define im_index(a, b) (vertical ? (width * a + b) : (width * b + a)) +// Check if two floats are nearly equal bool nearly_equal(float a, float b); -std::pair operator+(std::pair& p1, std::pair& p2); - -void operator+=(std::pair& p1, std::pair& p2); - bool does_seam_remove_mask(std::vector> energy, int width, int height, int nbChannels, std::vector opt_seam, bool vertical); @@ -17,6 +14,15 @@ std::vector> mask_energy(std::vector energy, int width, int height, unsigned char* mask); +//* Operators overwrites + +std::pair operator+(std::pair& p1, std::pair& p2); + +void operator+=(std::pair& p1, std::pair& p2); + +bool operator==(std::pair& p1, std::pair& p2); + + // Unfortunately, std::cout << (std::pair<>) does not work and can't be rewritten std::string str_of_e(std::pair energy); std::string str_of_e(float energy); @@ -31,4 +37,26 @@ namespace limits { return {3, std::numeric_limits::max()}; } }; + + struct null_energy { + template operator T() { + return 0.; + } + operator std::pair() { + return {0, limits::null_energy()}; + } + }; +} + +template +void compute_seam_tot(std::vector opt_seam, std::vector energy, int width, int height, bool vertical) { + int dim_long = vertical ? height : width; + + + T sum = limits::null_energy(); + for (int i=0; i < dim_long; i++) { + sum += energy[im_index(i, opt_seam[i])]; + // std::cout << str_of_e(sum); + } + std::cout << "Computed sum: " << str_of_e(sum) << std::endl; } \ No newline at end of file