Ejemplo n.º 1
0
int
font_style_info_diff (const FontStyleInfo *actual, const FontStyleInfo *desired)
{
#if 0
	int weight = abs (normalize_weight (actual->weight) - normalize_weight (desired->weight));
	
	if (actual->style == desired->style)
		return weight;
	
	if (actual->style == FontStylesNormal) {
		// we can emulate italic/oblique, but we would still prefer the real
		// italic font if we can find it so apply a slight penalty
		return 1000 + weight;
	}
	
	// ouch, apply a huge penalty
	return 1000000 + weight;
#else
	int weight = abs (normalize_weight (actual->weight) - normalize_weight (desired->weight));
	int width = abs (actual->stretch - desired->stretch);
	int slant = abs (actual->style - desired->style);
	
	// weight needs ~12 bits, width needs ~4 bits, and slant needs ~2 bits
	
	// width has the highest priority, followed by weight and then slant
	return ((width & 0x000f) << 14) | ((weight & 0x0fff) << 2) | (slant & 0x0003);
#endif
}
Ejemplo n.º 2
0
Archivo: kvld.cpp Proyecto: mdqyy/KVLD
VLD::VLD(const ImageScale& series, T const& P1, T const& P2) : contrast(0.0) {
	//============== initializing============//
	principleAngle.fill(0);
	descriptor.fill(0);
	weight.fill(0);

	begin_point[0]=P1.x;
	begin_point[1]=P1.y;
	end_point[0]=P2.x;
	end_point[1]=P2.y;

	float dy= float(end_point[1]- begin_point[1]), dx= float(end_point[0]- begin_point[0]);
	  distance=sqrt(dy*dy+dx*dx);

	if (distance==0)
		std::cerr<<"Two SIFT points have the same coordinate"<<std::endl;

	float radius=std::max(distance/float(dimension+1), 2.0f);//at least 2

	double mainAngle= get_orientation();//absolute angle

	int image_index=series.getIndex(radius);

	const Image<float> & ang = series.angles[image_index];
	const Image<float> & m   = series.magnitudes[image_index];
	double ratio=series.ratios[image_index];
  
 // std::cout<<std::endl<<"index of image "<<radius<<" "<<image_index<<" "<<ratio<<std::endl;
	
  int w=m.Width() ,h=m.Height();
	float r=float(radius/ratio);//series.radius_size;
	float sigma2=r*r;
	//======Computing the descriptors=====//

	for (int i=0;i<dimension; i++){
		double statistic[binNum];
    std::fill_n(statistic, binNum, 0.0);

		float xi= float(begin_point[0]+ float(i+1)/(dimension+1)*(dx));
		float yi= float(begin_point[1]+ float(i+1)/(dimension+1)*(dy));
		yi/=float(ratio);
		xi/=float(ratio);
		
    for (int y=int(yi-r);y<=int(yi+r+0.5);y++){
			for (int x=int(xi-r);x<=int(xi+r+0.5);x++){
				float d=point_distance(xi,yi,float(x),float(y));
				if (d<=r && inside(w,h,x,y,1)){
					//================angle and magnitude==========================//
					double angle;
					if (ang(y,x)>=0)
						angle=ang(y,x)-mainAngle;//relative angle
					else angle=0.0;

					//cout<<angle<<endl;
					while (angle<0)
						angle +=2*PI;
					while (angle>=2*PI)
						angle -=2*PI;

					//===============principle angle==============================//
					int index=int(angle*binNum/(2*PI)+0.5);

					double Gweight=exp(-d*d/4.5/sigma2)*(m(y,x));
          // std::cout<<"in number "<<image_index<<" "<<x<<" "<<y<<" "<<m(y,x)<<std::endl;
					if (index<binNum)
						statistic[index]+=Gweight;
					else // possible since the 0.5
						statistic[0]+=Gweight;

					//==============the descriptor===============================//
					int index2=int(angle*subdirection/(2*PI)+0.5);
					assert(index2>=0 && index2<=subdirection);

					if (index2<subdirection)
						descriptor[subdirection*i+index2]+=Gweight;
					else descriptor[subdirection*i]+=Gweight;// possible since the 0.5
				}
			}
		}
		//=====================find the biggest angle of ith SIFT==================//
		int index,second_index;
		max(statistic,weight[i],binNum,index,second_index);
		principleAngle[i]=index;
	}

  normalize_weight(descriptor);
 
  contrast= std::accumulate(weight.begin(), weight.end(), 0.0);
	contrast/=distance/ratio;
	normalize_weight(weight);
}