00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00032 #include "NeighbourPeronaMalikFlow.hpp"
00033
00034
00035
00036 using namespace Millie;
00037
00038
00039
00040
00041
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 }