Fixed decomposition loop
This commit is contained in:
parent
722d1be32e
commit
5ddb5dc39f
148
main.cpp
148
main.cpp
@ -13,11 +13,7 @@
|
|||||||
|
|
||||||
#include "Euclidean.hpp"
|
#include "Euclidean.hpp"
|
||||||
|
|
||||||
#ifdef DEBUG
|
#define NB_ITERATIONS 10
|
||||||
#include <time.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define NB_ITERATIONS 3
|
|
||||||
|
|
||||||
#define MIN(x,y) ((x)<(y)?(x):(y))
|
#define MIN(x,y) ((x)<(y)?(x):(y))
|
||||||
#define MAX(x,y) ((x)>(y)?(x):(y))
|
#define MAX(x,y) ((x)>(y)?(x):(y))
|
||||||
@ -47,21 +43,9 @@ CImg<float> decompose(const CImg<float> input)
|
|||||||
// Part 1: Finding minimas and maximas //
|
// Part 1: Finding minimas and maximas //
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
timeval tim;
|
|
||||||
double t1, t2;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
CImg<float> imgMax(inputImg.channel(0));
|
CImg<float> imgMax(inputImg.channel(0));
|
||||||
CImg<float> imgMin(inputImg.channel(0));
|
CImg<float> imgMin(inputImg.channel(0));
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
fprintf(stdout, "%-40s", "Calculate the extremas...");
|
|
||||||
|
|
||||||
gettimeofday(&tim, NULL);
|
|
||||||
t1 = tim.tv_sec+(tim.tv_usec/1000000.0);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int xmin, xmax, ymin, ymax;
|
int xmin, xmax, ymin, ymax;
|
||||||
float min, max;
|
float min, max;
|
||||||
|
|
||||||
@ -118,22 +102,9 @@ CImg<float> decompose(const CImg<float> input)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
gettimeofday(&tim, NULL);
|
|
||||||
t2 = tim.tv_sec+(tim.tv_usec/1000000.0);
|
|
||||||
printf("%.6f seconds\n", t2 - t1);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Array of Euclidean distance to the nearest non zero element
|
// Array of Euclidean distance to the nearest non zero element
|
||||||
std::vector<Euclidean>::iterator it1, it2;
|
std::vector<Euclidean>::iterator it1, it2;
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
fprintf(stdout, "%-40s", "Calculate the Euclidean distances...");
|
|
||||||
|
|
||||||
gettimeofday(&tim, NULL);
|
|
||||||
t1 = tim.tv_sec+(tim.tv_usec/1000000.0);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
for (it1 = vectEMax.begin(); it1 != vectEMax.end(); it1++) {
|
for (it1 = vectEMax.begin(); it1 != vectEMax.end(); it1++) {
|
||||||
for (it2 = it1 + 1; it2 != vectEMax.end(); it2++) {
|
for (it2 = it1 + 1; it2 != vectEMax.end(); it2++) {
|
||||||
double dist = (*it1).computeDistanceFrom(*it2);
|
double dist = (*it1).computeDistanceFrom(*it2);
|
||||||
@ -166,17 +137,6 @@ CImg<float> decompose(const CImg<float> input)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
gettimeofday(&tim, NULL);
|
|
||||||
t2 = tim.tv_sec+(tim.tv_usec/1000000.0);
|
|
||||||
printf("%.6f seconds\n", t2 - t1);
|
|
||||||
|
|
||||||
fprintf(stdout, "%-40s", "Calculate the window size...");
|
|
||||||
|
|
||||||
gettimeofday(&tim, NULL);
|
|
||||||
t1 = tim.tv_sec+(tim.tv_usec/1000000.0);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Calculate the window size
|
// Calculate the window size
|
||||||
int wmax = 0;
|
int wmax = 0;
|
||||||
for(unsigned int i = 0; i < vectEMin.size(); i++) {
|
for(unsigned int i = 0; i < vectEMin.size(); i++) {
|
||||||
@ -188,21 +148,8 @@ CImg<float> decompose(const CImg<float> input)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
gettimeofday(&tim, NULL);
|
|
||||||
t2 = tim.tv_sec+(tim.tv_usec/1000000.0);
|
|
||||||
printf("%.6f seconds\n", t2 - t1);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
CImg<float> imgSource(inputImg.channel(0));
|
CImg<float> imgSource(inputImg.channel(0));
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
fprintf(stdout, "%-40s", "Order the filters...");
|
|
||||||
|
|
||||||
gettimeofday(&tim, NULL);
|
|
||||||
t1 = tim.tv_sec+(tim.tv_usec/1000000.0);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Order filters with source image
|
// Order filters with source image
|
||||||
std::vector<float> vectFilterMax, vectFilterMin;
|
std::vector<float> vectFilterMax, vectFilterMin;
|
||||||
|
|
||||||
@ -234,21 +181,8 @@ CImg<float> decompose(const CImg<float> input)
|
|||||||
vectFilterMin.push_back(min);
|
vectFilterMin.push_back(min);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
gettimeofday(&tim, NULL);
|
|
||||||
t2 = tim.tv_sec+(tim.tv_usec/1000000.0);
|
|
||||||
printf("%.6f seconds\n", t2 - t1);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
CImg<float> newImgMax(imgMax.width(), imgMax.height());
|
CImg<float> newImgMax(imgMax.width(), imgMax.height());
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
fprintf(stdout, "%-40s", "Calculate the upper envelope...");
|
|
||||||
|
|
||||||
gettimeofday(&tim, NULL);
|
|
||||||
t1 = tim.tv_sec+(tim.tv_usec/1000000.0);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Calculate the upper envelope
|
// Calculate the upper envelope
|
||||||
for(int unsigned i = 0; i < vectEMax.size(); i++) {
|
for(int unsigned i = 0; i < vectEMax.size(); i++) {
|
||||||
for (int k = vectEMax[i].getX() - ((wmax - 1) / 2); k < vectEMax[i].getX() + ((wmax + 1) / 2); k++) {
|
for (int k = vectEMax[i].getX() - ((wmax - 1) / 2); k < vectEMax[i].getX() + ((wmax + 1) / 2); k++) {
|
||||||
@ -265,17 +199,6 @@ CImg<float> decompose(const CImg<float> input)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
gettimeofday(&tim, NULL);
|
|
||||||
t2 = tim.tv_sec+(tim.tv_usec/1000000.0);
|
|
||||||
printf("%.6f seconds\n", t2 - t1);
|
|
||||||
|
|
||||||
fprintf(stdout, "%-40s", "Smooth the upper envelope...");
|
|
||||||
|
|
||||||
gettimeofday(&tim, NULL);
|
|
||||||
t1 = tim.tv_sec+(tim.tv_usec/1000000.0);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Smooth of the upper envelope
|
// Smooth of the upper envelope
|
||||||
for (int k = 0; k < imgSource.width(); k++) {
|
for (int k = 0; k < imgSource.width(); k++) {
|
||||||
for (int l = 0; l < imgSource.height(); l++) {
|
for (int l = 0; l < imgSource.height(); l++) {
|
||||||
@ -285,21 +208,8 @@ CImg<float> decompose(const CImg<float> input)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
gettimeofday(&tim, NULL);
|
|
||||||
t2 = tim.tv_sec+(tim.tv_usec/1000000.0);
|
|
||||||
printf("%.6f seconds\n", t2 - t1);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
CImg<float> newImgMin(imgMin.width(), imgMin.height());
|
CImg<float> newImgMin(imgMin.width(), imgMin.height());
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
fprintf(stdout, "%-40s", "Calculate the lower envelope...");
|
|
||||||
|
|
||||||
gettimeofday(&tim, NULL);
|
|
||||||
t1 = tim.tv_sec+(tim.tv_usec/1000000.0);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Calculate the lower envelope
|
// Calculate the lower envelope
|
||||||
for(int unsigned i = 0; i < vectEMin.size(); i++) {
|
for(int unsigned i = 0; i < vectEMin.size(); i++) {
|
||||||
for (int k = vectEMin[i].getX() - ((wmax - 1) / 2); k < vectEMin[i].getX() + ((wmax + 1) / 2); k++) {
|
for (int k = vectEMin[i].getX() - ((wmax - 1) / 2); k < vectEMin[i].getX() + ((wmax + 1) / 2); k++) {
|
||||||
@ -316,17 +226,6 @@ CImg<float> decompose(const CImg<float> input)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
gettimeofday(&tim, NULL);
|
|
||||||
t2 = tim.tv_sec+(tim.tv_usec/1000000.0);
|
|
||||||
printf("%.6f seconds\n", t2 - t1);
|
|
||||||
|
|
||||||
fprintf(stdout, "%-40s", "Smooth the lower envelope...");
|
|
||||||
|
|
||||||
gettimeofday(&tim, NULL);
|
|
||||||
t1 = tim.tv_sec+(tim.tv_usec/1000000.0);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Smooth of the lower envelope
|
// Smooth of the lower envelope
|
||||||
for (int k = 0; k < imgSource.width(); k++) {
|
for (int k = 0; k < imgSource.width(); k++) {
|
||||||
for (int l = 0; l < imgSource.height(); l++) {
|
for (int l = 0; l < imgSource.height(); l++) {
|
||||||
@ -336,29 +235,10 @@ CImg<float> decompose(const CImg<float> input)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
// Display images for max and min
|
|
||||||
CImgDisplay dispEMax(imgMax,"Envelope Max");
|
|
||||||
CImgDisplay dispEMin(imgMin,"Envelope Min");
|
|
||||||
CImgDisplay dispSMax(newImgMax,"Smooth Max");
|
|
||||||
CImgDisplay dispSMin(newImgMin,"Smooth Min");
|
|
||||||
|
|
||||||
gettimeofday(&tim, NULL);
|
|
||||||
t2 = tim.tv_sec+(tim.tv_usec/1000000.0);
|
|
||||||
printf("%.6f seconds\n", t2 - t1);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
// Part 2: Average //
|
// Part 2: Average //
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
fprintf(stdout, "%-40s", "Average...");
|
|
||||||
|
|
||||||
gettimeofday(&tim, NULL);
|
|
||||||
t1 = tim.tv_sec+(tim.tv_usec/1000000.0);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Calculate the Average
|
// Calculate the Average
|
||||||
CImg<float> imgMoyenne(inputImg.width(), inputImg.height());
|
CImg<float> imgMoyenne(inputImg.width(), inputImg.height());
|
||||||
|
|
||||||
@ -368,22 +248,10 @@ CImg<float> decompose(const CImg<float> input)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
CImgDisplay dispMoyenne(imgMoyenne, "Average");
|
|
||||||
|
|
||||||
gettimeofday(&tim, NULL);
|
|
||||||
t2 = tim.tv_sec+(tim.tv_usec/1000000.0);
|
|
||||||
printf("%.6f seconds\n", t2 - t1);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
// Partie 3: Deletion //
|
// Partie 3: Deletion //
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
printf("Deletion..\n");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return inputImg - imgMoyenne;
|
return inputImg - imgMoyenne;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -392,20 +260,22 @@ CImg<float> decompose(const CImg<float> input)
|
|||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
char title[50];
|
char modeTitle[30], residueTitle[50];
|
||||||
CImgDisplay disp[NB_ITERATIONS + 1];
|
CImgDisplay disp[NB_ITERATIONS * 2 + 1];
|
||||||
|
|
||||||
CImg<float> inputImg("lena.bmp"), imgMode;
|
CImg<float> inputImg("lena.bmp"), imgMode;
|
||||||
disp[0].assign(inputImg, "Source Image");
|
disp[0].assign(inputImg, "Source Image");
|
||||||
|
|
||||||
for (int i = 1; i < NB_ITERATIONS; i++) {
|
for (int i = 1; i < NB_ITERATIONS + 1; i++) {
|
||||||
sprintf(title, "BEMC-%d", i);
|
sprintf(modeTitle, "BEMC-%d", i);
|
||||||
fprintf(stdout, "Decomposing %s\n", title);
|
sprintf(residueTitle, "Residue %s", modeTitle);
|
||||||
|
fprintf(stdout, "Decomposing %s\n", modeTitle);
|
||||||
|
|
||||||
imgMode = decompose(inputImg);
|
imgMode = decompose(inputImg);
|
||||||
inputImg = inputImg - imgMode;
|
inputImg = inputImg - imgMode;
|
||||||
|
|
||||||
disp[i].assign(imgMode, title);
|
disp[i].assign(imgMode, modeTitle);
|
||||||
|
disp[NB_ITERATIONS + i].assign(inputImg, residueTitle);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (!disp[0].is_closed()) {
|
while (!disp[0].is_closed()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user