From affb89c76e42a3220d46cab875afbfa36dea72ab Mon Sep 17 00:00:00 2001 From: augustin64 Date: Wed, 2 Apr 2025 17:41:58 +0200 Subject: [PATCH] Add templates back. Remove --energy-recompute-all --- src/seam-carving.cpp | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/seam-carving.cpp b/src/seam-carving.cpp index a8d7586..aadebb1 100644 --- a/src/seam-carving.cpp +++ b/src/seam-carving.cpp @@ -15,7 +15,6 @@ // Global flags bool silent = false; bool test_energy = false; -bool energy_recompute_all = false; int max_step = 1; // Get index for any table indexed by [width*(i : height) + (j : width)], but a @@ -34,6 +33,10 @@ std::pair operator+(std::pair& p1, std::pair }; } +void operator+=(std::pair& p1, std::pair& p2) { + p1 = p1+p2; +} + void export_image(const char *filename, const void *data, int width, int height, int nbChannels) { if (!silent) @@ -117,7 +120,7 @@ template std::vector optimal_seam(std::vector energy, int w dyn_energy[dim_large * i + j], dyn_energy[dim_large * (i - 1) + k] ); } - dyn_energy[dim_large * i + j] = dyn_energy[dim_large * i + j]+energy[im_index(i, j)]; + dyn_energy[dim_large * i + j] += energy[im_index(i, j)]; } } @@ -255,11 +258,11 @@ void recompute_energy_along_seam( /** Carves an image and its energy by one seam, and recomputes the energy. Returns the optimal seam used */ -//template +template std::vector carving_step(const std::vector source_img, - std::vector> source_energy, + std::vector source_energy, std::vector &output_img, - std::vector> &output_energy, int width, + std::vector &output_energy, int width, int height, int nbChannels, int nbColorChannels, bool vertical) { @@ -368,11 +371,11 @@ void seam_carving(unsigned char *source, int width, int height, int nbChannels, source_img, masked_energy, output_img, output_masked_energy, curWidth, curHeight, nbChannels, nbColorChannels, vertical ); - //} else { - // opt_seam = carving_step( - // source_img, source_energy, output_img, output_energy, - // curWidth, curHeight, nbChannels, nbColorChannels, vertical - // ); + } else { + opt_seam = carving_step( + source_img, source_energy, output_img, output_energy, + curWidth, curHeight, nbChannels, nbColorChannels, vertical + ); } std::copy(output_img.begin(), output_img.end(), source_img.begin()); std::copy(output_energy.begin(), output_energy.end(), @@ -440,8 +443,6 @@ int main(int argc, char **argv) { app.add_flag("--silent", silent, "No verbose messages"); app.add_flag("--test-energy", test_energy, "Don't resize image, just try the specified energy function"); - app.add_flag("--energy-recompute-all", energy_recompute_all, - "recompute the whole energy at each step"); CLI11_PARSE(app, argc, argv); // Image loading