Image Component Library (ICL)
DynMatrixUtils.h
Go to the documentation of this file.
1 /********************************************************************
2 ** Image Component Library (ICL) **
3 ** **
4 ** Copyright (C) 2006-2013 CITEC, University of Bielefeld **
5 ** Neuroinformatics Group **
6 ** Website: www.iclcv.org and **
7 ** http://opensource.cit-ec.de/projects/icl **
8 ** **
9 ** File : ICLMath/src/ICLMath/DynMatrixUtils.h **
10 ** Module : ICLMath **
11 ** Authors: Christof Elbrechter, Daniel Dornbusch **
12 ** **
13 ** **
14 ** GNU LESSER GENERAL PUBLIC LICENSE **
15 ** This file may be used under the terms of the GNU Lesser General **
16 ** Public License version 3.0 as published by the **
17 ** **
18 ** Free Software Foundation and appearing in the file LICENSE.LGPL **
19 ** included in the packaging of this file. Please review the **
20 ** following information to ensure the license requirements will **
21 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt **
22 ** **
23 ** The development of this software was supported by the **
24 ** Excellence Cluster EXC 277 Cognitive Interaction Technology. **
25 ** The Excellence Cluster EXC 277 is a grant of the Deutsche **
26 ** Forschungsgemeinschaft (DFG) in the context of the German **
27 ** Excellence Initiative. **
28 ** **
29 ********************************************************************/
30 
31 #pragma once
32 
33 #include <ICLUtils/CompatMacros.h>
34 #include <ICLMath/DynMatrix.h>
35 #include <ICLUtils/BasicTypes.h>
36 #include <algorithm>
37 
38 namespace icl{
39  namespace math{
40 
43 
60  template<class T, class Init>
61  inline DynMatrix<T> &matrix_init(DynMatrix<T> &m, Init init){
62  std::fill(m.begin(),m.end(),init);
63  return m;
64  }
65 
67 
68  template<class T> ICLMath_IMP
70 
72 
73  template<class T> ICLMath_IMP
75 
77 
78  template<class T> ICLMath_IMP
80 
82 
83  template<class T> ICLMath_IMP
85 
87 
88  template<class T> ICLMath_IMP
90 
92 
93  template<class T> ICLMath_IMP
95 
97 
98  template<class T> ICLMath_IMP
100 
102 
103  template<class T> ICLMath_IMP
105 
107 
108  template<class T> ICLMath_IMP
110 
112 
113  template<class T> ICLMath_IMP
115 
117 
118  template<class T> ICLMath_IMP
120 
122 
123  template<class T> ICLMath_IMP
125 
127 
128  template<class T> ICLMath_IMP
130 
132 
133  template<class T> ICLMath_IMP
135 
137 
138  template<class T> ICLMath_IMP
140 
142 
143  template<class T> ICLMath_IMP
145 
147 
148  template<class T> ICLMath_IMP
150 
152 
153  template<class T> ICLMath_IMP
155 
157 
158  template<class T> ICLMath_IMP
160 
162 
163  template<class T> ICLMath_IMP
165 
167 
168  template<class T> ICLMath_IMP
170 
172 
173  template<class T> ICLMath_IMP
175 
177 
178  template<class T> ICLMath_IMP
180 
182 
183  template<class T> ICLMath_IMP
185 
188 
190  template<class T> ICLMath_IMP
191  DynMatrix<T> &matrix_powc(DynMatrix<T> &m, T exponent);
192 
194 
195  template<class T> ICLMath_IMP
196  DynMatrix<T> &matrix_powc(const DynMatrix<T> &m, T exponent, DynMatrix<T> &dst);
197 
199 
200  template<class T> ICLMath_IMP
202 
204 
205  template<class T> ICLMath_IMP
206  DynMatrix<T> &matrix_addc(const DynMatrix<T> &m, T val, DynMatrix<T> &dst);
207 
209 
210  template<class T> ICLMath_IMP
212 
214 
215  template<class T> ICLMath_IMP
216  DynMatrix<T> &matrix_subc(const DynMatrix<T> &m, T val, DynMatrix<T> &dst);
217 
219 
220  template<class T> ICLMath_IMP
222 
224 
225  template<class T> ICLMath_IMP
226  DynMatrix<T> &matrix_divc(const DynMatrix<T> &m, T val, DynMatrix<T> &dst);
227 
229 
230  template<class T> ICLMath_IMP
232 
234 
235  template<class T> ICLMath_IMP
236  DynMatrix<T> &matrix_mulc(const DynMatrix<T> &m, T val, DynMatrix<T> &dst);
237 
240 
242  template<class T> ICLMath_IMP
244  ;
245 
247 
248  template<class T> ICLMath_IMP
249  DynMatrix<T> &matrix_add(const DynMatrix<T> &m1, const DynMatrix<T> &m2, DynMatrix<T> &dst)
250  ;
251 
253 
254  template<class T> ICLMath_IMP
255  DynMatrix<T> &matrix_sub(const DynMatrix<T> &m1, const DynMatrix<T> &m2, DynMatrix<T> &dst)
256  ;
257 
259 
260  template<class T> ICLMath_IMP
261  DynMatrix<T> &matrix_mul(const DynMatrix<T> &m1, const DynMatrix<T> &m2, DynMatrix<T> &dst)
262  ;
263 
265 
266  template<class T> ICLMath_IMP
267  DynMatrix<T> &matrix_div(const DynMatrix<T> &m1, const DynMatrix<T> &m2, DynMatrix<T> &dst)
268  ;
269 
271 
272  template<class T> ICLMath_IMP
273  DynMatrix<T> &matrix_pow(const DynMatrix<T> &m1, const DynMatrix<T> &m2, DynMatrix<T> &dst)
274  ;
275 
279 
283  template<class T> ICLMath_IMP
284  T matrix_distance(const DynMatrix<T> &m1, const DynMatrix<T> &m2, T norm = 2)
285  ;
286 
288 
291  template<class T> ICLMath_IMP
292  T matrix_divergence(const DynMatrix<T> &m1, const DynMatrix<T> &m2)
293  ;
294 
295 
299 
305  template<class T> ICLMath_IMP
306  T matrix_min(const DynMatrix<T> &m, int *x = 0, int *y = 0);
307 
309 
314  template<class T> ICLMath_IMP
315  T matrix_max(const DynMatrix<T> &m, int *x = 0, int *y = 0);
316 
318 
327  template<class T> ICLMath_IMP
328  void matrix_minmax(const DynMatrix<T> &m, T dst[2],
329  int *minx=0, int *miny=0,
330  int *maxx=0, int *maxy=0);
331 
332 
334 
335  template<class T> ICLMath_IMP
336  T matrix_mean(const DynMatrix<T> &m);
337 
339 
340  template<class T> ICLMath_IMP
341  T matrix_var(const DynMatrix<T> &m);
342 
344 
354  template<class T> ICLMath_IMP
355  T matrix_var(const DynMatrix<T> &m, T mean, bool empiricalMean = true);
356 
358 
361  template<class T> ICLMath_IMP
362  void matrix_meanvar(const DynMatrix<T> &m, T *mean, T*var);
363 
365 
366  template<class T> ICLMath_IMP
367  T matrix_stddev(const DynMatrix<T> &m);
368 
370 
380  template<class T> ICLMath_IMP
381  T matrix_stddev(const DynMatrix<T> &m, T mean, bool empiricalMean = true);
382 
386 
388  template<class T> ICLMath_IMP
389  DynMatrix<T> &matrix_muladd(const DynMatrix<T> &a, T alpha, const DynMatrix<T> &b, T beta, T gamma, DynMatrix<T> &dst)
390  ;
391 
393 
394  template<class T> ICLMath_IMP
395  DynMatrix<T> &matrix_muladd(const DynMatrix<T> &a, T alpha, T gamma, DynMatrix<T> &dst);
396 
398 
399  template<class T> ICLMath_IMP
401  ;
402 
404 
405  template<class T> ICLMath_IMP
407  ;
408 
414  enum transposedDef{
417  SRC1_T=1<<0,
418  SRC2_T=1<<1,
420  };
421 
423 
434  template<class T> ICLMath_IMP
435  DynMatrix<T> &matrix_mult_t(const DynMatrix<T> &src1, const DynMatrix<T> &src2, DynMatrix<T> &dst, int transpDef)
436  ;
437 
439 
450  template<class T> ICLMath_IMP
451  DynMatrix<T> &big_matrix_mult_t(const DynMatrix<T> &src1, const DynMatrix<T> &src2, DynMatrix<T> &dst, int transpDef)
452  ;
453 
455  template<class T> ICLMath_IMP
456  DynMatrix<T> &matrix_add_t(const DynMatrix<T> &src1, const DynMatrix<T> &src2, DynMatrix<T> &dst, int transpDef)
457  ;
458 
460  template<class T> ICLMath_IMP
461  DynMatrix<T> &matrix_sub_t(const DynMatrix<T> &src1, const DynMatrix<T> &src2, DynMatrix<T> &dst, int transpDef)
462  ;
463 
466 
473  template<class T> ICLMath_IMP
474  void svd_dyn(const DynMatrix<T> &A, DynMatrix<T> &U, DynMatrix<T> &S, DynMatrix<T> &V) ;
475 
476 
477  #if 0
478  U.setBounds(A.cols(), A.rows());
479  V.setBounds(A.cols(), A.cols());
480  s.setBounds(1,A.cols());
481  DynMatrix<icl64f> A64f(A.cols(),A.rows()),U64f(U.cols(),U.rows()),s64f(1,s.rows()),V64f(V.cols(),V.rows());
482  std::copy(A.begin(),A.end(),A64f.begin());
483 
484  svd_cpp_64f(A64f,U64f,s64f,V64f);
485 
486  std::copy(U64f.begin(),U64f.end(),U.begin());
487  std::copy(V64f.begin(),V64f.end(),V.begin());
488  std::copy(s64f.begin(),s64f.end(),s.begin());
489  }
490 
492  // SVD specialization for direct call to 64f function in order to avoid unnecessary double to double conversion before hand
493  template<> inline void svd_dyn<icl64f>(const DynMatrix<icl64f> &A, DynMatrix<icl64f> &U, DynMatrix<icl64f> &s, DynMatrix<icl64f> &V) {
494  U.setBounds(A.cols(), A.rows());
495  V.setBounds(A.cols(), A.cols());
496  s.setBounds(1,A.cols());
497 
498  svd_cpp_64f(A,U,s,V);
499  }
502  #endif
503 
506  } // namespace math
507 }
ICLMath_IMP T matrix_mean(const DynMatrix< T > &m)
calculate matrix mean value [IPP-optimized]
Definition: DynMatrixUtils.h:417
undocument this line if you encounter any issues!
Definition: Any.h:37
DynMatrix< T > & matrix_init(DynMatrix< T > &m, Init init)
Matrix initialization template.
Definition: DynMatrixUtils.h:61
ICLQt_API core::Img< T > norm(const core::Img< T > &image)
normalize an images range to [0,255]
ICLMath_IMP DynMatrix< T > & matrix_arcsin(DynMatrix< T > &m)
element-wise arcus sinus-function (inplace)
ICLMath_IMP void matrix_minmax(const DynMatrix< T > &m, T dst[2], int *minx=0, int *miny=0, int *maxx=0, int *maxy=0)
find min- and maxinim element at once (optionally with locations) [IPP-optimized]
ICLMath_IMP DynMatrix< T > & matrix_pow(const DynMatrix< T > &m1, const DynMatrix< T > &m2, DynMatrix< T > &dst)
element-wise power
ICLMath_IMP DynMatrix< T > & matrix_sqrt(DynMatrix< T > &m)
element-wise square-root-function (inplace) [IPP-optimized]
ICLMath_IMP DynMatrix< T > & matrix_sqr(DynMatrix< T > &m)
element-wise square-function (x*x) (inplace) [IPP-optimized]
double mean(ForwardIterator begin, ForwardIterator end)
computes the mean value of a data range
Definition: MathFunctions.h:78
Highly flexible and optimized matrix class implementation.
Definition: DynMatrix.h:81
ICLMath_IMP DynMatrix< T > & matrix_mulc(DynMatrix< T > &m, T val)
element-wise multiplication with constant value (inplace) [IPP-optimized]
ICLMath_IMP DynMatrix< T > & matrix_arctan(DynMatrix< T > &m)
element-wise arcus tangent-function (inplace)
iterator begin()
returns an iterator to the begin of internal data array
Definition: DynMatrix.h:751
ICLMath_IMP DynMatrix< T > & matrix_arctan2(const DynMatrix< T > &my, const DynMatrix< T > &mx, DynMatrix< T > &dst)
element-wise atan2 function atan2(y,x)
ICLMath_IMP DynMatrix< T > & matrix_reciprocal(DynMatrix< T > &m)
element-wise reciprocal-function (1/x) (inplace)
ICLMath_IMP DynMatrix< T > & matrix_mask(const DynMatrix< unsigned char > &mask, DynMatrix< T > &m)
applies masking operation (m(i,j) is set to 0 if mask(i,j) is 0) (inplace)
ICLMath_IMP DynMatrix< T > & matrix_muladd(const DynMatrix< T > &a, T alpha, const DynMatrix< T > &b, T beta, T gamma, DynMatrix< T > &dst)
computes alpha*a + beta*b + gamma
ICLMath_IMP DynMatrix< T > & matrix_powc(DynMatrix< T > &m, T exponent)
element-wise power-function (x^exponent) (inplace)
ICLMath_IMP T matrix_var(const DynMatrix< T > &m)
calculate matrix variance [IPP-optimized]
transposedDef
special utility type for definition of transposed states for matrices
Definition: DynMatrixUtils.h:415
ICLMath_IMP DynMatrix< T > & matrix_tan(DynMatrix< T > &m)
element-wise tangent-function (inplace)
ICLMath_IMP DynMatrix< T > & matrix_divc(DynMatrix< T > &m, T val)
element-wise division by constant value (inplace) [IPP-optimized]
ICLMath_IMP DynMatrix< T > & matrix_div(const DynMatrix< T > &m1, const DynMatrix< T > &m2, DynMatrix< T > &dst)
element-wise division [IPP-optimized]
ICLMath_IMP DynMatrix< T > & matrix_sub(const DynMatrix< T > &m1, const DynMatrix< T > &m2, DynMatrix< T > &dst)
element-wise substraction [IPP-optimized]
ICLMath_IMP void matrix_meanvar(const DynMatrix< T > &m, T *mean, T *var)
computes matrix mean and variance at once [IPP-optimized]
ICLQt_API void fill(float r, float g=-1, float b=-1, float alpha=255)
sets the current fill color to given r,g,b,alpha value
ICLMath_IMP DynMatrix< T > & matrix_add(const DynMatrix< T > &m1, const DynMatrix< T > &m2, DynMatrix< T > &dst)
element-wise addition [IPP-optimized]
ICLMath_IMP DynMatrix< T > & matrix_sin(DynMatrix< T > &m)
element-wise sinus-function (x*x) (inplace)
Definition: DynMatrixUtils.h:416
ICLMath_IMP T matrix_divergence(const DynMatrix< T > &m1, const DynMatrix< T > &m2)
computes generalized Kullback-Leibler-divergence between matrix vectors
Definition: DynMatrixUtils.h:418
iterator end()
returns an iterator to the end of internal data array
Definition: DynMatrix.h:754
Definition: DynMatrixUtils.h:419
ICLMath_IMP DynMatrix< T > & matrix_arccos(DynMatrix< T > &m)
element-wise arcus cosinus-function (inplace)
ICLMath_IMP DynMatrix< T > & big_matrix_mult_t(const DynMatrix< T > &src1, const DynMatrix< T > &src2, DynMatrix< T > &dst, int transpDef)
applies matrix mutliplication on optionally transposed matrices (specialized for big matrices)
ICLMath_IMP void svd_dyn(const DynMatrix< T > &A, DynMatrix< T > &U, DynMatrix< T > &S, DynMatrix< T > &V)
SVD function - decomposes A into USV' (only icl32f and icl64f)
ICLMath_IMP T matrix_min(const DynMatrix< T > &m, int *x=0, int *y=0)
find minimum element of matrix (optionally find location too) [IPP-optimized]
ICLMath_IMP T matrix_distance(const DynMatrix< T > &m1, const DynMatrix< T > &m2, T norm=2)
computes norm between matrix vectors
ICLMath_IMP DynMatrix< T > & matrix_abs(DynMatrix< T > &m)
element-wise absolute value (inplace) [IPP-optimized]
#define ICLMath_IMP
Definition: CompatMacros.h:172
ICLMath_IMP DynMatrix< T > & matrix_mul(const DynMatrix< T > &m1, const DynMatrix< T > &m2, DynMatrix< T > &dst)
element-wise multiplication [IPP-optimized]
ICLMath_IMP DynMatrix< T > & matrix_exp(DynMatrix< T > &m)
element-wise exp-function (inplace) [IPP-optimized]
ICLMath_IMP DynMatrix< T > & matrix_sub_t(const DynMatrix< T > &src1, const DynMatrix< T > &src2, DynMatrix< T > &dst, int transpDef)
applies matrix substraction on optionally transposed matrices
ICLMath_IMP T matrix_stddev(const DynMatrix< T > &m)
computes matrix standard deviation (sqrt(var)) [IPP-optimized]
void copy(const T *src, const T *srcEnd, T *dst)
moves data from source to destination array (no casting possible)
Definition: CoreFunctions.h:216
ICLMath_IMP DynMatrix< T > & matrix_addc(DynMatrix< T > &m, T val)
element-wise addition of constant value (inplace) [IPP-optimized]
ICLMath_IMP DynMatrix< T > & matrix_log(DynMatrix< T > &m)
element-wise logarith (basis E) (inplace) [IPP-optimized]
ICLMath_IMP DynMatrix< T > & matrix_cos(DynMatrix< T > &m)
element-wise cosinus-function (inplace)
ICLMath_IMP T matrix_max(const DynMatrix< T > &m, int *x=0, int *y=0)
find maximum element of matrix (optionally find location too) [IPP-optimized]
ICLMath_IMP DynMatrix< T > & matrix_subc(DynMatrix< T > &m, T val)
element-wise substraction of constant value (inplace) [IPP-optimized]
ICLMath_IMP DynMatrix< T > & matrix_add_t(const DynMatrix< T > &src1, const DynMatrix< T > &src2, DynMatrix< T > &dst, int transpDef)
applies matrix addition on optionally transposed matrices
ICLMath_IMP DynMatrix< T > & matrix_mult_t(const DynMatrix< T > &src1, const DynMatrix< T > &src2, DynMatrix< T > &dst, int transpDef)
applies matrix mutliplication on optionally transposed matrices