Go to the documentation of this file.00001
00002 #ifndef vil3d_find_peaks_h_
00003 #define vil3d_find_peaks_h_
00004
00005
00006
00007
00008
00009 #include <vil3d/vil3d_image_view.h>
00010 #include <vgl/vgl_point_3d.h>
00011 #include <vcl_vector.h>
00012
00013
00014 template <class T>
00015 inline bool vil3d_is_above_8nbrs(T v, const T* im, vcl_ptrdiff_t i_step, vcl_ptrdiff_t j_step)
00016 {
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 template <class T>
00030 inline bool vil3d_is_peak26(const T* im, vcl_ptrdiff_t i_step,
00031 vcl_ptrdiff_t j_step, vcl_ptrdiff_t k_step)
00032 {
00033 if (!vil3d_is_above_8nbrs(im[0],im,i_step,j_step)) return false;
00034 if (*im<=im[k_step]) return false;
00035 if (!vil3d_is_above_8nbrs(im[0],im+k_step,i_step,j_step)) return false;
00036 if (*im<=im[-k_step]) return false;
00037 if (!vil3d_is_above_8nbrs(im[0],im-k_step,i_step,j_step)) return false;
00038 return true;
00039 }
00040
00041
00042
00043
00044 template <class T>
00045 inline void vil3d_find_peaks_26(vcl_vector<vgl_point_3d<int> >& peaks,
00046 const vil3d_image_view<T>& image,
00047 const T& min_thresh,
00048 bool clear_list=true)
00049 {
00050 if (clear_list) peaks.resize(0);
00051
00052 const unsigned ni1=image.ni()-1,nj1=image.nj()-1,nk1=image.nk()-1;
00053 const vcl_ptrdiff_t istep = image.istep(),jstep=image.jstep(),kstep=image.kstep();
00054 const T* plane = image.origin_ptr()+istep+jstep+kstep;
00055 for (unsigned k=1;k<nk1;++k,plane+=kstep)
00056 {
00057 const T* row = plane;
00058 for (unsigned j=1;j<nj1;++j,row+=jstep)
00059 {
00060 const T* pixel = row;
00061 for (unsigned i=1;i<ni1;++i,pixel+=istep)
00062 if (*pixel>=min_thresh && vil3d_is_peak26(pixel,istep,jstep,kstep))
00063 { peaks.push_back(vgl_point_3d<int>(i,j,k)); }
00064 }
00065 }
00066 }
00067
00068 #endif // vil3d_find_peaks_h_