X-Boost  2.3.8
IntegralChannelFeature.h
1 /* XBoost: Ada-Boost and Friends on Haar/ICF/HOG Features, Library and ToolBox
2  *
3  * Copyright (c) 2008-2014 Paolo Medici <medici@ce.unipr.it>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20 
21 #ifndef _INTEGRAL_CHANNEL_FEATURE_H
22 #define _INTEGRAL_CHANNEL_FEATURE_H
23 
28 #include <vector>
29 #include <iostream>
31 
32 #ifdef __SSE4_1__
33 # include <smmintrin.h>
34 # include <emmintrin.h>
35 # include <mmintrin.h>
36 #endif
37 
38 // FWD
40 
45  int x0,y0,x1,y1;
47  int channel;
48 public:
49 
51  typedef unsigned int InputDataType;
52 
55 
57  typedef int DescriptorType;
58 
59  enum { InvokeParam = 2 };
60 public:
61 
63 
65  IntegralChannelFeature(const IntegralChannelFeature &src, int scale, long offset, long stride)
66  {
67  std::cerr << "cannot allocate ichn @ scale"<<std::endl;
68  }
69  void invert_polarity()
70  {
71  std::cerr << "cannot invert polarity"<<std::endl;
72  }
73 
74  const char *debug_name() {
75  // TODO: use a global object with real-names
76  static const char *channel_name[]={"c0","c1","c2", "c3", "c4", "c5", "c6", "c7", "c8", "c9", "c10", "c11", "c12", "c13", "c14", "c15", "c16" };
77  return channel_name[channel];
78  }
79  static void debug_name(const char *str) { }
80 
82  static std::string signature() { return "icf"; }
83 
84  // params: first stride1 second stride2
85  inline int response(const unsigned int *pIntImage, const std::pair<int32_t,int32_t> & params) const
86  {
87  pIntImage += channel * params.second;
88  return (int) pIntImage[x1 + y1 * params.first] +
89  (int) pIntImage[x0 + y0 * params.first] -
90  (int) pIntImage[x1 + y0 * params.first] -
91  (int) pIntImage[x0 + y1 * params.first];
92  }
93 
97  void rescale(int sx, int sy)
98  {
99  x0 = (x0 * sx + sx - 1);
100  y0 = (y0 * sy + sy - 1);
101  x1 = (x1 * sx + sx - 1);
102  y1 = (y1 * sy + sy - 1);
103  }
104 };
105 
106 
107  std::istream & operator >> (std::istream & in, IntegralChannelFeature & s);
108  std::ostream & operator << (std::ostream & out, const IntegralChannelFeature & s);
109 
111 
114  int A,B,C,D;
115 
117 
118 public:
119 
120  // TODO
122 
124 OptimizedIntegralChannelFeature(const OptimizedIntegralChannelFeature &src, int scale, long offset, long stride)
125  {
126  std::cerr << "cannot allocate ichn @ scale"<<std::endl;
127  }
128 
129  void invert_polarity()
130  {
131  std::cerr << "cannot invert polarity"<<std::endl;
132  }
135 OptimizedIntegralChannelFeature(const IntegralChannelFeature &src, long offset, long stride1, long stride2)
136 {
137  A = offset + src.x0 + src.y0 * stride1 + src.channel * stride2;
138  B = offset + src.x0 + src.y1 * stride1 + src.channel * stride2;
139  C = offset + src.x1 + src.y0 * stride1 + src.channel * stride2;
140  D = offset + src.x1 + src.y1 * stride1 + src.channel * stride2;
141 }
142 
144 {
145  A = offset + src.x0 + src.y0 * p.stride1 + src.channel * p.stride2;
146  B = offset + src.x0 + src.y1 * p.stride1 + src.channel * p.stride2;
147  C = offset + src.x1 + src.y0 * p.stride1 + src.channel * p.stride2;
148  D = offset + src.x1 + src.y1 * p.stride1 + src.channel * p.stride2;
149 }
150 
152 inline int response(const unsigned int *pIntImage) const
153 {
154  return (int) pIntImage[A] + (int) pIntImage[D] - (int) pIntImage[B] - (int) pIntImage[C];
155 }
156 
157 #ifdef __SSE4_1__
158 inline __m128i response4(const unsigned int *pIntImage) const
160 {
161  __m128i p1 = _mm_load_si128((__m128i *)( (long) (pIntImage + A) ) );
162  __m128i p2 = _mm_load_si128((__m128i *)( (long) (pIntImage + D) ) );
163  __m128i p3 = _mm_load_si128((__m128i *)( (long) (pIntImage + B) ) );
164  __m128i p4 = _mm_load_si128((__m128i *)( (long) (pIntImage + C) ) );
165  p1 = _mm_add_epi32(p1, p2);
166  p3 = _mm_add_epi32(p3, p4);
167  return _mm_sub_epi32(p1, p3);
168 }
169 #endif
170 
171 };
172 
173 #endif
int channel
channel identifier
Definition: IntegralChannelFeature.h:47
OptimizedIntegralChannelFeature(const IntegralChannelFeature &src, long offset, long stride1, long stride2)
Definition: IntegralChannelFeature.h:135
static std::string signature()
Definition: IntegralChannelFeature.h:82
int DescriptorType
type of data returned by this feature extractor
Definition: IntegralChannelFeature.h:57
IntegralChannelFeature(const IntegralChannelFeature &src, int scale, long offset, long stride)
Definition: IntegralChannelFeature.h:65
unsigned int InputDataType
type of data requested by this Feature Extractor
Definition: IntegralChannelFeature.h:51
OptimizedIntegralChannelFeature OptimizedType
The feature type used during fast execution:
Definition: IntegralChannelFeature.h:54
void rescale(int sx, int sy)
Definition: IntegralChannelFeature.h:97
an optimized SumAreaFeature
Definition: IntegralChannelFeature.h:113
int response(const unsigned int *pIntImage) const
compute the response
Definition: IntegralChannelFeature.h:152
parameters required to address a channel params
Definition: IntegralChannelImagePreprocessor.h:36
Sum of a rectangular area, implemented on top of Integral Image.
Definition: IntegralChannelFeature.h:42
method to convert an image sample in integral Channels Image
OptimizedIntegralChannelFeature(const OptimizedIntegralChannelFeature &src, int scale, long offset, long stride)
Definition: IntegralChannelFeature.h:124
int x0
Definition: IntegralChannelFeature.h:45