Set energy to {0, 0.} for negatively-masked pixels

This commit is contained in:
augustin64 2025-04-04 12:27:38 +02:00
parent 4b6f123974
commit a3019975c7
2 changed files with 10 additions and 5 deletions

View File

@ -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);
}
}
}

View File

@ -32,6 +32,9 @@ std::vector<std::pair<int, float>> mask_energy(std::vector<float> energy,
std::vector<std::pair<int, float>> 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]};
}