diff --git a/src/seam-carving.cpp b/src/seam-carving.cpp index 6ab287c..511872a 100644 --- a/src/seam-carving.cpp +++ b/src/seam-carving.cpp @@ -154,29 +154,17 @@ std::vector optimal_seam(std::vector energy, int width, int height, return result; } - void remove_seam(const std::vector source, std::vector &output, int width, int height, - int nbChannels, bool vertical, const std::vector seam) -{ - /* remove the given seam from the image, the result is in output*/ - std::vector blacklist(width * height); - + int nbChannels, bool vertical, const std::vector seam) { + // remove the given seam from the image, the result is in output int dim_large = vertical ? width : height; int dim_long = vertical ? height : width; - for (auto k = 0; k < width * height; k++) { - blacklist[k] = false; - } - for (auto i = 0; i < dim_long; i++) { - int index = vertical ? seam[i] + i * width : i + width * seam[i]; - blacklist[index] = true; - } - for (auto i = 0; i < dim_long; i++) { int cur_j = 0; for (auto j = 0; cur_j < dim_large - 1 && j < dim_large; j++) { - if (!blacklist[im_index(i, j)]) { + if (seam[i] != j) { int out_pixelIndex = nbChannels * (vertical ? ((width - 1) * i + cur_j) : (width * cur_j + i)); int src_pixelIndex = nbChannels * im_index(i, j); @@ -187,25 +175,18 @@ void remove_seam(const std::vector source, } } } - - } + std::vector carving_step(const std::vector source, + std::vector energy, std::vector &output, int width, int height, int nbChannels, bool vertical) { /** Carves an image by one seam. Returns the optimal seam used */ - std::vector energy = energy_e1(source, width, height, nbChannels); std::vector opt_seam = optimal_seam(energy, width, height, vertical); remove_seam(source, output, width, height, nbChannels, vertical, opt_seam); return opt_seam; } - - - - - - void seam_carving(unsigned char *source, int width, int height, int nbChannels, const char *out_filename, int nbSeams, bool vertical, bool test_energy = false) { @@ -215,18 +196,18 @@ void seam_carving(unsigned char *source, int width, int height, int nbChannels, int dim_large = vertical ? width : height; int dim_long = vertical ? height : width; + // dim_long=longueur des seam - std::vector carve_output( - width * height * - nbChannels); // Receives at each step the newly carved image - std::vector source_img( - width * height * nbChannels); // Contains at each step the carved image - std::vector complete_blacklist( - width * height); // Contains all removed pixels, for "test_energy" - std::vector - ini_energy; // Contains the initial energy, only for "test_energy" - std::vector test_energy_output( - width * height * nbChannels); // Final output for "test_energy" + std::vector carve_output(width * height * nbChannels); + // Receives at each step the newly carved image + std::vector source_img(width * height * nbChannels); + // Contains at each step the carved image + std::vector complete_blacklist(width * height); + // Contains all removed pixels, for "test_energy" + std::vector ini_energy; + // Contains the initial energy, only for "test_energy" + std::vector test_energy_output(width * height * nbChannels); + // Final output for "test_energy" for (auto i = 0; i < width * height * nbChannels; i++) { source_img[i] = source[i]; @@ -253,8 +234,11 @@ void seam_carving(unsigned char *source, int width, int height, int nbChannels, SimpleProgressBar::ProgressBar bar(nbSeams); for (auto seam = 0; seam < nbSeams; seam++) { - std::vector opt_seam = carving_step(source_img, carve_output, curWidth, - curHeight, nbChannels, vertical); + std::vector energy = + energy_e1(source_img, width, height, nbChannels); + std::vector opt_seam = + carving_step(source_img, energy, carve_output, curWidth, curHeight, + nbChannels, vertical); std::copy(carve_output.begin(), carve_output.end(), source_img.begin()); if (vertical) // We just reduced the dimension @@ -282,7 +266,7 @@ void seam_carving(unsigned char *source, int width, int height, int nbChannels, bar.increment(); bar.print(); } - std::cout << std::endl; + // std::cout << std::endl; if (test_energy) { export_image(out_filename, test_energy_output.data(), width, height,