recomputation of energy seems to work better
This commit is contained in:
parent
3e96a3df05
commit
8612f2f0f1
@ -252,22 +252,35 @@ void update_energy_along_seam(std::vector<int> opt_seam,
|
|||||||
std::copy(energy.begin(), energy.end(), output_energy.begin());
|
std::copy(energy.begin(), energy.end(), output_energy.begin());
|
||||||
} else {
|
} else {
|
||||||
if (vertical) { // Vertical seam
|
if (vertical) { // Vertical seam
|
||||||
for (auto j = 0; j < height; j++) {
|
for (auto j0 = 0; j0 < height; j0++) {
|
||||||
for (auto i = -1; i < 2; i++) {
|
auto i0 = opt_seam[j0];
|
||||||
if ((0 < (opt_seam[j] + i)) && ((opt_seam[j] + i) < width - 1)) {
|
// recompute on a square around i0,j0
|
||||||
compute_energy_for_pixel(output_img, (width - 1), height,
|
for (auto i_offset = -max_step - 2; i_offset <= max_step + 2;
|
||||||
(opt_seam[j] + i), j, nbChannels,
|
i_offset++) {
|
||||||
nbColorChannels, output_energy);
|
for (auto j_offset = -max_step - 2; j_offset <= max_step + 2;
|
||||||
|
j_offset++) {
|
||||||
|
if (((0 < (i0 + i_offset)) && ((i0 + i_offset) < width - 1)) &&
|
||||||
|
((0 < j0 + j_offset) && (j0 + j_offset < (height)))) {
|
||||||
|
compute_energy_for_pixel(
|
||||||
|
output_img, (width - 1), height, (i0 + i_offset),
|
||||||
|
(j0 + j_offset), nbChannels, nbColorChannels, output_energy);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (auto i = 0; i < width; i++) {
|
for (auto i0 = 0; i0 < width; i0++) {
|
||||||
for (auto j = -1; j < 2; j++) {
|
auto j0 = opt_seam[i0];
|
||||||
if ((0 < (opt_seam[i] + j)) && ((opt_seam[i] + j) < height - 1)) {
|
for (auto j_offset = -max_step - 2; j_offset <= max_step + 2;
|
||||||
compute_energy_for_pixel(output_img, width, height - 1, i,
|
j_offset++) {
|
||||||
(opt_seam[i] + j), nbChannels,
|
for (auto i_offset = -max_step - 2; i_offset <= max_step + 2;
|
||||||
nbColorChannels, output_energy);
|
i_offset++) {
|
||||||
|
if (((0 < (j0 + j_offset)) && ((j0 + j_offset) < height - 1)) &&
|
||||||
|
((0 < (i0 + i_offset)) && (i0 + i_offset) < width)) {
|
||||||
|
compute_energy_for_pixel(
|
||||||
|
output_img, width, height - 1, (i0 + i_offset),
|
||||||
|
(j0 + j_offset), nbChannels, nbColorChannels, output_energy);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -463,8 +476,8 @@ int main(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
nbSeams = std::min(
|
nbSeams = std::min(
|
||||||
nbSeams, vertical
|
nbSeams,
|
||||||
? width - 1
|
vertical ? width - 1
|
||||||
: height - 1); // We want to keep at least one row or column
|
: height - 1); // We want to keep at least one row or column
|
||||||
|
|
||||||
auto result = seam_carving(source, width, height, nbChannels, nbSeams,
|
auto result = seam_carving(source, width, height, nbChannels, nbSeams,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user