contrib/tbl/vipl/vipl_gradient_mag.txx
Go to the documentation of this file.
00001 #ifndef vipl_gradient_mag_txx_
00002 #define vipl_gradient_mag_txx_
00003 
00004 #include "vipl_gradient_mag.h"
00005 #include <vcl_cmath.h> // for sqrt()
00006 
00007 template <class ImgIn,class ImgOut,class DataIn,class DataOut,class PixelItr>
00008 bool vipl_gradient_mag <ImgIn,ImgOut,DataIn,DataOut,PixelItr> :: section_applyop()
00009 {
00010   const ImgIn &in = this->in_data(0);
00011   ImgOut &out = *this->out_data_ptr();
00012 
00013   register double dx, dy;
00014   int startx = vipl_filter<ImgIn,ImgOut,DataIn,DataOut,2,PixelItr>::start(this->X_Axis());
00015   int starty = vipl_filter<ImgIn,ImgOut,DataIn,DataOut,2,PixelItr>::start(this->Y_Axis());
00016   int stopx  = vipl_filter<ImgIn,ImgOut,DataIn,DataOut,2,PixelItr>::stop(this->X_Axis());
00017   int stopy  = vipl_filter<ImgIn,ImgOut,DataIn,DataOut,2,PixelItr>::stop(this->Y_Axis());
00018   for (int j = starty; j < stopy; ++j)
00019     for (int i = startx; i < stopx; ++i) {
00020       dx = fgetpixel(in, i, j, DataIn(0)) - getpixel(in, i-1, j, DataIn(0));
00021       dy = fgetpixel(in, i, j, DataIn(0)) - getpixel(in, i, j-1, DataIn(0));
00022       dx = (vcl_sqrt( dx*dx + dy*dy ) + shift()) * scale();
00023       fsetpixel(out, i, j, DataOut(dx));
00024     }
00025   return true;
00026 }
00027 
00028 #endif // vipl_gradient_mag_txx_