00001
00002 #ifndef vimt_find_troughs_h_
00003 #define vimt_find_troughs_h_
00004
00005
00006
00007
00008
00009 #include <vimt/vimt_image_2d_of.h>
00010
00011
00012
00013 template <class T>
00014 inline bool vimt_is_trough_3x3(const T* im, vcl_ptrdiff_t i_step, vcl_ptrdiff_t j_step)
00015 {
00016 T v = *im;
00017 if (v>=im[i_step]) return false;
00018 if (v>=im[-i_step]) return false;
00019 if (v>=im[j_step]) return false;
00020 if (v>=im[-j_step]) return false;
00021 if (v>=im[i_step+j_step]) return false;
00022 if (v>=im[i_step-j_step]) return false;
00023 if (v>=im[j_step-i_step]) return false;
00024 if (v>=im[-i_step-j_step]) return false;
00025 return true;
00026 }
00027
00028
00029
00030 template <class T>
00031 inline void vimt_find_image_troughs_3x3(vcl_vector<vgl_point_2d<unsigned> >& troughs,
00032 const vil_image_view<T>& image,
00033 unsigned plane=0, bool clear_list=true)
00034 {
00035 if (clear_list) troughs.resize(0);
00036 unsigned ni=image.ni(),nj=image.nj();
00037 vcl_ptrdiff_t istep = image.istep(),jstep=image.jstep();
00038 const T* row = image.top_left_ptr()+plane*image.planestep()+istep+jstep;
00039 for (unsigned j=1;j<nj-1;++j,row+=jstep)
00040 {
00041 const T* pixel = row;
00042 for (unsigned i=1;i<ni-1;++i,pixel+=istep)
00043 if (vimt_is_trough_3x3(pixel,istep,jstep))
00044 troughs.push_back(vgl_point_2d<unsigned>(i,j));
00045 }
00046 }
00047
00048
00049
00050 template <class T>
00051 inline void vimt_find_world_troughs_3x3(vcl_vector<vgl_point_2d<double> >& troughs,
00052 const vimt_image_2d_of<T>& image,
00053 unsigned plane=0, bool clear_list=true)
00054 {
00055 if (clear_list) troughs.resize(0);
00056 const vil_image_view<T>& im = image.image();
00057 vimt_transform_2d im2w = image.world2im().inverse();
00058 unsigned ni=im.ni(),nj=im.nj();
00059 vcl_ptrdiff_t istep = im.istep(),jstep=im.jstep();
00060 const T* row = im.top_left_ptr()+plane*im.planestep()+istep+jstep;
00061 for (unsigned j=1;j<nj-1;++j,row+=jstep)
00062 {
00063 const T* pixel = row;
00064 for (unsigned i=1;i<ni-1;++i,pixel+=istep)
00065 if (vimt_is_trough_3x3(pixel,istep,jstep)) troughs.push_back(im2w(i,j));
00066 }
00067 }
00068
00069
00070 #endif // vimt_find_troughs_h_