core/vbl/vbl_local_minima.h
Go to the documentation of this file.
00001 // This is core/vbl/vbl_local_minima.h
00002 #ifndef vbl_local_minima_h_
00003 #define vbl_local_minima_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \brief Find local minima in arrays
00010 // \author J.L. Mundy
00011 //  October 2, 2010
00012 // \verbatim
00013 //  Modifications
00014 //   <None>
00015 // \endverbatim
00016 
00017 #include <vbl/vbl_array_1d.h>
00018 #include <vbl/vbl_array_2d.h>
00019 #include <vbl/vbl_array_3d.h>
00020 
00021 //: Find the local minima in arrays
00022 //  The result is an array with non-zero elements where local minima
00023 //  exist. A local minimum must be smaller than \e all neighboring elements
00024 //  by a threshold.
00025 //  The result is an array with non-zero elements at minima.
00026 //  The value of non-zero element indicates the smallest difference
00027 //  between the minima and the neighboring elements.
00028 template <class T>
00029 vbl_array_1d<T> vbl_local_minima(vbl_array_1d<T> const& in, T thresh = T(0))
00030 {
00031   vbl_array_1d<T> m(in.size(), T(0));
00032   if (local_minima(in, m, thresh)) return m;
00033   else return vbl_array_1d<T>();
00034 }
00035 
00036 //: Find the local minima in arrays
00037 //  The result is an array with non-zero elements where local minima
00038 //  exist. A local minimum must be smaller than \e all neighboring elements
00039 //  by a threshold. The neighborhoods are 4-connected.
00040 //  The result is an array with non-zero elements at minima.
00041 //  The value of non-zero element indicates the smallest difference
00042 //  between the minima and the neighboring elements.
00043 template <class T>
00044 vbl_array_2d<T> vbl_local_minima(vbl_array_2d<T> const& in, T thresh = T(0))
00045 {
00046   vbl_array_2d<T> m(in.rows(), in.cols(), T(0));
00047   if (local_minima(in, m, thresh)) return m;
00048   else return vbl_array_2d<T>();
00049 }
00050 
00051 //: Find the local minima in arrays
00052 //  The result is an array with non-zero elements where local minima
00053 //  exist. A local minimum must be smaller than \e all neighboring elements
00054 //  by a threshold. The neighborhoods are 8-connected.
00055 //  The result is an array with non-zero elements at minima.
00056 //  The value of non-zero element indicates the smallest difference
00057 //  between the minima and the neighboring elements.
00058 template <class T>
00059 vbl_array_3d<T> vbl_local_minima(vbl_array_3d<T> const& in, T thresh = T(0))
00060 {
00061   vbl_array_3d<T> m=in;
00062   if (local_minima(in, m, thresh)) return m;
00063   else return vbl_array_3d<T>();
00064 }
00065 
00066 
00067 //: DEPRECATED
00068 // \deprecated in favour of vbl_local_minima
00069 template <class T>
00070 bool local_minima(vbl_array_1d<T> const& in, vbl_array_1d<T>& minima,
00071                   T thresh = T(0));
00072 
00073 //: DEPRECATED
00074 // \deprecated in favour of vbl_local_minima
00075 template <class T>
00076 bool local_minima(vbl_array_2d<T> const& in, vbl_array_2d<T>& minima,
00077                   T thresh = T(0));
00078 
00079 //: DEPRECATED
00080 // \deprecated in favour of vbl_local_minima
00081 template <class T>
00082 bool local_minima(vbl_array_3d<T> const& in, vbl_array_3d<T>& minima,
00083                   T thresh = T(0));
00084 
00085 #endif // vbl_local_minima_h_