From c2199009807f3aa1f646e7e2c7472233857b3a2f Mon Sep 17 00:00:00 2001 From: Davis King Date: Sun, 25 Oct 2015 18:13:22 -0400 Subject: [PATCH] Added image_plane() --- dlib/dnn/tensor.h | 25 +++++++++++++++++++++++++ dlib/dnn/tensor_abstract.h | 20 ++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/dlib/dnn/tensor.h b/dlib/dnn/tensor.h index bf015d43c..d8be005d2 100644 --- a/dlib/dnn/tensor.h +++ b/dlib/dnn/tensor.h @@ -241,6 +241,31 @@ namespace dlib return mat(t, t.num_samples(), t.size()/t.num_samples()); } + inline const matrix_op > image_plane ( + const tensor& t, + long sample = 0, + long k = 0 + ) + { + DLIB_ASSERT(0 <= sample && sample < t.num_samples() && + 0 <= k && k < t.k() && + t.size() != 0, + "\tconst matrix_exp image_plane(tensor,sample,k)" + << "\n\t Invalid arguments were given to this function." + << "\n\t sample: " << sample + << "\n\t k: " << k + << "\n\t t.num_samples(): " << t.num_samples() + << "\n\t t.k(): " << t.k() + << "\n\t t.size(): " << t.size() + ); + + + typedef op_pointer_to_mat op; + return matrix_op(op(t.host() + ((sample*t.k() + k)*t.nr())*t.nc(), + t.nr(), + t.nc())); + } + // ---------------------------------------------------------------------------------------- inline bool have_same_dimensions ( diff --git a/dlib/dnn/tensor_abstract.h b/dlib/dnn/tensor_abstract.h index 2bc8c6c5d..9a1169765 100644 --- a/dlib/dnn/tensor_abstract.h +++ b/dlib/dnn/tensor_abstract.h @@ -295,6 +295,26 @@ namespace dlib - returns mat(t, t.num_samples(), t.size()/t.num_samples()) !*/ + const matrix_exp image_plane ( + const tensor& t, + long sample = 0, + long k = 0 + ); + /*! + requires + - t.size() != 0 + - 0 <= sample < t.num_samples() + - 0 <= k < t.k() + ensures + - returns the k-th image plane from the sample-th image in t. That is, + returns a matrix M such that: + - M contains float valued elements. + - M.nr() == t.nr() + - M.nc() == t.nc() + - for all valid r and c: + - M(r,c) == t.host()[((sample*t.k() + k)*t.nr() + r)*t.nc() + c] + !*/ + // ---------------------------------------------------------------------------------------- bool have_same_dimensions (