From 6ca45db06eead31a9920364f0d47c0a51bf8a96a Mon Sep 17 00:00:00 2001 From: Davis King Date: Sun, 7 Dec 2014 11:00:11 -0500 Subject: [PATCH] Added max_point() --- dlib/matrix/matrix_utilities.h | 35 +++++++++++++++++++++++++ dlib/matrix/matrix_utilities_abstract.h | 13 +++++++++ 2 files changed, 48 insertions(+) diff --git a/dlib/matrix/matrix_utilities.h b/dlib/matrix/matrix_utilities.h index e9c328e0d..5e61f4ecf 100644 --- a/dlib/matrix/matrix_utilities.h +++ b/dlib/matrix/matrix_utilities.h @@ -122,6 +122,41 @@ namespace dlib } } +// ---------------------------------------------------------------------------------------- + + template < + typename EXP + > + point max_point ( + const matrix_exp& m + ) + { + DLIB_ASSERT(m.size() > 0, + "\tpoint max_point(const matrix_exp& m)" + << "\n\tm can't be empty" + << "\n\tm.size(): " << m.size() + << "\n\tm.nr(): " << m.nr() + << "\n\tm.nc(): " << m.nc() + ); + typedef typename matrix_exp::type type; + + point best_point(0,0); + type val = m(0,0); + for (long r = 0; r < m.nr(); ++r) + { + for (long c = 0; c < m.nc(); ++c) + { + type temp = m(r,c); + if (dlib::impl::magnitude(temp) > dlib::impl::magnitude(val)) + { + val = temp; + best_point = point(c,r); + } + } + } + return best_point; + } + // ---------------------------------------------------------------------------------------- template < diff --git a/dlib/matrix/matrix_utilities_abstract.h b/dlib/matrix/matrix_utilities_abstract.h index cd02c03d2..e5d62f566 100644 --- a/dlib/matrix/matrix_utilities_abstract.h +++ b/dlib/matrix/matrix_utilities_abstract.h @@ -1409,6 +1409,19 @@ namespace dlib (i.e. m(index_of_min(m)) == min(m)) !*/ +// ---------------------------------------------------------------------------------------- + + point max_point ( + const matrix_exp& m + ); + /*! + requires + - m.size() > 0 + ensures + - returns the location of the maximum element of the array, that is, if the + returned point is P then it will be the case that: m(P.y(),P.x()) == max(m). + !*/ + // ---------------------------------------------------------------------------------------- const matrix_exp::type sum (