Merge branch 'main' of gitlab.aliens-lyon.fr:alucas03/seam-carving
This commit is contained in:
commit
56df0521b3
BIN
imgs/ign-mask.jpg
Normal file
BIN
imgs/ign-mask.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 33 KiB |
BIN
imgs/ign.png
Normal file
BIN
imgs/ign.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.4 MiB |
@ -171,7 +171,7 @@ std::vector<int> optimal_seam(std::vector<T> energy, int width, int height,
|
|||||||
|
|
||||||
//* Find an end of the minimal connected vertical/horizontal seam
|
//* Find an end of the minimal connected vertical/horizontal seam
|
||||||
for (auto i = 0; i < dim_large; i++) {
|
for (auto i = 0; i < dim_large; i++) {
|
||||||
dyn_energy[i] = energy[i];
|
dyn_energy[i] = energy[vertical ? i : i*width];
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto i = 1; i < dim_long; i++) { // Propagate dyn_energy
|
for (auto i = 1; i < dim_long; i++) { // Propagate dyn_energy
|
||||||
@ -446,7 +446,7 @@ auto seam_carving(unsigned char *source, int width, int height, int nbChannels,
|
|||||||
nbChannels, nbColorChannels, vertical);
|
nbChannels, nbColorChannels, vertical);
|
||||||
|
|
||||||
if (until_mask_removal &&
|
if (until_mask_removal &&
|
||||||
!does_seam_remove_mask(masked_energy, width, height, nbChannels, opt_seam,
|
!does_seam_remove_mask(masked_energy, curWidth, curHeight, nbChannels, opt_seam,
|
||||||
vertical))
|
vertical))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ bool does_seam_remove_mask(std::vector<std::pair<int, float>> energy, int width,
|
|||||||
int dim_long = vertical ? height : width;
|
int dim_long = vertical ? height : width;
|
||||||
|
|
||||||
for (int i=0; i < dim_long; i++) {
|
for (int i=0; i < dim_long; i++) {
|
||||||
if (std::get<0>(energy[im_index(i, opt_seam[i])]) == 0) return true;
|
if (energy[im_index(i, opt_seam[i])].first == 0) return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -50,6 +50,9 @@ std::pair<int, float> operator+(std::pair<int, float>& p1, std::pair<int, float>
|
|||||||
void operator+=(std::pair<int, float>& p1, std::pair<int, float>& p2) {
|
void operator+=(std::pair<int, float>& p1, std::pair<int, float>& p2) {
|
||||||
p1 = p1+p2;
|
p1 = p1+p2;
|
||||||
}
|
}
|
||||||
|
bool operator==(std::pair<int, float>& p1, std::pair<int, float>& p2) {
|
||||||
|
return (p1.first==p2.first && p1.second == p2.second);
|
||||||
|
}
|
||||||
|
|
||||||
std::string str_of_e(std::pair<int, float> energy) {
|
std::string str_of_e(std::pair<int, float> energy) {
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
|
@ -4,12 +4,9 @@
|
|||||||
// : dim_long, b : dim_large
|
// : dim_long, b : dim_large
|
||||||
#define im_index(a, b) (vertical ? (width * a + b) : (width * b + a))
|
#define im_index(a, b) (vertical ? (width * a + b) : (width * b + a))
|
||||||
|
|
||||||
|
// Check if two floats are nearly equal
|
||||||
bool nearly_equal(float a, float b);
|
bool nearly_equal(float a, float b);
|
||||||
|
|
||||||
std::pair<int, float> operator+(std::pair<int, float>& p1, std::pair<int, float>& p2);
|
|
||||||
|
|
||||||
void operator+=(std::pair<int, float>& p1, std::pair<int, float>& p2);
|
|
||||||
|
|
||||||
bool does_seam_remove_mask(std::vector<std::pair<int, float>> energy, int width, int height, int nbChannels,
|
bool does_seam_remove_mask(std::vector<std::pair<int, float>> energy, int width, int height, int nbChannels,
|
||||||
std::vector<int> opt_seam, bool vertical);
|
std::vector<int> opt_seam, bool vertical);
|
||||||
|
|
||||||
@ -17,6 +14,15 @@ std::vector<std::pair<int, float>> mask_energy(std::vector<float> energy,
|
|||||||
int width, int height, unsigned char* mask);
|
int width, int height, unsigned char* mask);
|
||||||
|
|
||||||
|
|
||||||
|
//* Operators overwrites
|
||||||
|
|
||||||
|
std::pair<int, float> operator+(std::pair<int, float>& p1, std::pair<int, float>& p2);
|
||||||
|
|
||||||
|
void operator+=(std::pair<int, float>& p1, std::pair<int, float>& p2);
|
||||||
|
|
||||||
|
bool operator==(std::pair<int, float>& p1, std::pair<int, float>& p2);
|
||||||
|
|
||||||
|
|
||||||
// Unfortunately, std::cout << (std::pair<>) does not work and can't be rewritten
|
// Unfortunately, std::cout << (std::pair<>) does not work and can't be rewritten
|
||||||
std::string str_of_e(std::pair<int, float> energy);
|
std::string str_of_e(std::pair<int, float> energy);
|
||||||
std::string str_of_e(float energy);
|
std::string str_of_e(float energy);
|
||||||
@ -31,4 +37,26 @@ namespace limits {
|
|||||||
return {3, std::numeric_limits<float>::max()};
|
return {3, std::numeric_limits<float>::max()};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct null_energy {
|
||||||
|
template<class T> operator T() {
|
||||||
|
return 0.;
|
||||||
|
}
|
||||||
|
operator std::pair<int, float>() {
|
||||||
|
return {0, limits::null_energy()};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void compute_seam_tot(std::vector<int> opt_seam, std::vector<T> energy, int width, int height, bool vertical) {
|
||||||
|
int dim_long = vertical ? height : width;
|
||||||
|
|
||||||
|
|
||||||
|
T sum = limits::null_energy();
|
||||||
|
for (int i=0; i < dim_long; i++) {
|
||||||
|
sum += energy[im_index(i, opt_seam[i])];
|
||||||
|
// std::cout << str_of_e(sum);
|
||||||
|
}
|
||||||
|
std::cout << "Computed sum: " << str_of_e(sum) << std::endl;
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user