core/vil/algo/vil_find_plateaus.h
Go to the documentation of this file.
00001 // This is core/vil/algo/vil_find_plateaus.h
00002 #ifndef vil_find_plateaus_h_
00003 #define vil_find_plateaus_h_
00004 //:
00005 // \file
00006 // \brief Find plateau points in image. Based on vil_find_peaks.h
00007 // \author Tim Cootes, Kevin de Souza
00008 
00009 #include <vil/vil_image_view.h>
00010 #include <vcl_vector.h>
00011 
00012 //: True if pixel at *im is greater than or equal to all 8 neighbours.
00013 // \sa vil_is_peak_3x3()
00014 template <class T>
00015 inline bool vil_is_plateau_3x3(const T* im, vcl_ptrdiff_t i_step, vcl_ptrdiff_t j_step)
00016 {
00017   T v = *im;
00018   return v >= im[i_step]
00019       && v >= im[-i_step]
00020       && v >= im[j_step]
00021       && v >= im[-j_step]
00022       && v >= im[i_step+j_step]
00023       && v >= im[i_step-j_step]
00024       && v >= im[j_step-i_step]
00025       && v >= im[-i_step-j_step];
00026 }
00027 
00028 //: Return (pi,pj) for all points in image greater than or equal to all 8 neighbours.
00029 //  Compute position of all local plateau points (pi[k],pj[k]) above given threshold value.
00030 // \param clear_list  If true (the default) then empty lists before adding new examples
00031 // \sa vil_find_peaks_3x3()
00032 // \relatesalso vil_image_view
00033 template <class T>
00034 inline void vil_find_plateaus_3x3(vcl_vector<unsigned>& pi,
00035                                   vcl_vector<unsigned>& pj,
00036                                   const vil_image_view<T>& image,
00037                                   const T& min_thresh,
00038                                   bool clear_list=true)
00039 {
00040   if (clear_list) {
00041     pi.resize(0);
00042     pj.resize(0);
00043   }
00044   const unsigned ni1=image.ni()-1,nj1=image.nj()-1;
00045   const vcl_ptrdiff_t istep = image.istep(),jstep=image.jstep();
00046   const T* row = image.top_left_ptr()+istep+jstep;
00047   for (unsigned j=1;j<nj1;++j,row+=jstep)
00048   {
00049     const T* pixel = row;
00050     for (unsigned i=1;i<ni1;++i,pixel+=istep)
00051       if (*pixel>=min_thresh && vil_is_plateau_3x3(pixel,istep,jstep))
00052       {
00053         pi.push_back(i);
00054         pj.push_back(j);
00055       }
00056   }
00057 }
00058 
00059 #endif // vil_find_plateaus_h_