Пример #1
0
void LocalFeatureExtractor::extractPatches(ImageFeature &img, const ::std::vector<FeatureExtractionPosition> &positions, LocalFeatures &lf) {
  if(settings_.padding>0) {
    img=zeropad(img,settings_.padding, settings_.padding);
  }

  lf.winsize_=settings_.winsize;
  lf.padding_=settings_.padding;
  lf.numberOfFeatures_=positions.size();
  lf.zsize_=img.zsize();

  int windiameter=2*settings_.winsize+1;

  lf.dim_=windiameter*windiameter*img.zsize();
  lf.imageSizeX_=img.xsize();
  lf.imageSizeY_=img.ysize();
  lf.filename_=img.filename();

  int savesize=settings_.winsize*2+1;

  lf.positions_=positions;
  lf.data_.resize(positions.size());

  for(uint i=0;i<positions.size();++i) {
    const FeatureExtractionPosition &pos=positions[i];

    ImageFeature p=getPatch(img,pos.x,pos.y,pos.s);
    if(uint(pos.s)!=settings_.winsize) {
      p=scale(p,savesize,savesize);
    }
    lf.data_[i]=toVector(p);
  }
}
Пример #2
0
void LocalFeatureExtractor::extractHisto(ImageFeature &img, const ::std::vector<FeatureExtractionPosition> &positions, LocalFeatures &lf) {

	uint n_colors;
	if(settings_.forceGray == true)
		n_colors = 1;
	else
		n_colors = 3;

	// Extract patches
	if(settings_.padding>0) {
		img=zeropad(img,settings_.padding, settings_.padding);
	}

	lf.winsize_=settings_.winsize;
	lf.padding_=settings_.padding;
	lf.numberOfFeatures_=positions.size();
	lf.zsize_=img.zsize();

	int windiameter=2*settings_.winsize+1;

	if(n_colors == 1)
		lf.dim_=settings_.histosteps;
	else if(n_colors == 3)
		lf.dim_=settings_.histosteps*settings_.histosteps*settings_.histosteps;
	lf.imageSizeX_=img.xsize();
	lf.imageSizeY_=img.ysize();
	lf.filename_=img.filename();

	int savesize=settings_.winsize*2+1;

	lf.positions_=positions;
	lf.data_.resize(positions.size());

	uint steps=settings_.histosteps;

	for(uint i=0;i<positions.size();++i) {
		const FeatureExtractionPosition &pos=positions[i];

		ImageFeature p=getPatch(img,pos.x,pos.y,pos.s);
		if(uint(pos.s)!=settings_.winsize) {
			p=scale(p,savesize,savesize);
		}

		// Histogramize patch
		HistogramFeature histo(vector<uint>(n_colors,steps));
		histo.min()=vector<double>(n_colors,0.0);
		histo.max()=vector<double>(n_colors,1.0);
		histo.initStepsize();

		vector<double> tofeed(n_colors);

		for(uint x=0;x<p.xsize();++x) {
			for(uint y=0;y<p.ysize();++y) {
				for(uint c=0;c<n_colors;++c) {
					tofeed[c]=p(x,y,c);
				}
				histo.feed(tofeed);
			}
		}
		lf.data_[i]=histo.data();
	}
}