21 #ifndef __RegionMatcher_hh__
22 #define __RegionMatcher_hh__
24 #include <bias_config.h>
26 #include <Base/Debug/Debug.hh>
27 #include <Base/Debug/Error.hh>
28 #include <MathAlgo/Lapack.hh>
29 #include <Base/Math/Matrix2x2.hh>
30 #include <Base/Math/Vector2.hh>
32 #define D_REGION_MATCHER_SEARCHNCC 0x0001
33 #define D_REGION_MATCHER_KLT 0x0002
34 #define D_REGION_MATCHER_LINE 0x0004
35 #define D_REGION_MATCHER_PARABOLA 0x0008
36 #define D_REGION_MATCHER_COLORNCC 0x0010
37 #define D_REGION_MATCHER_COLORCCV 0x0020
38 #define D_REGION_MATCHER_KLT_EDGE 0x0040
39 #define D_REGION_MATCHER_SEARCH_EVEN 0x0080
40 #define D_REGION_MATCHER_SEARCH_ODD 0x0100
43 #define KLT_TYPE double
51 class BIASImageBase_EXPORT
Image;
55 #define ABSDIFF(a, b) ((a>b)?(a-b):(b-a))
56 #define SAD3x3(x1, y1, x2, y2, ida1, ida2, re)\
57 unsigned x1m=x1-1, x1p=x1+1, y1m=y1-1, y1p=y1+1;\
58 unsigned x2m=x2-1, x2p=x2+1, y2m=y2-1, y2p=y2+1;\
59 re = (unsigned)ABSDIFF(ida1[y1m][x1m], ida2[y2m][x2m]) + \
60 (unsigned)ABSDIFF(ida1[y1m][x1], ida2[y2m][x2]) + \
61 (unsigned)ABSDIFF(ida1[y1m][x1p], ida2[y2m][x2p]) + \
62 (unsigned)ABSDIFF(ida1[y1][x1m], ida2[y2][x2m]) + \
63 (unsigned)ABSDIFF(ida1[y1][x1], ida2[y2][x2]) + \
64 (unsigned)ABSDIFF(ida1[y1][x1p], ida2[y2][x2p]) + \
65 (unsigned)ABSDIFF(ida1[y1p][x1m], ida2[y2p][x2m]) + \
66 (unsigned)ABSDIFF(ida1[y1p][x1], ida2[y2p][x2]) + \
67 (unsigned)ABSDIFF(ida1[y1p][x1p], ida2[y2p][x2p]);
69 #define SAD5x5(x1, y1, x2, y2, ida1, ida2, re)\
70 unsigned x1m=x1-1, x1p=x1+1, y1m=y1-1, y1p=y1+1, x1m2=x1-2, x1p2=x2+2, y1m2=y2-2, y1p2=y2+2;\
71 unsigned x2m=x2-1, x2p=x2+1, y2m=y2-1, y2p=y2+1, x2m2=x1-2, x2p2=x2+2, y2m2=y2-2, y2p2=y2+2;\
72 re = (unsigned)ABSDIFF(ida1[y1m2][x1m2], ida2[y2m2][x2m2]) + \
73 (unsigned)ABSDIFF(ida1[y1m2][x1m], ida2[y2m2][x2m]) + \
74 (unsigned)ABSDIFF(ida1[y1m2][x1], ida2[y2m2][x2]) + \
75 (unsigned)ABSDIFF(ida1[y1m2][x1p], ida2[y2m2][x2p]) + \
76 (unsigned)ABSDIFF(ida1[y1m2][x1p2], ida2[y2m2][x2p2]) + \
77 (unsigned)ABSDIFF(ida1[y1m][x1m2], ida2[y2m][x2m2]) + \
78 (unsigned)ABSDIFF(ida1[y1m][x1m], ida2[y2m][x2m]) + \
79 (unsigned)ABSDIFF(ida1[y1m][x1], ida2[y2m][x2]) + \
80 (unsigned)ABSDIFF(ida1[y1m][x1p], ida2[y2m][x2p]) + \
81 (unsigned)ABSDIFF(ida1[y1m][x1p2], ida2[y2m][x2p2]) + \
82 (unsigned)ABSDIFF(ida1[y1][x1m2], ida2[y2][x2m2]) + \
83 (unsigned)ABSDIFF(ida1[y1][x1m], ida2[y2][x2m]) + \
84 (unsigned)ABSDIFF(ida1[y1][x1], ida2[y2][x2]) + \
85 (unsigned)ABSDIFF(ida1[y1][x1p], ida2[y2][x2p]) + \
86 (unsigned)ABSDIFF(ida1[y1][x1p2], ida2[y2][x2p2]) + \
87 (unsigned)ABSDIFF(ida1[y1p][x1m2], ida2[y2p][x2m2]) + \
88 (unsigned)ABSDIFF(ida1[y1p][x1m], ida2[y2p][x2m]) + \
89 (unsigned)ABSDIFF(ida1[y1p][x1], ida2[y2p][x2]) + \
90 (unsigned)ABSDIFF(ida1[y1p][x1p], ida2[y2p][x2p]) + \
91 (unsigned)ABSDIFF(ida1[y1p][x1p2], ida2[y2p][x2p2]) + \
92 (unsigned)ABSDIFF(ida1[y1p2][x1m2], ida2[y2p2][x2m2]) + \
93 (unsigned)ABSDIFF(ida1[y1p2][x1m], ida2[y2p2][x2m]) + \
94 (unsigned)ABSDIFF(ida1[y1p2][x1], ida2[y2p2][x2]) + \
95 (unsigned)ABSDIFF(ida1[y1p2][x1p], ida2[y2p2][x2p]) + \
96 (unsigned)ABSDIFF(ida1[y1p2][x1p2], ida2[y2p2][x2p2]);
98 #define NCC5x5(x1, y1, x2, y2, ida1, ida2, re)\
99 unsigned x1m=x1-1, x1p=x1+1, y1m=y1-1, y1p=y1+1, x1m2=x1-2, x1p2=x2+2, y1m2=y2-2, y1p2=y2+2;\
100 unsigned x2m=x2-1, x2p=x2+1, y2m=y2-1, y2p=y2+1, x2m2=x1-2, x2p2=x2+2, y2m2=y2-2, y2p2=y2+2;\
101 int im1, im2; unsigned long S11=0, S12=0, S22=0, N=0, S1=0, S2=0;\
102 im1=ida1[y1m2][x1m2]; im2=ida2[y2m2][x2m2]; N++; S1+=im1; S2+=im2; S11+=im1*im1; S12+=im1*im2; S22+=im2*im2; \
103 im1=ida1[y1m2][x1m]; im2=ida2[y2m2][x2m]; N++; S1+=im1; S2+=im2; S11+=im1*im1; S12+=im1*im2; S22+=im2*im2; \
104 im1=ida1[y1m2][x1]; im2=ida2[y2m2][x2]; N++; S1+=im1; S2+=im2; S11+=im1*im1; S12+=im1*im2; S22+=im2*im2; \
105 im1=ida1[y1m2][x1p]; im2=ida2[y2m2][x2p]; N++; S1+=im1; S2+=im2; S11+=im1*im1; S12+=im1*im2; S22+=im2*im2; \
106 im1=ida1[y1m2][x1p2]; im2=ida2[y2m2][x2p2]; N++; S1+=im1; S2+=im2; S11+=im1*im1; S12+=im1*im2; S22+=im2*im2; \
107 im1=ida1[y1m][x1m2]; im2=ida2[y2m][x2m2]; N++; S1+=im1; S2+=im2; S11+=im1*im1; S12+=im1*im2; S22+=im2*im2; \
108 im1=ida1[y1m][x1m]; im2=ida2[y2m][x2m]; N++; S1+=im1; S2+=im2; S11+=im1*im1; S12+=im1*im2; S22+=im2*im2; \
109 im1=ida1[y1m][x1]; im2=ida2[y2m][x2]; N++; S1+=im1; S2+=im2; S11+=im1*im1; S12+=im1*im2; S22+=im2*im2; \
110 im1=ida1[y1m][x1p]; im2=ida2[y2m][x2p]; N++; S1+=im1; S2+=im2; S11+=im1*im1; S12+=im1*im2; S22+=im2*im2; \
111 im1=ida1[y1m][x1p2]; im2=ida2[y2m][x2p2]; N++; S1+=im1; S2+=im2; S11+=im1*im1; S12+=im1*im2; S22+=im2*im2; \
112 im1=ida1[y1][x1m2]; im2=ida2[y2][x2m2]; N++; S1+=im1; S2+=im2; S11+=im1*im1; S12+=im1*im2; S22+=im2*im2; \
113 im1=ida1[y1][x1m]; im2=ida2[y2][x2m]; N++; S1+=im1; S2+=im2; S11+=im1*im1; S12+=im1*im2; S22+=im2*im2; \
114 im1=ida1[y1][x1]; im2=ida2[y2][x2]; N++; S1+=im1; S2+=im2; S11+=im1*im1; S12+=im1*im2; S22+=im2*im2; \
115 im1=ida1[y1][x1p]; im2=ida2[y2][x2p]; N++; S1+=im1; S2+=im2; S11+=im1*im1; S12+=im1*im2; S22+=im2*im2; \
116 im1=ida1[y1][x1p2]; im2=ida2[y2][x2p2]; N++; S1+=im1; S2+=im2; S11+=im1*im1; S12+=im1*im2; S22+=im2*im2; \
117 im1=ida1[y1p][x1m2]; im2=ida2[y2p][x2m2]; N++; S1+=im1; S2+=im2; S11+=im1*im1; S12+=im1*im2; S22+=im2*im2; \
118 im1=ida1[y1p][x1m]; im2=ida2[y2p][x2m]; N++; S1+=im1; S2+=im2; S11+=im1*im1; S12+=im1*im2; S22+=im2*im2; \
119 im1=ida1[y1p][x1]; im2=ida2[y2p][x2]; N++; S1+=im1; S2+=im2; S11+=im1*im1; S12+=im1*im2; S22+=im2*im2; \
120 im1=ida1[y1p][x1p]; im2=ida2[y2p][x2p]; N++; S1+=im1; S2+=im2; S11+=im1*im1; S12+=im1*im2; S22+=im2*im2; \
121 im1=ida1[y1p][x1p2]; im2=ida2[y2p][x2p2]; N++; S1+=im1; S2+=im2; S11+=im1*im1; S12+=im1*im2; S22+=im2*im2; \
122 im1=ida1[y1p2][x1m2]; im2=ida2[y2p2][x2m2]; N++; S1+=im1; S2+=im2; S11+=im1*im1; S12+=im1*im2; S22+=im2*im2; \
123 im1=ida1[y1p2][x1m]; im2=ida2[y2p2][x2m]; N++; S1+=im1; S2+=im2; S11+=im1*im1; S12+=im1*im2; S22+=im2*im2; \
124 im1=ida1[y1p2][x1]; im2=ida2[y2p2][x2]; N++; S1+=im1; S2+=im2; S11+=im1*im1; S12+=im1*im2; S22+=im2*im2; \
125 im1=ida1[y1p2][x1p]; im2=ida2[y2p2][x2p]; N++; S1+=im1; S2+=im2; S11+=im1*im1; S12+=im1*im2; S22+=im2*im2; \
126 im1=ida1[y1p2][x1p2]; im2=ida2[y2p2][x2p2]; N++; S1+=im1; S2+=im2; S11+=im1*im1; S12+=im1*im2; S22+=im2*im2; \
127 re =((double)N*(double)S12 - (double)S1*(double)S2)/ \
128 sqrt(((double)N*(double)S11 - (double)S1*(double)S1) * \
129 ((double)N*(double)S22 - (double)S2*(double)S2)); \
132 #define hamming_distance(a, b, re) \
134 for(int i = 0 ; i < 8; i++ ) { \
135 ab = (a & ( 1 << i )) ? 1 : 0; \
136 bb = (b & ( 1 << i )) ? 1 : 0; \
137 if( (ab && !bb) || (!ab && bb) ) { \
160 template<
class StorageType>
167 template<
class StorageType>
174 template<
class StorageType>
181 template<
class StorageType>
192 template<
class StorageType>
194 SSD(
const unsigned int p1[2],
const unsigned int p2[2],
195 const StorageType **ida1,
const StorageType **ida2,
196 const unsigned int halfwinsize,
double& result)
const;
203 template<
class StorageType>
205 SAD(
const unsigned int p1[2],
const unsigned int p2[2],
206 const StorageType **ida1,
const StorageType **ida2,
207 const unsigned int halfwinsize,
double& result)
const;
213 template<
class StorageType>
215 SAD(
const unsigned int p1[2],
const unsigned int p2[2],
216 const StorageType **ida1,
const StorageType **ida2,
217 const unsigned int halfwinsize,
const unsigned channel_count,
218 double& result)
const;
225 template<
class StorageType>
227 SADN(
const unsigned int p1[2],
const unsigned int p2[2],
228 const StorageType **ida1,
const StorageType **ida2,
229 const unsigned int halfwinsize,
double& result)
const;
238 template<
class StorageType>
240 NCC(
const unsigned int p1[2],
const unsigned int p2[2],
241 const StorageType **ida1,
const StorageType **ida2,
242 const unsigned int halfwinsize,
double& result)
const;
246 template<
class StorageType>
248 NCC(
const double p1[2],
const double p2[2],
const StorageType **ida1,
249 const StorageType **ida2,
const unsigned halfwinsize,
double &result);
257 template<
class StorageType>
259 NCC(
const unsigned p1[2],
const unsigned p2[2],
const StorageType **ida1,
260 const StorageType **roi1,
const StorageType **ida2,
261 const StorageType **roi2,
const unsigned hww,
const unsigned hwh,
262 double& result)
const;
266 template<
class StorageType>
268 ColorNCC(
const unsigned int p1[2],
const unsigned int p2[2],
269 const StorageType **ida1,
const StorageType **ida2,
270 const unsigned int halfwinsize,
double &result)
const;
275 template<
class StorageType>
277 ColorCCV(
const unsigned int p1[2],
const unsigned int p2[2],
278 const StorageType **ida1,
const StorageType **ida2,
279 const unsigned int halfwinsize,
double &result)
const;
283 template<
class StorageType>
285 CNCC(
const unsigned int p1[2],
const unsigned int p2[2],
286 const StorageType **ida1,
const StorageType **ida2,
287 const unsigned int halfwinsize,
double &result)
const;
310 template<
class StorageType>
312 NCCSearchOdd(
const unsigned int p1[2],
const unsigned int p2[2],
313 const StorageType **ida1,
const StorageType **ida2,
314 const unsigned int halfnccwinsize,
315 const unsigned int halfsearchwinsize,
unsigned int resultpoint[2],
316 const double mincorrelation,
double& result)
const;
321 template<
class StorageType>
323 NCCSearchEven(
const unsigned int p1[2],
const unsigned int p2[2],
324 const StorageType **ida1,
const StorageType **ida2,
325 const unsigned int halfnccwinsize,
326 const unsigned int halfsearchwinsize,
unsigned int resultpoint[2],
327 const double mincorrelation,
double& result)
const;
331 template<
class StorageType>
333 HammingDistance(
const unsigned int p1[2],
const unsigned int p2[2],
334 const StorageType **ida1,
const StorageType **ida2,
335 const unsigned int halfwinsize,
const unsigned int censussize,
336 double& result)
const;
337 template <
class StorageType>
339 SADSamplingInsensitive(
const unsigned int p1[2],
const unsigned int p2[2],
340 const StorageType **ida1,
const StorageType **ida2,
341 const unsigned int halfwinsize,
double& result)
const;
474 template<
class StorageType>
476 LineMatcherNCC(
const unsigned int p1[2],
const unsigned int start2[2],
477 const unsigned int end2[2],
const StorageType **ida1,
478 const StorageType **ida2,
const StorageType **grad1,
479 const StorageType **grad2,
const unsigned int halfwinsize,
480 const unsigned int epsilon,
const double gradientscale,
481 unsigned int result[2],
double& correlation)
const;
484 template<
class StorageType>
486 LineMatcherSAD(
const unsigned int p1[2],
const unsigned int start2[2],
487 const unsigned int end2[2],
const StorageType **ida1,
488 const StorageType **ida2,
const StorageType **grad1,
489 const StorageType **grad2,
const unsigned int halfwinsize,
490 const unsigned int epsilon,
const double gradientscale,
491 unsigned int result[2],
double& sad)
const;
494 template<
class StorageType>
496 LineMatcherSSD(
const unsigned int p1[2],
const unsigned int start2[2],
497 const unsigned int end2[2],
const StorageType **ida1,
498 const StorageType **ida2,
const StorageType **grad1,
499 const StorageType **grad2,
const unsigned int halfwinsize,
500 const unsigned int epsilon,
const double gradientscale,
501 unsigned int result[2],
double& ssd)
const;
511 template<
class StorageType>
513 ParabolaNCC(
const unsigned int p1[2],
const unsigned int p2[2],
514 const StorageType **ida1,
const StorageType **ida2,
515 const unsigned int halfwinsize, KLT_TYPE result[2])
const;
525 template<
class StorageType>
527 ParabolaNCC5(
const unsigned int p1[2],
const unsigned int p2[2],
528 const StorageType **ida1,
const StorageType **ida2,
529 const unsigned int halfwinsize, KLT_TYPE result[2])
const;
542 template<
class StorageType>
544 AD(
const unsigned int x1,
const unsigned int y1,
552 template<
class StorageType>
554 SamplingInsensitiveDissimilarity(
const unsigned int p1[2],
const unsigned int p2[2],
555 const StorageType **ida1,
const StorageType **ida2,
double &result)
const;
558 template<
class StorageType>
560 _Bilinear(
const StorageType **ida,
const KLT_TYPE x,
const KLT_TYPE y)
const;
563 _Bilinear(
const unsigned char **ida,
const KLT_TYPE x,
const KLT_TYPE y)
const;
570 template<
class StorageType>
572 _BilinearRegion(
const StorageType **ida,
const KLT_TYPE x,
576 _BilinearRegion(
const unsigned char **ida,
const KLT_TYPE x,
590 a = (x1 - 2.0 * x2 + x3);
592 return (a != 0.0) ? (KLT_TYPE) p / (2.0 * a) : (KLT_TYPE) 0.0;
598 const KLT_TYPE x4,
const KLT_TYPE x5)
const
608 return (res[0] != 0.0) ? (KLT_TYPE) res[1] / (2.0 * res[0])
625 #endif // __RegionMatcher_hh__
BIAS::Vector< double > Lapack_LLS_QR_linear_solve(const BIAS::Matrix< double > &A, const BIAS::Vector< double > &b, int &res)
linear least squares solves |Ax-b|=min res=0 on success, anything else rudimentary tested (woelk) ...
Matrix2x2< KLT_TYPE > _Ginv
class BIASImageBase_EXPORT Image
Matrix< KLT_TYPE > _gy2_5
The image template class for specific storage types.
Basic functions for CornerMatcher.
KLT_TYPE _ParabolaApprox(const KLT_TYPE x1, const KLT_TYPE x2, const KLT_TYPE x3) const
bilinear interpolation, also moved gradient image data from [0:255] to [-127, 128] before interpolati...
KLT_TYPE _ParabolaApprox(const KLT_TYPE x1, const KLT_TYPE x2, const KLT_TYPE x3, const KLT_TYPE x4, const KLT_TYPE x5) const