double Cell::GetVesselnessValue(const GradientVectorType & grad_Dx_vector, const GradientVectorType & grad_Dy_vector, const GradientVectorType & grad_Dz_vector) { double Dxx = grad_Dx_vector[0]; double Dxy = grad_Dx_vector[1]; double Dxz = grad_Dx_vector[2]; double Dyx = grad_Dy_vector[0]; double Dyy = grad_Dy_vector[1]; double Dyz = grad_Dy_vector[2]; double Dzx = grad_Dz_vector[0]; double Dzy = grad_Dz_vector[1]; double Dzz = grad_Dz_vector[2]; double grad_GVF_matrix[3][3]; grad_GVF_matrix[0][0] = Dxx; grad_GVF_matrix[0][1] = Dxy; grad_GVF_matrix[0][2] = Dxz; grad_GVF_matrix[1][0] = Dyx; grad_GVF_matrix[1][1] = Dyy; grad_GVF_matrix[1][2] = Dyz; grad_GVF_matrix[2][0] = Dzx; grad_GVF_matrix[2][1] = Dzy; grad_GVF_matrix[2][2] = Dzz; double eigenvalues[3]; double eigenvectors[3][3]; EigenAnalysis::eigen_decomposition(grad_GVF_matrix, eigenvectors, eigenvalues); double Lambda1 = eigenvalues[0]; double Lambda2 = eigenvalues[1]; double Lambda3 = eigenvalues[2]; if ( Lambda2 >= 0.0 || Lambda3 > 0.0 ) { return 0.0; } else { static const double FrangiAlpha = 0.5; static const double FrangiBeta = 0.5; static const double FrangiC = 100.0; const double A = 2 * pow(FrangiAlpha,2); const double B = 2 * pow(FrangiBeta,2); const double C = 2 * pow(FrangiC,2); const double Ra = Lambda2 / Lambda3; const double Rb = Lambda1 / vcl_sqrt ( vnl_math_abs( Lambda2 * Lambda3 )); const double S = vcl_sqrt( pow(Lambda1,2) + pow(Lambda2,2) + pow(Lambda3,2)); const double vesMeasure_1 = ( 1 - vcl_exp(-1.0*(( vnl_math_sqr( Ra ) ) / ( A ))) ); const double vesMeasure_2 = vcl_exp ( -1.0 * ((vnl_math_sqr( Rb )) / ( B ))); const double vesMeasure_3 = ( 1 - vcl_exp( -1.0 * (( vnl_math_sqr( S )) / ( C ))) ); const double V_Saliency = vesMeasure_1 * vesMeasure_2 * vesMeasure_3; return V_Saliency; } }
void HomographyModel::compute_residuals (const vector< ScoredMatch> &data_points, vector<float> &residuals) const { // residuals -> errors // Compute the residuals relative to the given parameter vector. // based on rrel_homography2d_est :: compute_residuals vnl_matrix< double > H(3,3); int r,c; for ( r=0; r<3; ++r ) for ( c=0; c<3; ++c ) H( r, c ) = parameters[ 3*r + c ]; vnl_svd< double > svd_H( H ); if ( svd_H.rank() < 3 ) { if (true) cout << "H == " << H << endl; //throw runtime_error("HomographyModel::compute_residuals rank(H) < 3!!"); cout << "HomographyModel::compute_residuals rank(H) < 3!!" << endl; } vnl_matrix< double > H_inv( svd_H.inverse() ); residuals.resize(data_points.size()); // compute the residual of each data point vector< ScoredMatch>::const_iterator data_points_it; vector<float>::iterator residuals_it; vnl_vector< double > from_point( 3 ), to_point( 3 ); vnl_vector< double > trans_pt( 3 ), inv_trans_pt( 3 ); double del_x, del_y, inv_del_x, inv_del_y; for (data_points_it = data_points.begin(), residuals_it = residuals.begin(); data_points_it != data_points.end() && residuals_it != residuals.end(); ++data_points_it, ++residuals_it) { // from feature a to feature b from_point[0] = data_points_it->feature_a->x; from_point[1] = data_points_it->feature_a->y; from_point[2] = 1.0; to_point[0] = data_points_it->feature_b->x; to_point[1] = data_points_it->feature_b->y; to_point[2] = 1.0; trans_pt = H * from_point; inv_trans_pt = H_inv * to_point; if ( from_point[ 2 ] == 0 || to_point[ 2 ] == 0 || trans_pt[ 2 ] == 0 || inv_trans_pt[ 2 ] == 0 ) { *residuals_it = 1e10; } else { del_x = trans_pt[ 0 ] / trans_pt[ 2 ] - to_point[ 0 ] /to_point[ 2 ]; del_y = trans_pt[ 1 ] / trans_pt[ 2 ] - to_point[ 1 ] / to_point[ 2 ]; inv_del_x = inv_trans_pt[ 0 ] / inv_trans_pt[ 2 ] -from_point[ 0 ] / from_point[ 2 ]; inv_del_y = inv_trans_pt[ 1 ] / inv_trans_pt[ 2 ] - from_point[ 1 ] / from_point[ 2 ]; const double t_value = vnl_math_sqr(del_x) + vnl_math_sqr(del_y) + vnl_math_sqr(inv_del_x) + vnl_math_sqr(inv_del_y); *residuals_it = vcl_sqrt( t_value ); } } // end of 'for each data point' return; } // end of method FundamentalMatrixModel<F>::compute_residuals