00001 #ifndef Impala_Core_Feature_HaarResponse_h
00002 #define Impala_Core_Feature_HaarResponse_h
00003
00004 #include "Core/Array/Arrays.h"
00005 #include "Core/Array/Abs.h"
00006
00007 namespace Impala
00008 {
00009 namespace Core
00010 {
00011 namespace Feature
00012 {
00013
00014
00015 void
00016 HaarFirstLine(std::vector<Array::Array2dScalarReal64*>& response,
00017 Array::Array2dScalarReal64* image, int y)
00018 {
00019 double* sPtr = image->CPB(0, y);
00020 double* sPtr2 = sPtr+1;
00021 double* dPtrH = response[0]->CPB(0, y);
00022 double* dPtrV = response[1]->CPB(0, y);
00023 for(int x=0 ; x<image->W()-1 ; ++x)
00024 {
00025 double h = *sPtr2 - *sPtr;
00026 double v = *sPtr + *sPtr2;
00027 *dPtrH = h;
00028 *dPtrV = -v;
00029 ++dPtrH;
00030 ++dPtrV;
00031 ++sPtr;
00032 ++sPtr2;
00033 }
00034 }
00035
00036
00037 void
00038 HaarSecondLine(std::vector<Array::Array2dScalarReal64*>& response,
00039 Array::Array2dScalarReal64* image, int y)
00040 {
00041 double* sPtr = image->CPB(0, y);
00042 double* sPtr2 = sPtr+1;
00043 double* dPtrH = response[0]->CPB(0, y-1);
00044 double* dPtrV = response[1]->CPB(0, y-1);
00045 for(int x=0 ; x<image->W()-1 ; ++x)
00046 {
00047 double h = *sPtr2 - *sPtr;
00048 double v = *sPtr + *sPtr2;
00049 *dPtrH += h;
00050 *dPtrV += v;
00051 ++sPtr;
00052 ++sPtr2;
00053 ++dPtrH;
00054 ++dPtrV;
00055 }
00056 }
00057
00074 std::vector<Array::Array2dScalarReal64*>
00075 HaarResponse(Array::Array2dScalarReal64* image)
00076 {
00077 std::vector<Array::Array2dScalarReal64*> response;
00078 int w = image->W()-1;
00079 int h = image->H()-1;
00080 response.push_back(new Array::Array2dScalarReal64(w, h, 0, 0));
00081 response.push_back(new Array::Array2dScalarReal64(w, h, 0, 0));
00082 for(int y=0 ; y<image->H()-1 ; ++y)
00083 {
00084 HaarFirstLine(response, image, y);
00085 HaarSecondLine(response, image, y+1);
00086 }
00087 response.push_back(new Array::Array2dScalarReal64(w,h,0,0));
00088 response.push_back(new Array::Array2dScalarReal64(w,h,0,0));
00089 Abs(response[2],response[0]);
00090 Abs(response[3],response[1]);
00091 return response;
00092 }
00093
00094 }
00095 }
00096 }
00097
00098 #endif