2011-11-30 19:02:40 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2011-11-30 19:24:28 +08:00
|
|
|
// Empirical Mode Decomposition //
|
2011-11-30 19:02:40 +08:00
|
|
|
// BERNARD Guillaume //
|
|
|
|
// DURAND William //
|
|
|
|
// ZZ3F2 ISIMA //
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "CImg.h"
|
|
|
|
#include <math.h>
|
2011-12-06 00:17:32 +08:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "Euclidean.hpp"
|
2011-11-30 19:02:40 +08:00
|
|
|
|
|
|
|
using namespace cimg_library;
|
|
|
|
|
|
|
|
/*******************************************************************************
|
2011-11-30 19:24:28 +08:00
|
|
|
Main
|
|
|
|
*******************************************************************************/
|
2011-11-30 19:02:40 +08:00
|
|
|
int main()
|
|
|
|
{
|
|
|
|
CImg<unsigned char> imgLena("lena.bmp");
|
|
|
|
|
|
|
|
CImgDisplay dispBase(imgLena,"Image de base");
|
2011-11-30 19:24:28 +08:00
|
|
|
|
2011-12-06 00:17:32 +08:00
|
|
|
std::vector<Euclidean> vectEMax, vectEMin;
|
|
|
|
|
2011-11-30 19:24:28 +08:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Part 1: Finding minimas and maximas //
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2011-12-06 00:17:32 +08:00
|
|
|
CImg<unsigned char> imgMax = imgLena.channel(0);
|
|
|
|
CImg<unsigned char> imgMin = imgLena.channel(0);
|
|
|
|
|
|
|
|
imgMax.print();
|
2011-11-30 19:24:28 +08:00
|
|
|
|
2011-11-30 19:02:40 +08:00
|
|
|
for (int i = 0; i<imgLena.width() ; i+=3) {
|
|
|
|
for (int j = 0; j<imgLena.height() ; j+=3) {
|
2011-11-30 19:24:28 +08:00
|
|
|
|
|
|
|
// Save max and min locations
|
2011-11-30 19:02:40 +08:00
|
|
|
int xmax = i;
|
|
|
|
int ymax = j;
|
|
|
|
int xmin = i;
|
|
|
|
int ymin = j;
|
2011-11-30 19:24:28 +08:00
|
|
|
|
|
|
|
// save values
|
2011-11-30 19:02:40 +08:00
|
|
|
unsigned char max = imgMax(i,j);
|
|
|
|
unsigned char min = imgMin(i,j);
|
2011-11-30 19:24:28 +08:00
|
|
|
|
2011-12-06 00:17:32 +08:00
|
|
|
Euclidean eMax(i, j);
|
|
|
|
Euclidean eMin(i, j);
|
|
|
|
|
2011-11-30 19:24:28 +08:00
|
|
|
// 3x3
|
2011-11-30 19:02:40 +08:00
|
|
|
for (int k = i; k<i+3 ; k++) {
|
|
|
|
for (int l = j; l<j+3 ; l++) {
|
2011-11-30 19:24:28 +08:00
|
|
|
|
2011-12-05 23:10:49 +08:00
|
|
|
// Max
|
2011-11-30 19:02:40 +08:00
|
|
|
if ((imgMax(k,l) <= max)&&(l!=ymax &&k!=xmax)) {
|
|
|
|
imgMax(k,l) = 0;
|
2011-11-30 19:24:28 +08:00
|
|
|
} else {
|
2011-11-30 19:02:40 +08:00
|
|
|
max = imgMax(k,l);
|
|
|
|
imgMax(xmax,ymax) = 0;
|
|
|
|
xmax = k;
|
|
|
|
ymax = l;
|
2011-12-06 00:17:32 +08:00
|
|
|
|
|
|
|
eMax.setX(k);
|
|
|
|
eMax.setY(l);
|
2011-11-30 19:02:40 +08:00
|
|
|
}
|
2011-11-30 19:24:28 +08:00
|
|
|
|
2011-12-05 23:10:49 +08:00
|
|
|
// Min
|
2011-11-30 19:02:40 +08:00
|
|
|
if ((imgMin(k,l) >= min)&&(l!=ymin &&k!=xmin)) {
|
|
|
|
imgMin(k,l) = 0;
|
2011-11-30 19:24:28 +08:00
|
|
|
} else {
|
2011-11-30 19:02:40 +08:00
|
|
|
min = imgMin(k,l);
|
2011-12-06 00:17:32 +08:00
|
|
|
imgMin(xmin,ymin) = 0;
|
2011-11-30 19:02:40 +08:00
|
|
|
xmin = k;
|
|
|
|
ymin = l;
|
2011-12-06 00:17:32 +08:00
|
|
|
|
|
|
|
eMin.setX(k);
|
|
|
|
eMin.setY(l);
|
2011-11-30 19:02:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-12-06 00:17:32 +08:00
|
|
|
|
|
|
|
vectEMax.push_back(eMax);
|
|
|
|
vectEMin.push_back(eMin);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Array of Euclidean distance to the nearest non zero element
|
|
|
|
std::vector<Euclidean>::iterator it1, it2;
|
|
|
|
|
|
|
|
for (it1 = vectEMax.begin(); it1 != vectEMax.end(); it1++) {
|
|
|
|
for (it2 = it1 + 1; it2 != vectEMax.end(); it2++) {
|
|
|
|
double dist = (*it1).computeDistanceFrom(*it2);
|
|
|
|
|
|
|
|
if (0 == (*it1).getDistance() || dist < (*it1).getDistance()) {
|
|
|
|
(*it1).setDistance(dist);
|
|
|
|
(*it1).setNearest(*it2);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (0 == (*it2).getDistance() || dist < (*it2).getDistance()) {
|
|
|
|
(*it2).setDistance(dist);
|
|
|
|
(*it2).setNearest(*it1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (it1 = vectEMin.begin(); it1 != vectEMin.end(); it1++) {
|
|
|
|
for (it2 = it1 + 1; it2 != vectEMin.end(); it2++) {
|
|
|
|
double dist = (*it1).computeDistanceFrom(*it2);
|
|
|
|
|
|
|
|
if (0 == (*it1).getDistance() || dist < (*it1).getDistance()) {
|
|
|
|
(*it1).setDistance(dist);
|
|
|
|
(*it1).setNearest(*it2);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (0 == (*it2).getDistance() || dist < (*it2).getDistance()) {
|
|
|
|
(*it2).setDistance(dist);
|
|
|
|
(*it2).setNearest(*it1);
|
|
|
|
}
|
2011-11-30 19:02:40 +08:00
|
|
|
}
|
|
|
|
}
|
2011-11-30 19:24:28 +08:00
|
|
|
|
2011-12-06 00:17:32 +08:00
|
|
|
// Calculate the window size
|
|
|
|
|
|
|
|
// Order filters with source image
|
|
|
|
|
|
|
|
// Calculate the upper envelope
|
|
|
|
|
|
|
|
// Calculate the lower envelope
|
|
|
|
|
2011-11-30 19:24:28 +08:00
|
|
|
// Display images for max and min
|
2011-11-30 19:02:40 +08:00
|
|
|
CImgDisplay dispMax(imgMax,"Image de Max");
|
|
|
|
CImgDisplay dispMin(imgMin,"Image de Min");
|
2011-11-30 19:24:28 +08:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Part 2: Average //
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2011-11-30 19:02:40 +08:00
|
|
|
|
2011-12-06 00:17:32 +08:00
|
|
|
// Calculate the Average
|
2011-11-30 19:02:40 +08:00
|
|
|
CImg<unsigned char> imgMoyenne = (imgMax+imgMin)/2;
|
|
|
|
CImgDisplay dispMoyenne(imgMoyenne,"Image Moyenne");
|
2011-11-30 19:24:28 +08:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Partie 3: Deletion //
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2011-11-30 19:02:40 +08:00
|
|
|
CImg<unsigned char> imgFin = imgLena - imgMoyenne;
|
|
|
|
CImgDisplay dispFin(imgFin,"Image Finale");
|
2011-11-30 19:24:28 +08:00
|
|
|
|
|
|
|
while (!dispBase.is_closed()) {
|
2011-11-30 19:02:40 +08:00
|
|
|
dispBase.wait();
|
|
|
|
}
|
2011-11-30 19:24:28 +08:00
|
|
|
|
2011-11-30 19:02:40 +08:00
|
|
|
return 0;
|
|
|
|
}
|