KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
l_ew.h
Go to the documentation of this file.
1 /* $Id: l_ew.h 17249 2014-08-07 16:03:32Z predoehl $ */
2 /* =========================================================================== *
3  |
4  | Copyright (c) 1994-2010 by Kobus Barnard (author)
5  |
6  | Personal and educational use of this code is granted, provided that this
7  | header is kept intact, and that the authorship is not misrepresented, that
8  | its use is acknowledged in publications, and relevant papers are cited.
9  |
10  | For other use contact the author (kobus AT cs DOT arizona DOT edu).
11  |
12  | Please note that the code in this file has not necessarily been adequately
13  | tested. Naturally, there is no guarantee of performance, support, or fitness
14  | for any particular task. Nonetheless, I am interested in hearing about
15  | problems that you encounter.
16  |
17  | Author: Ernesto Brau
18  * =========================================================================== */
19 
20 #ifndef KJB_L_EW_DEFINED
21 #define KJB_L_EW_DEFINED
22 
29 namespace kjb
30 {
31 
42 template<class Indexable>
43 Indexable ew_multiply(const Indexable& I, const Indexable& J)
44 {
45  Indexable K = I;
46  for(int i = 0; i < I.get_length(); i++)
47  {
48  K(i) = K(i) * J(i);
49  }
50 
51  return K;
52 }
53 
57 template<class Indexable>
58 void ew_abs_ow(Indexable& I)
59 {
60  for(int i = 0; i < I.get_length(); i++)
61  {
62  I(i) = abs(I(i));
63  }
64 }
65 
70 template<class Indexable>
71 void ew_square_ow(Indexable& I)
72 {
73  for(int i = 0; i < I.get_length(); i++)
74  {
75  I(i) = I(i) * I(i);
76  }
77 }
78 
83 template<class Indexable>
84 Indexable ew_square(const Indexable& I)
85 {
86  Indexable M = I;
87  ew_square_ow(M);
88  return M;
89 }
90 
95 template<class Indexable>
96 void ew_sqrt_ow(Indexable& I)
97 {
98  for(int i = 0; i < I.get_length(); i++)
99  {
100  using ::sqrt;
101  I(i) = sqrt(I(i));
102  }
103 }
104 
109 template<class Indexable>
110 Indexable ew_sqrt(const Indexable& I)
111 {
112  Indexable M = I;
113  ew_sqrt_ow(M);
114  return M;
115 }
116 
118 
119 } //namespace kjb
120 
121 #endif /* KJB_L_EW_DEFINED */
122 
void ew_square_ow(Indexable &I)
Square the elements of an indexable class in place. I must be indexed via operator().
Definition: l_ew.h:71
void ew_abs_ow(Indexable &I)
Element-wise abosulte value.
Definition: l_ew.h:58
void ew_sqrt_ow(Indexable &I)
Take the square root of the elements of an indexable class in place. I must be indexed via operator()...
Definition: l_ew.h:96
Indexable ew_sqrt(const Indexable &I)
Take the square root the elements of an indexable class; the result is returned. I must be indexed vi...
Definition: l_ew.h:110
for I
Definition: APPgetLargeConnectedEdges.m:141
kjb_c::Pixel abs(const kjb_c::Pixel &p)
Take the channel-wise absolute value of a kjb_c::Pixel.
Definition: i_pixel.h:354
Indexable ew_multiply(const Indexable &I, const Indexable &J)
Multiply the elements of two Indexable things. Must be indexed via operator() and assignable...
Definition: l_ew.h:43
Indexable ew_square(const Indexable &I)
Square the elements of an indexable class; the result is returned. I must be indexed via operator()...
Definition: l_ew.h:84
get the indices of edges in each direction for i
Definition: APPgetLargeConnectedEdges.m:48