www.pudn.com > firev0.01.rar > hsvxxyxxy.hpp


/*
This file is part of the FIRE -- Flexible Image Retrieval System

FIRE is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

FIRE is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with FIRE; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/
#ifndef __hsvxxyxxy_hpp
#define __hsvxxyxxy_hpp

#include "featurefunction.hpp"
#include 
#include 


class HSVXxyXxy : public FeatureFunction {
public:
  HSVXxyXxy(int x1, int y1, int x2, int y2) {
    x1_=x1;
    y1_=y1;
    x2_=x2;
    y2_=y2;
  }

  HSVXxyXxy(::std::string featureFunctionName) {
    int pos;
    string nrstring="";
    int X1,Y1,X2,Y2;
    
    pos=featureFunctionName.find("X1=");
    for(int i=pos+3;featureFunctionName[i] >= '0' && featureFunctionName[i]<='9';++i) {
      nrstring+=featureFunctionName[i];
    }
    nrstring+=" ";
    
    pos=featureFunctionName.find("Y1=");
    for(int i=pos+3;featureFunctionName[i] >= '0' && featureFunctionName[i]<='9';++i) {
      nrstring+=featureFunctionName[i];
    }
    nrstring+=" ";

    pos=featureFunctionName.find("X2=");
    for(int i=pos+3;featureFunctionName[i] >= '0' && featureFunctionName[i]<='9';++i) {
      nrstring+=featureFunctionName[i];
    }
    nrstring+=" ";

    pos=featureFunctionName.find("Y2=");
    for(int i=pos+3;featureFunctionName[i] >= '0' && featureFunctionName[i]<='9';++i) {
      nrstring+=featureFunctionName[i];
    }
    nrstring+=" ";
    
    istringstream istr(nrstring);
    istr >> X1 >> Y1 >> X2 >>  Y2;
    
    DBG(DBG_MESSAGE) << X1 << " " << Y1 << " " << X2 << " " << Y2 << endl;
    x1_=X1;
    y1_=Y1;
    x2_=X2;
    y2_=Y2;
    
  }
  


  virtual double max() const {
    return 255.0;
  }

  virtual double calculate(const ::img::InterpolBaseImage& image,const int t0, const int t1,const int r,const int R, const double s=1.0) const {
    double phi=2*M_PI*r/R;
    
    double pos1=s*x1_*sin(phi)+s*y1_*sin(phi)+t0;
    double pos2=s*(-x1_)*sin(phi)+s*y1_*cos(phi)+t1;
    double pos3=s*x2_*sin(phi)+s*y2_*sin(phi)+t0;
    double pos4=s*(-x2_)*sin(phi)+s*y2_*cos(phi)+t1;
    
    return sqrt(image(pos1,pos2)*image(pos3,pos4));
  }

  
  virtual ::img::ColorPixel calculate(const ::img::InterpolRGBImage& image,const int t0, const int t1,const int r,const int R, const double s=1.0) const {
    ::img::ColorPixel result=0;

    double phi=2*M_PI*r/R;
    double pos1=s*x1_*sin(phi)   +s*y1_*sin(phi)+t0;
    double pos2=s*(-x1_)*sin(phi)+s*y1_*cos(phi)+t1;
    double pos3=s*x2_*sin(phi)   +s*y2_*sin(phi)+t0;
    double pos4=s*(-x2_)*sin(phi)+s*y2_*cos(phi)+t1;
    
    ::img::ColorPixel hsv1=image(pos1,pos2).hsvPixel();
    ::img::ColorPixel hsv2=image(pos3,pos4).hsvPixel();



    hsv1[1]*=255.0;
    hsv2[1]*=255.0;
    
    hsv1[0]*=255.0/360.0;
    hsv2[0]*=255.0/360.0;
    //    cout << hsv1 << " " << hsv2 << endl;

    for(int i=0;i<3;++i) {
      result[i]=sqrt(hsv1[i]*hsv2[i]);
    }
    
    return result;
  }
  
private:
  int x1_, y1_, x2_, y2_;
  
};
#endif