コード例 #1
0
void TrueClusterHistogram::hbof(const patch &descriptor,
				  Descriptor &histogram,
				  bool histogram_first){
  typedef patch_collection::const_iterator pcit;
  typedef Descriptor::iterator dcit;

  // find closest cluster
  size_t classification = 0;
  float min_distance = 0;
  bool first = true;
  for(pcit i = centers.begin(); i != centers.end(); ++i){
    float current_distance = (*i).distance(descriptor);
    if(first == true || current_distance < min_distance){
      min_distance = current_distance;
      classification = i - centers.begin();
    }
    first = false; 
  }

  // initialize histogram if applicable
  if(histogram_first)
    for(dcit i = histogram.begin(); i != histogram.end(); ++i)
      *i  = 0;
  // increment closest center in the histogram
  histogram[classification] += 1;
}
コード例 #2
0
void TrueClusterHistogram::min(const patch &descriptor,
				  Descriptor &histogram,
				  bool first){
	Descriptor::iterator h = histogram.begin();
	patch_collection::iterator c = centers.begin();
	while(h != histogram.end() && c != centers.end()){
	  float dist = descriptor.distance(*c);
	  if(first || dist < *h)
	    *h = dist;
	  h++;
	  c++;
	}
}