core/vil/algo/vil_suppress_non_plateau.h
Go to the documentation of this file.
00001 // This is core/vil/algo/vil_suppress_non_plateau.h
00002 #ifndef vil_suppress_non_plateau_h_
00003 #define vil_suppress_non_plateau_h_
00004 //:
00005 // \file
00006 // \brief Suppress all non-plateau points in image
00007 // \author Tim Cootes, Kevin de Souza
00008 
00009 #include <vil/vil_image_view.h>
00010 #include <vil/algo/vil_find_plateaus.h>
00011 #include <vil/vil_fill.h>
00012 #include <vcl_cassert.h>
00013 
00014 //: Suppress all non-plateau pixels in the image.
00015 //  If image(i,j) is greater than or equal to all neighbouring pixels,
00016 //  and is above the threshold, then it is retained. All other
00017 //  pixels are set to non_max_value.
00018 //
00019 //  non_max_value must be below the threshold (so the default value of
00020 //  zero is inappropriate if the image contains plateaus of interest with
00021 //  negative values)
00022 //
00023 // \sa vil_suppress_non_max_3x3()
00024 // \relatesalso vil_image_view
00025 template <class T>
00026 inline void vil_suppress_non_plateau_3x3(const vil_image_view<T>& src_im,
00027                                          vil_image_view<T>& dest_im,
00028                                          T threshold=0, T non_max_value=0)
00029 {
00030   unsigned ni=src_im.ni(),nj=src_im.nj();
00031   assert(src_im.nplanes()==1);
00032 
00033   dest_im.set_size(ni,nj,1);
00034 
00035   vcl_ptrdiff_t istep = src_im.istep(),jstep=src_im.jstep();
00036   vcl_ptrdiff_t distep = dest_im.istep(),djstep=dest_im.jstep();
00037   const T* row = src_im.top_left_ptr()+istep+jstep;
00038   T* drow = dest_im.top_left_ptr()+distep+djstep;
00039   for (unsigned j=1;j<nj-1;++j,row+=jstep,drow+=djstep)
00040   {
00041     const T* pixel = row;
00042     T* dpixel = drow;
00043     for (unsigned i=1;i<ni-1;++i,pixel+=istep,dpixel+=distep)
00044     {
00045       if (*pixel<threshold || !vil_is_plateau_3x3(pixel,istep,jstep))
00046         *dpixel = non_max_value;
00047       else
00048         *dpixel = *pixel;
00049     }
00050   }
00051 
00052   // Border pixels assumed not to be local plateaus
00053   vil_fill_row(dest_im,0,non_max_value);
00054   vil_fill_row(dest_im,nj-1,non_max_value);
00055   vil_fill_col(dest_im,0,non_max_value);
00056   vil_fill_col(dest_im,ni-1,non_max_value);
00057 }
00058 
00059 #endif // vil_suppress_non_plateau_h_