Use valid limits
This commit is contained in:
parent
affb89c76e
commit
5a9eb05b6a
@ -37,6 +37,18 @@ void operator+=(std::pair<int, float>& p1, std::pair<int, float>& p2) {
|
|||||||
p1 = p1+p2;
|
p1 = p1+p2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace limits {
|
||||||
|
struct max_energy {
|
||||||
|
template<class T> operator T() {
|
||||||
|
return std::numeric_limits<T>::max();
|
||||||
|
}
|
||||||
|
operator std::pair<int, float>() {
|
||||||
|
return {2, std::numeric_limits<float>::max()};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void export_image(const char *filename, const void *data, int width, int height,
|
void export_image(const char *filename, const void *data, int width, int height,
|
||||||
int nbChannels) {
|
int nbChannels) {
|
||||||
if (!silent)
|
if (!silent)
|
||||||
@ -110,7 +122,7 @@ template <typename T> std::vector<int> optimal_seam(std::vector<T> energy, int w
|
|||||||
|
|
||||||
for (auto i = 1; i < dim_long; i++) { // Propagate dyn_energy
|
for (auto i = 1; i < dim_long; i++) { // Propagate dyn_energy
|
||||||
for (auto j = 0; j < dim_large; j++) {
|
for (auto j = 0; j < dim_large; j++) {
|
||||||
dyn_energy[dim_large * i + j] = std::numeric_limits<T>::max();
|
dyn_energy[dim_large * i + j] = limits::max_energy();
|
||||||
int lower_bound = std::max(j - max_step, 0);
|
int lower_bound = std::max(j - max_step, 0);
|
||||||
int upper_bound = std::min(j + max_step, dim_large - 1);
|
int upper_bound = std::min(j + max_step, dim_large - 1);
|
||||||
|
|
||||||
@ -127,7 +139,8 @@ template <typename T> std::vector<int> optimal_seam(std::vector<T> energy, int w
|
|||||||
std::vector<int> result(dim_long);
|
std::vector<int> result(dim_long);
|
||||||
// Find the seam end
|
// Find the seam end
|
||||||
int min_idx = -1;
|
int min_idx = -1;
|
||||||
T min_val = std::numeric_limits<T>::max();
|
T min_val = limits::max_energy();
|
||||||
|
|
||||||
for (auto j = 0; j < dim_large; j++) {
|
for (auto j = 0; j < dim_large; j++) {
|
||||||
if (min_val > dyn_energy[dim_large * (dim_long - 1) + j]) {
|
if (min_val > dyn_energy[dim_large * (dim_long - 1) + j]) {
|
||||||
min_idx = j;
|
min_idx = j;
|
||||||
@ -148,7 +161,7 @@ template <typename T> std::vector<int> optimal_seam(std::vector<T> energy, int w
|
|||||||
(dyn_energy[(i - 1) * dim_large + idx] + energy[im_index(i, min_idx)] == \
|
(dyn_energy[(i - 1) * dim_large + idx] + energy[im_index(i, min_idx)] == \
|
||||||
min_val)
|
min_val)
|
||||||
|
|
||||||
// This is not the nicest way to do thiss but we want to check in priority
|
// This is not the nicest way to do this but we want to check in priority
|
||||||
// at the center to have straight seams
|
// at the center to have straight seams
|
||||||
bool found = false;
|
bool found = false;
|
||||||
if (is_next_idx(min_idx)) {
|
if (is_next_idx(min_idx)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user