www.pudn.com > firev0.01.rar > crosstd.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 __crosstangentdistdistance_hpp
#define __crosstangentdistdistance_hpp
#include "td.hpp"
#include "image.hpp"
#include "imagefeature.hpp"
#include "rgbimage.hpp"
#include "rgbimagefeature.hpp"
#include "basehisto.hpp"
#include "basefeature.hpp"
#include "diag.hpp"
#include 
#include 
#include 

class CrossTangentDistance : public BaseDist {
public:
  CrossTangentDistance(int d,double bg, int *choice) {
    d_=d;
    background_=bg;
    choice_=(int*)malloc(9*sizeof(int));

    DBG(DBG_MESSAGE) << "d="<< d_ << " bg=" << background_ << " choice=";

    for(int i=0;i<9;++i) {
      choice_[i]=choice[i];
      BLINK(DBG_MESSAGE) << choice_[i] ;
    }
    BLINK(DBG_MESSAGE) << endl;

  }
  
  virtual ~CrossTangentDistance() {
    free(choice_);
  }
  
  virtual double dist(const BaseFeature *b, const BaseFeature *a) const {
    const ImageFeature *gfa=dynamic_cast(a);
    const ImageFeature *gfb=dynamic_cast(b);
    
    if(!gfa || !gfb) {
      
      ERR << "Only Gray Image Features can be used!" << ::std::endl;
      exit(20);
    } else {
      BaseImage ima=gfa->img();
      BaseImage imb=gfb->img();
      
      return crosstangentdist_grey(ima, imb);
    }
  };

 
  virtual double dist(const BaseFeature*, const vector&) const {
    ERR << "Not defined" << endl;
    exit(20);
    return 0.0;
  };
  
  virtual std::string name() {
    return "crosstangentdistdist";
  }
  
private:
  
  double crosstangentdist_color(const RGBImage & ima, const RGBImage &imb) const {
    ERR << "Not yet implemented!" << endl;
    exit(20);
  }
  
  
  double crosstangentdist_grey(const BaseImage &inA, const BaseImage &inB) const {

    if(inA.xDim()!=inA.yDim() || inB.xDim()!=inB.yDim()) {
      ERR << "only square images allowed" << endl;
      exit(20);
    }
    
    if(inA.xDim()!=inB.xDim() || inA.yDim() != inB.yDim()) {
      ERR << "images have to be of equal size" << endl;
      exit(20);
    }

    int dim=inA.xDim();


    int aX,aY;
    double dist=numeric_limits::max();
    double minDist=numeric_limits::max();
    unsigned int size=dim*dim;
    double *imageOne, *imageTwo;
    imageOne=(double*)malloc(size*sizeof(double));
    imageTwo=(double*)malloc(size*sizeof(double));
    for(unsigned int i=0;i test(dim,dim);
    
    for(int n=-d_;n<=d_;++n) {  // maximising over m and n
      for(int m=-d_;m<=d_;++m) {

        //create shifted image
        int pos=0;
        int size=0;
        for(int y=0;y=0&&aX=0&&aYdist) {
          minDist=dist;
        }
      }
    }
    free(imageOne);
    free(imageTwo);

    return minDist;
  }
  
  int d_;
  double background_;
  int *choice_;

  
};
#endif