21 #ifndef _INTEGRAL_CHANNEL_IMAGE_PREPROCS_H
22 #define _INTEGRAL_CHANNEL_IMAGE_PREPROCS_H
29 #include "IntegralImage.h"
37 long stride1, stride2;
38 unsigned int width, height, nchannels;
40 inline unsigned int Width()
const {
43 inline unsigned int Height()
const {
46 inline unsigned int NChannels()
const {
54 return (b.width == width) && (b.height == height) && (b.nchannels == nchannels);
66 #define ICF_GENERATE_ATAN2_TABLE
74 bool m_useOrientationSign;
76 unsigned int m_nOrientationBin;
78 bool m_magnitudeChannel;
80 bool m_luminanceChannel;
82 int m_derivativeFilter;
87 #ifdef ICF_GENERATE_ATAN2_TABLE
88 unsigned char *table_atan2_module;
115 void Configure(
bool orientationSign,
int nOrientationBin,
bool magnitudeChannel,
bool luminanceChannel,
int derivativeFilter);
118 void Configure(
const char* str);
119 void Configure(std::istream & in);
121 void GetConf(
char* strconf)
const
124 strPconf[0] = m_nOrientationBin + 0x30;
126 if(m_useOrientationSign) strPconf[i++]=
's';
127 if(m_magnitudeChannel) strPconf[i++]=
'm';
128 if(m_luminanceChannel) strPconf[i++]=
'l';
130 strcpy(strconf,strPconf);
133 void GetParam(
ParamType & params,
unsigned int width,
unsigned int height)
const
135 params.width = width;
136 params.height = height;
137 params.nchannels = nChannels;
138 params.stride1 = width+1;
139 params.stride2 = (width+1)*(height);
143 unsigned int DataSize(
unsigned int width,
unsigned int height)
const
145 return sizeof(uint32_t) * (width + 1) * (height * nChannels + 1);
150 memcpy(buf, src.data, n);
155 dst.data =
new uint32_t[n/4];
156 memcpy(dst.data, buf, n);
159 template<
class T,
bool magnitude,
bool luminance>
160 bool core(
unsigned char *buffer,
const T *image,
unsigned int width,
unsigned int height,
unsigned int j0,
unsigned int j1,
long stride)
const
162 unsigned int channel_size = width * height;
163 const int magnitude_offset = m_nOrientationBin * channel_size;
164 const int luminance_offset = (m_nOrientationBin + (magnitude ? 1 : 0) ) * channel_size;
166 #ifndef ICF_GENERATE_ATAN2_TABLE
167 static const float scale = 1.0f / std::sqrt(2.0f);
168 static const float norm_factor = (m_useOrientationSign) ? ((
double)m_nOrientationBin/ (2.0f*M_PI)) : ((double)m_nOrientationBin/ (M_PI));
170 image += j0 * stride;
171 buffer += j0 * width;
174 for(
unsigned int j=j0; j<j1; ++j)
176 for(
unsigned int i=1; i<width-1; ++i)
181 dx = (int)image[i + 1] - (
int)image[i - 1];
182 dy = (int)image[i + stride] - (
int)image[i - stride];
184 #ifndef ICF_GENERATE_ATAN2_TABLE
185 unsigned char m = std::sqrt(dx*dx + dy*dy) *scale;
186 float p = std::atan2( (
float) dy, (
float) dx);
187 int bin = (int) ( (p + M_PI) * norm_factor);
188 bin = (bin) % m_nOrientationBin;
190 unsigned char bin = table_atan2_module[((dx + 255) + (dy + 255) * 512)*2+0];
191 unsigned char m = table_atan2_module[((dx + 255) + (dy + 255) * 512)*2+1];
194 buffer[bin * channel_size + i] = m;
198 buffer[i + magnitude_offset] = m;
202 buffer[i + luminance_offset] = image[i];
215 bool Process(std::pair<IntegralImageData, IntegralChannelImageParams> & out,
const T *image,
unsigned int width,
unsigned int height,
long stride)
const
217 unsigned char *buffer =
new unsigned char [width * height * nChannels];
219 out.second.width = width;
220 out.second.height = height;
221 out.second.stride1 = width+1;
222 out.second.stride2 = (width+1)*(height);
223 out.second.nchannels = nChannels;
226 memset(buffer,0,width*height*nChannels);
229 if(!m_magnitudeChannel && !m_luminanceChannel)
230 core<T, false, false>(buffer, image, width, height, 1, height-1, stride);
232 if(m_magnitudeChannel && !m_luminanceChannel)
233 core<T, true, false>(buffer, image, width, height, 1, height-1, stride);
235 if(!m_magnitudeChannel && m_luminanceChannel)
236 core<T, false, true>(buffer, image, width, height, 1, height-1, stride);
238 if(m_magnitudeChannel && m_luminanceChannel)
239 core<T, true, true>(buffer, image, width, height, 1, height-1, stride);
242 integral_image.
Build(buffer, width, height * nChannels, width,
true);
245 out.first.data = integral_image.data;
a descritor based on a integral image
std::pair< DataType, ParamType > ReturnType
Data provided by this preprocessor.
Definition: IntegralChannelImagePreprocessor.h:101
bool Process(std::pair< IntegralImageData, IntegralChannelImageParams > &out, const T *image, unsigned int width, unsigned int height, long stride) const
compute the ICH
Definition: IntegralChannelImagePreprocessor.h:215
IntegralImageData DataType
Data provided by this Preprocessor.
Definition: IntegralChannelImagePreprocessor.h:95
Definition: IntegralChannelImagePreprocessor.h:70
parameters required to address a channel params
Definition: IntegralChannelImagePreprocessor.h:36
unsigned int DataSize(unsigned int width, unsigned int height) const
compute memory required to serialize/deserialize the preprocessed image
Definition: IntegralChannelImagePreprocessor.h:143
il dato IntegralImage e' pressoche' equivalente a quello di RawData < uint32_t >
Definition: IntegralImageData.h:52
bool operator==(const IntegralChannelImageParams &b) const
to check if parameters are related
Definition: IntegralChannelImagePreprocessor.h:53
void Build(const _S *src, unsigned int width, unsigned int height, long stride, bool extend=false)
Build integral image from buffer.
Definition: IntegralImage.h:202
IntegralChannelImageParams ParamType
Common data provided by this preprocessor.
Definition: IntegralChannelImagePreprocessor.h:98