www.pudn.com > firev0.01.rar > crosscorrelation.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 __crosscorrelationdistance_hpp
#define __crosscorrelationdistance_hpp
#include "basehisto.hpp"
#include "basefeature.hpp"
#include "diag.hpp"
#include 
#include 

class CrossCorrelationDistance : public BaseDist {
public:
  CrossCorrelationDistance(int d) {
    d_=d;
    DBG(DBG_MESSAGE) << "d="<< d_ << ::std::endl;
  }
  
  virtual ~CrossCorrelationDistance() {
  }

  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 crosscorrelation_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 "crosscorrelationdist";
  }
  
private:
  
  double crosscorrelation_color(const RGBImage & ima, const RGBImage &imb) const {
    ERR << "Not yet implemented!" << endl;
    exit(20);
  }
  
  
  double crosscorrelation_grey(const BaseImage &inA, const BaseImage &inB) const {
    double maxCorel=0.0;

    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 avgA=0.0, avgB=0.0;
    
    //get image averages
    for(int y=0;y=0&&aX=0&&aY