/* Given a sample from the image gradient, place it in the index array.
*/
void AddSample(
	float index[IndexSize][IndexSize][OriSize], keypoint& key,
	const flimage& grad, const flimage& orim,
	float r, float c, float rpos, float cpos, float rx, float cx,siftPar &par)
{
	/* Clip at image boundaries. */
	if (r < 0  ||  r >= grad.nheight()  ||  c < 0  ||  c >= grad.nwidth())
		return;

	/* Compute Gaussian weight for sample, as function of radial distance
	   from center.  Sigma is relative to half-width of index. */
	float	sigma  = par.IndexSigma * 0.5 * IndexSize,
		weight = exp(- (rpos * rpos + cpos * cpos) / (2.0 * sigma * sigma)),
//		mag    = weight *  grad(c,r); 
		mag    = weight *  grad((int)c,(int)r); // Guoshen Yu, explicitely cast to int to avoid warning


	/* Subtract keypoint orientation to give ori relative to keypoint. */
//	float	ori = orim(c,r) -  key.angle; 
	float	ori = orim((int)c,(int)r) -  key.angle; // Guoshen Yu, explicitely cast to int to avoid warning


	/* Put orientation in range [0, 2*PI].  If sign of gradient is to
	   be ignored, then put in range [0, PI]. */
	if (par.IgnoreGradSign) {
		while (ori > PI ) ori -= PI;
		while (ori < 0.0) ori += PI;
	} else {
		while (ori > 2.0*PI) ori -= 2.0*PI;
		while (ori < 0.0   ) ori += 2.0*PI;
	}
	PlaceInIndex(index, mag, ori, rx, cx,par);
}
Exemple #2
0
/* Given a sample from the image gradient, place it in the index array.
*/
void AddSample(
	float index[IndexSize][IndexSize][OriSize], keypoint& key,
	const flimage& grad,
	int r, int c, float rpos, float cpos, float rx, float cx,siftPar &par)
{
	/* Clip at image boundaries. */
	if (r < 0  ||  r >= grad.h  ||  c < 0  ||  c >= grad.w)
		return;

    const float* g = grad.pixel(c,r);
	/* Compute Gaussian weight for sample, as function of radial distance
	   from center.  Sigma is relative to half-width of index. */
	float	sigma  = par.IndexSigma * 0.5f * IndexSize,
		weight = exp(- (rpos * rpos + cpos * cpos) / (2.0f * sigma * sigma)),
		mag    = weight * g[0];

	/* Subtract keypoint orientation to give ori relative to keypoint. */
	float	ori = g[1] - key.angle;

	/* Put orientation in range [0, 2*PI].  If sign of gradient is to
	   be ignored, then put in range [0, PI]. */
	if (par.IgnoreGradSign) {
		while (ori > M_PI ) ori -= M_PI;
		while (ori < 0.0f) ori += M_PI;
	} else {
		while (ori > 2.0f*M_PI) ori -= 2.0f*M_PI;
		while (ori < 0.0f   ) ori += 2.0f*M_PI;
	}
	PlaceInIndex(index, mag, ori, rx, cx,par);
}
Exemple #3
0
/* Given a sample from the image gradient, place it in the index array.
*/
void AddSample(float index[IndexSize][IndexSize][OriSize], KKeypoint k,
	       Image grad, Image orim, int r, int c, float rpos, float cpos,
	       float rx, float cx)
{
    float mag, ori, sigma, weight;
    
    /* Clip at image boundaries. */
    if (r < 0  ||  r >= grad->rows  ||  c < 0  ||  c >= grad->cols)
       return;
    
    /* Compute Gaussian weight for sample, as function of radial distance
       from center.  Sigma is relative to half-width of index.
    */
    sigma = IndexSigma * 0.5 * IndexSize;
    weight = exp(- (rpos * rpos + cpos * cpos) / (2.0 * sigma * sigma));

    mag = weight * grad->pixels[r][c];

    /* Subtract keypoint orientation to give ori relative to keypoint. */
    ori = orim->pixels[r][c] - k->ori;
    
    /* Put orientation in range [0, 2*PII].  If sign of gradient is to
       be ignored, then put in range [0, PII].
    */
    if (IgnoreGradSign) {
       while (ori > PII)
          ori -= PII;
       while (ori < 0.0)
          ori += PII;
    } else {
       while (ori > 2*PII)
          ori -= 2*PII;
       while (ori < 0.0)
          ori += 2*PII;
    }
    PlaceInIndex(index, mag, ori, rx, cx);
}