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 "SimplePeronaMalikFlow.hpp"
00033 #include "operator/DifferentialOperators.hpp"
00034 #include "MillieStd.hpp"
00035
00036
00037
00038
00039
00040
00041
00042 namespace Millie
00043 {
00044
00045 SimplePeronaMalikFlow::SimplePeronaMalikFlow(float lambda)
00046 {
00047 _lambda2 = Math::square(lambda);
00048 }
00049
00050
00051
00052 float SimplePeronaMalikFlow::computeDiffusion(float v) const
00053 {
00054 return (_lambda2)/((_lambda2) + Math::square(v));
00055 }
00056
00057 SimplePeronaMalikFlow* SimplePeronaMalikFlow::clone() const
00058 {
00059 return new SimplePeronaMalikFlow(*this);
00060 }
00061
00062 float SimplePeronaMalikFlow::computeFlow(const Image & image, int x, int y, int canal) const
00063 {
00064 float current = image.getPixel(x,y, canal);
00065 int width = image.getWidth();
00066 int height = image.getHeight();
00067
00068
00069 int px = x-1;
00070 int nx = x+1;
00071 int py = y-1;
00072 int ny = y+1;
00073 if (px<0)
00074 px=0;
00075 if (nx>=width)
00076 nx=width-1;
00077 if (py<0)
00078 py=0;
00079 if (ny>=height)
00080 ny=height-1;
00081
00082 float ixp = image.getPixel(px, y, canal);
00083 float ixn = image.getPixel(nx, y, canal);
00084 float iyp = image.getPixel(x, ny, canal);
00085 float iyn = image.getPixel(x, py, canal);
00086
00087 float diffxn = computeDiffusion(current - ixn);
00088 float diffxp = computeDiffusion(current - ixp);
00089 float diffyn = computeDiffusion(current - iyn);
00090 float diffyp = computeDiffusion(current - ixp);
00091
00092
00093 float delta = (diffxn * (ixn - current))
00094 + (diffxp * (ixp - current))
00095 + (diffyp * (iyp - current))
00096 + (diffyn * (iyn - current));
00097
00098
00099 return delta;
00100 }
00101 }
00102
00103
00104