00001 #ifndef QD_IMGRANK_HPP
00002 #define QD_IMGRANK_HPP
00003
00004 #include <iostream>
00005 #include <fstream>
00006 #include <sstream>
00007 #include <string>
00008 #include <vector>
00009
00010 #include <math.h>
00011
00012 #include "kernel/jafarMacro.hpp"
00013 #include "jmath/jblas.hpp"
00014 #include "image/Image.hpp"
00015
00016
00017 namespace jafar {
00018
00019 namespace quasidense {
00020
00029 struct imgDataRank {
00030
00031 private :
00032
00034 image::Image *rankImage;
00035
00036 public :
00037
00038 unsigned int rowstep;
00039
00041 unsigned char *rankRawData;
00042
00044 boost::numeric::ublas::matrix<bool> vMask;
00045
00049 imgDataRank (jafar::image::Image &img , unsigned int rRank=2, unsigned int rExclu=2, double cmThreshold=0.01) :
00050 vMask(img.height(),img.width())
00051 {
00052 JFR_PRECOND( img.depth()==8, "quasidense::imgdata::imgdata : image depth must be equal to 8 ");
00053 JFR_PRECOND( rRank<=7, "quasidense::ingDataRank::imgDataRank : 7 is the maximal radius tolarated by rank Transform");
00054
00055
00056
00057 rankImage = img.rankTransform(rRank);
00058 rankRawData = rankImage->data();
00059
00060
00061 unsigned int nbcol = img.width();
00062 unsigned int nbrow = img.height();
00063 double vmax1, vmax2, cstnormal = 1.0/255.0;
00064
00065 jblas::mat diffv(nbrow,nbcol);
00066 jblas::mat diffh(nbrow,nbcol);
00067
00068
00069 rowstep = img.step();
00070
00071
00072
00073
00074
00075 vMask(0,0) = false;
00076 diffv(0,0) = 0.0;
00077 diffh(0,0) = 0.0;
00078
00079 for (unsigned int cptr=1; cptr<nbrow;cptr++)
00080 {
00081 vMask(cptr,0) = false;
00082 diffv(cptr,0) = cstnormal*fabs((double)rankRawData[cptr*rowstep]-(double)rankRawData[cptr*rowstep-rowstep]);
00083 diffh(cptr,0) = 0.0;
00084 }
00085
00086 for (unsigned int cptc=1; cptc<nbcol;cptc++)
00087 {
00088 vMask(0,cptc) = false;
00089 diffv(0,cptc) = 0.0;
00090 diffh(0,cptc) = cstnormal*fabs((double)rankRawData[cptc]-(double)rankRawData[cptc-1]);
00091 }
00092
00093 unsigned int pos;
00094 for (unsigned int cptr = 1; cptr<nbrow; ++cptr)
00095 {
00096 pos = cptr*rowstep;
00097 {
00098 for (unsigned int cptc = 1; cptc<nbcol; ++cptc)
00099 {
00100 vMask(cptr,cptc) = false;
00101 diffv(cptr,cptc) = cstnormal*fabs((double)rankRawData[pos+cptc]-(double)rankRawData[pos-rowstep+cptc]);
00102 diffh(cptr,cptc) = cstnormal*fabs((double)rankRawData[pos+cptc]-(double)rankRawData[pos+cptc-1]);
00103 }
00104 }
00105 }
00106
00107
00108
00109 for (unsigned int cptr=rExclu;cptr<(nbrow-rExclu);++cptr)
00110 for (unsigned int cptc=rExclu;cptc<(nbcol-rExclu);++cptc)
00111 {
00112 vmax1 = (diffv(cptr,cptc)<diffh(cptr,cptc))?diffh(cptr,cptc):diffv(cptr,cptc);
00113 vmax2 = (diffv(cptr+1,cptc)<diffh(cptr,cptc+1))?diffh(cptr,cptc+1):diffv(cptr+1,cptc);
00114 if ((vmax1>=cmThreshold)||(vmax2>=cmThreshold))
00115 vMask(cptr,cptc) = true;
00116 }
00117
00118 };
00119
00120 };
00121
00122
00128 class imgPairRank {
00129
00130 imgDataRank img1;
00131
00132 imgDataRank img2;
00133
00134 unsigned int rRank;
00135
00136 unsigned int winwidth;
00137
00138 public :
00142 imgPairRank (jafar::image::Image &img1_, jafar::image::Image &img2_, unsigned int rRank_=2,
00143 unsigned int rExclu_=2, double cmThreshold_=0.01) :
00144 img1(img1_, rRank_, rExclu_, cmThreshold_),
00145 img2(img2_, rRank_, rExclu_, cmThreshold_),
00146 rRank(rRank_),
00147 winwidth(2*rRank_+1)
00148 { };
00149
00153 bool isPointValidinIma1 (int u, int v);
00154 bool isPointValidinIma2 (int u, int v);
00155
00159 bool isMatchValid (int u1, int v1, int u2, int v2);
00160 bool isMatchValid (int u1, int v1, int u2, int v2, unsigned int radius);
00161
00165 double matchEval (int u1, int v1, int u2, int v2);
00166 double matchEval (int u1, int v1, int u2, int v2, unsigned int radius);
00167
00171 void confirmedMatch (int u1, int v1, int u2, int v2)
00172 {
00173 img1.vMask(v1,u1) = false;
00174 img2.vMask(v2,u2) = false;
00175 };
00176
00177 };
00178
00179 }
00180
00181 }
00182
00183 #endif