Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

vimt_find_troughs.h

Go to the documentation of this file.
00001 // This is mul/vimt/algo/vimt_find_troughs.h
00002 #ifndef vimt_find_troughs_h_
00003 #define vimt_find_troughs_h_
00004 //:
00005 // \file
00006 // \brief Find troughs in image
00007 // \author Tim Cootes
00008 
00009 #include <vimt/vimt_image_2d_of.h>
00010 
00011 //: True if pixel at *im is strictly below its 8 neighbours
00012 //  The image pixel (first argument) should *not* be a border pixel!
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 //: Return image co-ordinates of all points in image strictly below their 8 neighbours
00029 // \param clear_list: If true (the default) then empty list before adding new examples
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) // do not run over border
00040   {
00041     const T* pixel = row;
00042     for (unsigned i=1;i<ni-1;++i,pixel+=istep) // do not run over border
00043       if (vimt_is_trough_3x3(pixel,istep,jstep))
00044         troughs.push_back(vgl_point_2d<unsigned>(i,j));
00045   }
00046 }
00047 
00048 //: Return world co-ordinates of all points in image strictly below their 8 neighbours
00049 // \param clear_list: If true (the default) then empty list before adding new examples
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) // do not run over border
00062   {
00063     const T* pixel = row;
00064     for (unsigned i=1;i<ni-1;++i,pixel+=istep) // do not run over border
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_

Generated on Thu Jan 10 14:43:58 2008 for contrib/mul/vimt by  doxygen 1.4.4