/home/neoflo/smb4k/SERVEUR/Millie/trunk/src/operator/PeronaMalikFilter/NeighbourPeronaMalikFlow.cpp

Aller à la documentation de ce fichier.
00001 /******************************************************************************
00002  *       __    _    _   _       _       _   _____                             *
00003  *       | \  / |  | | | |     | |     | |  | ___|                            *
00004  *       |  \/  |  | | | |     | |     | |  | |_                              *
00005  *       |      |  | | | |     | |     | |  |  _|                             *
00006  *       | |\/| |  | | | |__   | |__   | |  | |__                             *
00007  *       |_|  |_|  |_| |____|  |____|  |_|  |____|                            *
00008  * __________________________________________________________________________ *
00009  *                 Multifunctional Library For Image Processing               *
00010  *                                                                            *
00011  *                                                                            *
00012  *                                                                            *
00013  *      (c) Copyright 2007 by Humbert Florent                                 *
00014  *                                                                            *
00015  *      This program is free software; you can redistribute it and/or modify  *
00016  *      it under the terms of the GNU General Public License as published by  *
00017  *      the Free Software Foundation; only version 2 of the License.          *
00018  *                                                                            *
00019  *      This program is distributed in the hope that it will be useful,       *
00020  *      but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00021  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00022  *      GNU General Public License for more details.                          *
00023  *                                                                            *
00024  *      You should have received a copy of the GNU General Public License     *
00025  *      along with this program; if not, write to the Free Software           *
00026  *      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA             *
00027  *      02111-1307, USA.                                                      *
00028  ******************************************************************************/
00029 
00032 #include "NeighbourPeronaMalikFlow.hpp"
00033 
00034 
00035 
00036 using namespace Millie;
00037 
00038 /*
00039  * Cet algorithme est fortement inspiré de l'algorithme de résolution proposé par :
00040  *   Jan-Friedrich Ehlenbröker, Alexander Maier, Uwe Mönks, Stefan
00041  * Schwalowsky et Matthias Tobergte
00042  */
00043 
00044 float NeighbourPeronaMalikFlow::computeFlow(const Image& image,
00045                                         int x,
00046                                         int y,
00047                                         int canal) const
00048 {
00049   float current = image.getPixel(x,y, canal);
00050   int width = image.getWidth();
00051   int height = image.getHeight();
00052 
00053 
00054   int px = x-1;
00055   int nx = x+1;
00056   int py = y-1;
00057   int ny = y+1;
00058   if (px<0)
00059     px=0;
00060   if (nx>=width)
00061     nx=width-1;
00062   if (py<0)
00063     py=0;
00064   if (ny>=height)
00065     ny=height-1;
00066 
00067   float ixp = image.getPixel(px, y, canal);
00068   float ixn = image.getPixel(nx, y, canal);
00069   float iyp = image.getPixel(x, ny, canal);
00070   float iyn = image.getPixel(x, py, canal);
00071 
00072   float diffxn = computeDiffusion(current- ixn);
00073   float diffxp = computeDiffusion(current- ixp);
00074   float diffyn = computeDiffusion(current- iyn);
00075   float diffyp = computeDiffusion(current- ixp);
00076 
00077   float iNE = image.getPixel(nx, py, canal);
00078   float iSW = image.getPixel(px, ny, canal);
00079   float iNW = image.getPixel(px, py, canal);
00080   float iSE = image.getPixel(nx ,ny, canal);
00081   float diffNE = computeDiffusion(current  - iNE);
00082   float diffSW = computeDiffusion(current- iSW);
00083   float diffNW = computeDiffusion(current- iNW);
00084   float diffSE = computeDiffusion(current- iSE);
00085 
00086 
00087   float delta =   diffxn * (ixn - current)
00088                   + diffxp * (ixp - current)
00089                   + diffyp * (iyp - current)
00090                   + diffyn * (iyn - current)
00091                   +
00092                   0.5f * (
00093                     diffNE * (iNE- current)
00094                     +  diffSW * (iSW - current)
00095                     +  diffSE * (iSE - current)
00096                     +  diffNW * (iNW -current)
00097                   );
00098 
00099 
00100   return delta;
00101 
00102 }
00103 
00104 
00105 
00106 NeighbourPeronaMalikFlow::NeighbourPeronaMalikFlow(float lambda) :
00107     SimplePeronaMalikFlow(lambda)
00108 {
00109 }
00110 
00111 NeighbourPeronaMalikFlow*  NeighbourPeronaMalikFlow::clone() const
00112 {
00113   return new NeighbourPeronaMalikFlow(*this);
00114 }

Généré le Fri May 18 23:24:44 2007 pour Millie par  doxygen 1.5.1