00001
00002
00003 #ifndef SAS_CONSPICUITY_HPP
00004 #define SAS_CONSPICUITY_HPP
00005
00006 #include <vector>
00007 #include "kernel/keyValueFile.hpp"
00008 #include "image/Image.hpp"
00009 #include "image/filter.hpp"
00010 #include "image/pyramid.hpp"
00011
00012 namespace jafar {
00013 namespace sas {
00014
00015 typedef enum MaxNormType {
00016 STD=0,
00017 NOV=1,
00018 FANCY=2,
00019 FFANCY=3
00020 };
00021
00022 class CParams : public jafar::kernel::KeyValueFileLoad {
00023 public:
00025 int sml;
00026 int lmin;
00027 int lmax;
00028 int dmin;
00029 int dmax;
00030 int maxlevels;
00031 double nmin;
00032 double nmax;
00033 int niter;
00034 MaxNormType ntype;
00035
00036 CParams(int sml_=3,int lmin_=2,int lmax_=4,int dmin_=3, int dmax_=4, double nmin_=0.0, double nmax_=10.0, int niter_=3, MaxNormType ntype_=FANCY) :
00037 sml(sml_),lmin(lmin_), lmax(lmax_),dmin(dmin_), dmax(dmax_),maxlevels(lmax_+dmax_+1),
00038 nmin(nmin_), nmax(nmax_), niter(niter_), ntype(ntype_) {};
00039 protected:
00043 void loadKeyValueFile(jafar::kernel::KeyValueFile const& keyValueFile);
00044 };
00045
00051 class Conspicuity : public jafar::image::Pyramid {
00052 public:
00054 CParams params;
00055
00057 Conspicuity(CParams const & params_=CParams()) : jafar::image::Pyramid(params_.maxlevels), params(params_) {};
00059 virtual ~Conspicuity() {};
00060
00061 void process(jafar::image::Image const & img);
00062
00063 jafar::image::Image const & getMap(std::string const & label) const {
00064 return fmaps.find(label)->second;
00065 };
00066
00067 std::pair<std::string,float> getStrongestFMap(int wx, int wy) const {
00068 std::map<std::string,jafar::image::Image>::const_iterator it = fmaps.begin();
00069 std::pair<std::string,float> res("",-1.);
00070 for(; it != fmaps.end(); it++) {
00071 if ( it->first != "cmap") {
00072 float val = it->second.getPixelValue<float>(wx,wy);
00073 if ( val > res.second ) {
00074 res.first = it->first;
00075 res.second = val;
00076 }
00077 }
00078 }
00079 return res;
00080 };
00081
00084 static void maxNormalize(jafar::image::Image& img, double mi, double ma, int niter, MaxNormType ntype);
00085
00086
00089 static std::string getLabel(int c, int s) {
00090 std::stringstream st;
00091 st << "fmap(" << c << "," << s << ")";
00092 return st.str();
00093 }
00094
00095 protected:
00096
00097 std::map<std::string,jafar::image::Image> fmaps;
00098
00102 void centerSurround(jafar::image::Image const & center,
00103 jafar::image::Image const & surround,
00104 jafar::image::Image & result,
00105 bool absol=false);
00106
00110 void centerSurroundR(jafar::image::Image const & center,
00111 jafar::image::Image const & surround,
00112 jafar::image::Image & result,
00113 bool absol=false);
00114
00115 };
00116
00117
00122 class OrientedConspicuity : public Conspicuity {
00123 public:
00125 OrientedConspicuity(float theta_, CParams const & params_=CParams(), float period=7., int size=-1) :
00126 Conspicuity(params_) {
00127 gabor0 = jafar::image::filter::gaborkernel(period*0.312,period*0.312,period,0.,theta_,size);
00128 gabor90 = jafar::image::filter::gaborkernel(period*0.312,period*0.312,period,90.,theta_,size);
00129 };
00130
00132 virtual ~OrientedConspicuity() {};
00133
00134 virtual void build(jafar::image::Image const & img, int l=0) {
00135 jafar::image::Pyramid::build(img,l);
00136 int anchorw = gabor0.cols()/2;
00137 int anchorh = gabor0.rows()/2;
00138 for(int i=0; i<size(); i++) {
00139 jafar::image::Image tmp = p_pyr[i].clone();
00140 cvFilter2D(p_pyr[i],p_pyr[i],gabor0,cvPoint(anchorw,anchorh));
00141 cvFilter2D(tmp,tmp,gabor90,cvPoint(anchorw,anchorh));
00142 cvAdd(p_pyr[i],tmp,p_pyr[i]);
00143 }
00144 };
00145
00146 private:
00147 CvMatrix gabor0;
00148 CvMatrix gabor90;
00149 };
00150
00151
00152 }
00153 }
00154
00155 #endif // SAS_CONSPICUITY_HPP