www.pudn.com > firev0.01.rar > globaltexturefeature.cpp


/*
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
*/
#include 
#include 
#include 
#include "gzstream.hpp"
#include "diag.hpp"
#include "image.hpp"
#include "rgbimage.hpp"
#include "colorpixel.hpp"
#include "globaltexturefeature.hpp"

using namespace std;
using namespace img;
using namespace diag;

GlobalTextureFeature::GlobalTextureFeature(){
  data_=vector(43);
}

const double GlobalTextureFeature::operator[](const unsigned int i) const{
  return data_[i];
}

const unsigned int GlobalTextureFeature::size() const{
  return data_.size();
}

void GlobalTextureFeature::calculate(const ::img::RGBImage &image){
  BaseImage img(image.yDim(),image.xDim());
  
  for(unsigned int y=0;ycalculate(img);
}


void GlobalTextureFeature::calculate(const ::img::BaseImage &image){
  vector mean;
  vector contrast;
  vector angular_second_moment;
  vector entropy;

#ifdef __HAVE_GLOBALTEXTUREFEAT_CALCULATION
  this->calc_fractal_dim(image,data_[0]);
  this->calc_histogramm(image,data_[1],data_[2]);
  this->Circ_Moran(image,
                   data_[3],data_[4],
                   data_[5],data_[6],
                   data_[7],data_[8],
                   data_[9],data_[10]);

  this->sgld_statistics(image,mean,contrast, angular_second_moment, entropy);
#endif

  
  int cnt=11;
  for(int i=0;i<8;++i) {
    data_[cnt]=mean[i];
    data_[cnt+8]=contrast[i];
    data_[cnt+16]=angular_second_moment[i];
    data_[cnt+24]=entropy[i];
    ++cnt;
  }
}

void GlobalTextureFeature::save(const ::std::string filename) const {
  ofstream ofs(filename.c_str());
  if(!ofs) {
    ERR << "Unable to open '" << filename << "' to write GlobalTextureFeature" << endl;
  } else {
    ofs << "# GlobalTextureFeature using slightly modified sourcecode from Boris Terhorst" << endl
        << "dim " << data_.size() << endl
        << "data" ;
    for (unsigned int i=0;i> keyword;
      if(!ifs.eof()) {
        if(keyword=="#") {
          char devnull[1024];
          ifs.getline(devnull,1024);
        } else if(keyword=="dim") {
          ifs >> dim;
          data_=vector(dim);
        } else if(keyword=="data") {
          for(int i=0;i> data_[i];
          }
        } else {
          DBG(DBG_MESSAGE) << "Unknown keyword '" << keyword << "'. " << endl;
        }
      }
    }
    ifs.close();
  }
}

#ifdef __HAVE_GLOBALTEXTUREFEAT_CALCULATION
#include "globaltexturefeaturecalculation.hpp"
#endif