"OpenCV" sift principle and source code analysis: direction Assignment

Source: Internet
Author: User

"Sift principle and Source Analysis" series Article index:http://www.cnblogs.com/tianyalu/p/5467813.html

From the previous article " key point search and positioning ", we have found the key point. In order to realize the image rotation invariance, it is necessary to assign the characteristic point direction according to the detected key point local image structure. That is, the alcorientationhist () statement that is seen in the Findscalespaceextrema () function:

// Calculate gradient Histogram float OMax = calcorientationhist (gauss_pyr[o* (noctavelayers+3) + layer], point                                                (C1, R1),                                                 * scl_octv),                                                * SCL_OCTV,                                                hist, n);
We use the gradient histogram method of image to find the stable direction of the local structure of key points. Gradient direction and amplitude values

In the previous article, we also found the scale value σ of the feature points after pinpointing the key points, and obtained the Gaussian image closest to this scale value according to this scale value:

Using the finite difference, the amplitude and amplitude of the image gradient in the area with the 3x1.5σ as a radius are calculated with the key points, and the formula is as follows:

Gradient histogram

After completing the Gaussian image gradient calculation in the key neighborhood, the histogram is used to statistic the gradient direction and amplitude of the pixels in the neighborhood.

The basic knowledge of histograms can be seen in the histogram of digital images , which can be regarded as the probability representation of discrete points. The core of this direction histogram is to make a contribution to the key point direction generated by the pixel point of the image in a certain region.

The gradient direction histogram is the gradient direction angle, the longitudinal axis is the tonsure direction angle corresponding gradient amplitude increment value. The gradient direction histogram divides the range of 0°~360° into 36 bars, and each 10 ° is a column. is to obtain the gradient from the Gaussian image, and then get the example of the gradient direction histogram by the gradient.

When the histogram is computed, each sample point added to the histogram is weighted with a circular Gaussian function function, i.e. Gaussian smoothing . This is mainly because the SIFT algorithm only considers the scale and rotation not deformed, and does not consider affine invariance. By Gaussian smoothing, the gradient amplitude near the key points can be weighted, which partially compensate for the instability of the characteristic points which are not considered to be caused by affine deformation.

Usually the discrete gradient histogram is interpolated to fit the interpolation, in order to obtain a more accurate direction angle value. (This is the same idea of interpolation in key point search and positioning ).

Key point Direction

The histogram peak represents the main direction of the image gradient in the neighborhood of the key point, that is, the main direction of the key point . In the gradient direction histogram, when there is another peak equivalent to 80% energy of the main peak, this direction is considered to be the secondary direction of the key point . So a key point may detect multiple directions, which can enhance the robustness of the match. Lowe's paper points out that there are about 15% key points with multiple orientations, but these points are critical to the stability of the match.

After acquiring the main direction of the image key point, there are three information (x,y,σ,θ) for each key point: position, scale, direction. Thus we can determine a SIFT feature area. Typically use a circle with arrows or use arrows directly to represent the three values of the SIFT area: The center represents the feature point position, the radius represents the key point scale (r=2.5σ), and the arrow represents the main direction. Keys that have multiple orientations can be copied into multiple copies, and the direction values are assigned to the copied key points, respectively. Such as:

Source
//computes a gradient orientation histogram at a specified pixel//Calculate gradient direction histogram for a specific pointStatic floatCalcorientationhist (Constmat& img, point PT,intradius,floatSigmafloat* Hist,intN) {//Len:2r+1 is the number of round (square) pixels with a radius of R    intI, J, k, Len = (radius*2+1) * (radius*2+1); floatExpf_scale =-1. f/(2. f * Sigma *Sigma); Autobuffer<float> buf (len*4+ n+4); float*x = buf, *y = x + len, *mag = x, *ori = Y + len, *w = Ori +Len; float* Temphist = W + len +2;  for(i =0; I < n; i++) Temphist[i]=0. F; //pixel range of image gradient histogram statistics     for(i =-radius, k =0; I <= radius; i++ )      {          inty = Pt.y +i; if(Y <=0|| Y >= img.rows-1 )              Continue;  for(j =-radius; J <= Radius; j + + )          {              intx = Pt.x +J; if(x <=0|| X >= Img.cols-1 )                  Continue; floatDX = (float) (img.at< Short> (Y, x+1)-img.at< Short> (y, X1)); floatDY = (float) (img.at< Short> (y1, x)-img.at< Short> (y+1, x)); X[K]= DX; Y[k] = dy; W[k] = (i*i + j*j) *Expf_scale; K++; }} Len=K; //compute gradient values, orientations and the weights over the pixel neighborhoodexp (W, W, Len); FastAtan2 (Y, X, Ori, Len,true);             Magnitude (X, Y, Mag, Len); //calculate histogram for each bin     for(k =0; K < Len; k++ )      {          intBin = Cvround ((n/ the. f) *Ori[k]); if(Bin >=N) Bin-=N; if(Bin <0) Bin+=N; Temphist[bin]+ = w[k]*Mag[k]; }        //Smooth the Histogram//Gaussian Smoothingtemphist[-1] = temphist[n-1]; temphist[-2] = temphist[n-2]; Temphist[n]= temphist[0]; Temphist[n+1] = temphist[1];  for(i =0; I < n; i++) {Hist[i]= (temphist[i-2] + temphist[i+2])*(1. f/ -. f) +(Temphist[i-1] + temphist[i+1])*(4. f/ -. f) +Temphist[i]*(6. f/ -. f); }            //get the main direction    floatMaxval = hist[0];  for(i =1; I < n; i++) Maxval=Std::max (Maxval, hist[i]); returnMaxval; }  

This step is relatively simple ~ See theSift Principle and source code analysis .

This article transferred from: http://blog.csdn.net/xiaowei_cqu/article/details/8096072

"OpenCV" sift principle and source code analysis: direction Assignment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.