From 5ddb5dc39fc968eb6685ad281981ecc0b6d58497 Mon Sep 17 00:00:00 2001 From: William DURAND Date: Tue, 10 Jan 2012 13:22:02 +0100 Subject: [PATCH] Fixed decomposition loop --- main.cpp | 148 ++++--------------------------------------------------- 1 file changed, 9 insertions(+), 139 deletions(-) diff --git a/main.cpp b/main.cpp index ce560c2..2ebe094 100644 --- a/main.cpp +++ b/main.cpp @@ -13,11 +13,7 @@ #include "Euclidean.hpp" -#ifdef DEBUG -#include -#endif - -#define NB_ITERATIONS 3 +#define NB_ITERATIONS 10 #define MIN(x,y) ((x)<(y)?(x):(y)) #define MAX(x,y) ((x)>(y)?(x):(y)) @@ -47,21 +43,9 @@ CImg decompose(const CImg input) // Part 1: Finding minimas and maximas // /////////////////////////////////////////////////////////////////////////////// -#ifdef DEBUG - timeval tim; - double t1, t2; -#endif - CImg imgMax(inputImg.channel(0)); CImg 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; float min, max; @@ -118,22 +102,9 @@ CImg decompose(const CImg 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 std::vector::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 (it2 = it1 + 1; it2 != vectEMax.end(); it2++) { double dist = (*it1).computeDistanceFrom(*it2); @@ -166,17 +137,6 @@ CImg decompose(const CImg 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 int wmax = 0; for(unsigned int i = 0; i < vectEMin.size(); i++) { @@ -188,21 +148,8 @@ CImg decompose(const CImg input) } } -#ifdef DEBUG - gettimeofday(&tim, NULL); - t2 = tim.tv_sec+(tim.tv_usec/1000000.0); - printf("%.6f seconds\n", t2 - t1); -#endif - CImg 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 std::vector vectFilterMax, vectFilterMin; @@ -234,21 +181,8 @@ CImg decompose(const CImg input) 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 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 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++) { @@ -265,17 +199,6 @@ CImg decompose(const CImg 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 for (int k = 0; k < imgSource.width(); k++) { for (int l = 0; l < imgSource.height(); l++) { @@ -285,21 +208,8 @@ CImg decompose(const CImg input) } } -#ifdef DEBUG - gettimeofday(&tim, NULL); - t2 = tim.tv_sec+(tim.tv_usec/1000000.0); - printf("%.6f seconds\n", t2 - t1); -#endif - CImg 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 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++) { @@ -316,17 +226,6 @@ CImg decompose(const CImg 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 for (int k = 0; k < imgSource.width(); k++) { for (int l = 0; l < imgSource.height(); l++) { @@ -336,29 +235,10 @@ CImg decompose(const CImg 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 // /////////////////////////////////////////////////////////////////////////////// -#ifdef DEBUG - fprintf(stdout, "%-40s", "Average..."); - - gettimeofday(&tim, NULL); - t1 = tim.tv_sec+(tim.tv_usec/1000000.0); -#endif - // Calculate the Average CImg imgMoyenne(inputImg.width(), inputImg.height()); @@ -368,22 +248,10 @@ CImg decompose(const CImg 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 // /////////////////////////////////////////////////////////////////////////////// -#ifdef DEBUG - printf("Deletion..\n"); -#endif - return inputImg - imgMoyenne; } @@ -392,20 +260,22 @@ CImg decompose(const CImg input) *******************************************************************************/ int main() { - char title[50]; - CImgDisplay disp[NB_ITERATIONS + 1]; + char modeTitle[30], residueTitle[50]; + CImgDisplay disp[NB_ITERATIONS * 2 + 1]; CImg inputImg("lena.bmp"), imgMode; disp[0].assign(inputImg, "Source Image"); - for (int i = 1; i < NB_ITERATIONS; i++) { - sprintf(title, "BEMC-%d", i); - fprintf(stdout, "Decomposing %s\n", title); + for (int i = 1; i < NB_ITERATIONS + 1; i++) { + sprintf(modeTitle, "BEMC-%d", i); + sprintf(residueTitle, "Residue %s", modeTitle); + fprintf(stdout, "Decomposing %s\n", modeTitle); imgMode = decompose(inputImg); 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()) {