diff --git a/src/seam-carving.cpp b/src/seam-carving.cpp index c090059..78ae877 100644 --- a/src/seam-carving.cpp +++ b/src/seam-carving.cpp @@ -37,7 +37,7 @@ void export_image(const char *filename, const void *data, int width, int height, #define compute_energy_for_pixel( \ source, width, height, i, j, \ nbChannels, /* computes the energy at pixel i,j, i.e. energy[width*j+i]*/ \ - nbColorChannels, dest) \ + nbColorChannels, dest) { \ auto indexPixel = (nbChannels) * (width * (j) + (i)); \ auto indexPixel_up = \ ((j) - 1 > 0) ? (nbChannels) * (width * ((j) - 1) + (i)) : indexPixel; \ @@ -132,7 +132,7 @@ void export_image(const char *filename, const void *data, int width, int height, std::cerr << "no implementation found for function \"" << function << "\"" \ << std::endl; \ exit(1); \ - }; + }} @@ -324,9 +324,11 @@ void recompute_energy_along_seam( int y = vertical ? j0 + j_offset : (i0 + i_offset); if (((0 < (i0 + i_offset)) && ((i0 + i_offset) < dim_large - 1)) && (((0 < j0 + j_offset) && (j0 + j_offset < dim_long)))) { - compute_energy_for_pixel(carved_img, newWidth, newHeight, x, y, - nbChannels, nbColorChannels, - output_energy[width * y + x].second); + // if the pixel is to be removed, we keep the energy at 0. + if (output_energy[width * y + x].first != 0) + compute_energy_for_pixel(carved_img, newWidth, newHeight, x, y, + nbChannels, nbColorChannels, + output_energy[width * y + x].second); } } } diff --git a/src/utils.cpp b/src/utils.cpp index 7853250..62a3f54 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -32,6 +32,9 @@ std::vector> mask_energy(std::vector energy, std::vector> output(width*height); for (auto i=0; i < width*height; i++) { + if (mask[i] == 0) // We want to remove the pixel + energy[i] = 0.; + output[i] = {mask[i], energy[i]}; }