00001 #ifndef QD_MATCHES_HPP
00002 #define QD_MATCHES_HPP
00003
00004 #include <iostream>
00005 #include <fstream>
00006 #include <string>
00007 #include <vector>
00008
00009 #include <math.h>
00010
00011 #include "kernel/jafarMacro.hpp"
00012 #include "jmath/jblas.hpp"
00013 #include "image/Image.hpp"
00014
00015
00016 namespace jafar {
00017
00018 namespace quasidense {
00019
00020 struct pixel {
00021
00022 int u;
00023 int v;
00024
00025 pixel () :
00026 u(0),
00027 v(0)
00028 {};
00029
00030 pixel ( int u_, int v_):
00031 u(u_),
00032 v(v_)
00033 { };
00034
00035 pixel ( int *tab) :
00036 u(tab[0]),
00037 v(tab[1])
00038 {};
00039
00040 pixel (const pixel &p)
00041 {
00042 u = p.u;
00043 v = p.v;
00044 };
00045
00046 double normL1 ()
00047 {
00048 double du = (double)u, dv = (double)v;
00049 return(fabs(du)+fabs(dv));
00050 };
00051
00052 double normL2 ()
00053 {
00054 double du = (double)u, dv = (double)v;
00055 return(sqrt(du*du+dv*dv));
00056 };
00057
00058 double normInf ()
00059 {
00060 return(u>v?u:v);
00061 }
00062
00063 pixel &operator+=(const pixel &pix)
00064 {
00065 u += pix.u;
00066 v += pix.v;
00067 return *this;
00068 }
00069
00070 pixel &operator-=(const pixel &pix)
00071 {
00072 u -= pix.u;
00073 v -= pix.v;
00074 return *this;
00075 }
00076
00077 pixel &operator=(const pixel &pix)
00078 {
00079 if (&pix!=this)
00080 {
00081 this->u = pix.u;
00082 this->v = pix.v;
00083 }
00084 return *this;
00085 }
00086
00087
00088 };
00089
00090 struct pixelmatch {
00091
00092 pixel pix1;
00093
00094 pixel pix2;
00095
00096 double znccScore;
00097
00098 pixelmatch( int u1, int v1, int u2, int v2, double score=0.0) :
00099 pix1(u1,v1),
00100 pix2(u2,v2),
00101 znccScore(score)
00102 { };
00103
00104 pixelmatch(pixel pix1_, pixel pix2_, double score=0.0) :
00105 pix1(pix1_),
00106 pix2(pix2_),
00107 znccScore(score)
00108 { };
00109
00110 double disparity ()
00111 {
00112 pixel ptmp(pix1.u-pix2.u,pix1.v-pix2.v);
00113 return ptmp.normL2();
00114 };
00115
00116 };
00117
00118 std::ostream& operator <<(std::ostream& s, jafar::quasidense::pixelmatch const& pixmat);
00119
00120
00121 struct greaterSimilScore
00122 {
00123 bool operator()(const pixelmatch* match1, const pixelmatch* match2) const
00124 {
00125 if (match1->znccScore >= match2->znccScore)
00126 return true;
00127 return false;
00128 }
00129 };
00130
00131 }
00132
00133 }
00134
00135 #endif