Esempio n. 1
0
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;
	}
}
Esempio n. 2
0
void 
rich_cell::
update_eccentricity_and_radius()
{
  //Step1: project the points to the x-y plane
  std::vector<vnl_vector_fixed<double, 2> > points_2d;
  std::vector<bool> checked(all_points_.size(), false);
  
  for (unsigned int i = 0; i<all_points_.size(); i++) {
    if (!checked[i]) {
      //record the x-y position
      vnl_vector_fixed<double, 2> pt(all_points_[i][0],all_points_[i][1]);
      points_2d.push_back( pt );
      checked[i] = true;

      //scan through the list to see if other points in the remaining
      //list contains the same x-y position
      for (unsigned int j = i+1; j<all_points_.size(); j++) {
        if (all_points_[j][0] == all_points_[i][0] 
            && all_points_[j][1] == all_points_[i][1]) 
          checked[j] = true;
      }
    }
  }
  
  //Step2: compute the scatter matrix
  //
  // compute the center
  vnl_vector_fixed<double, 2> center(0.0,0.0);
  for (unsigned int i = 0; i<points_2d.size(); i++) {
    center += points_2d[i];
  }
  center /= (double)points_2d.size();

  vnl_matrix<double> cov_matrix(2,2,0.0);
  std::cout<<"points_2d.size = "<<points_2d.size()<<std::endl;
  for (unsigned int i = 0; i<points_2d.size(); i++) {
    cov_matrix += outer_product(points_2d[i]-center, points_2d[i]-center);
  }
  cov_matrix /= (double)points_2d.size();

  //perform eigen-value decomposition to get the semi-major (a) and minor (b) 
  vnl_svd<double> svd_from( cov_matrix );
  
  //eccentricity=sqrt( 1-(b^2/a^2) ). If the shape is close to
  //circular, the value is 0. 
  //eccentricity_ =vcl_sqrt( 1- (svd_from.W(1)*svd_from.W(1))/(svd_from.W(0)*svd_from.W(0)) );
  eccentricity_ =vcl_sqrt( 1- vnl_math_abs(svd_from.W(1)/svd_from.W(0)) );
  float long_axis_mag = vcl_sqrt(vnl_math_abs(svd_from.W(0)));
  float short_axis_mag = vcl_sqrt(vnl_math_abs(svd_from.W(1)));
  average_radius_ = 0.5*(long_axis_mag + short_axis_mag);
}
Esempio n. 3
0
void MyFRPROptimizer::GetValueAndDerivative(ParametersType & p, double *val,
		ParametersType *xi) {
	this->m_CostFunction->GetValueAndDerivative(p, *val, *xi);
	if (this->GetMaximize()) {
		(*val) = -(*val);
		for (unsigned int i = 0; i < this->GetSpaceDimension(); i++) {
			(*xi)[i] = -(*xi)[i];
		}
	}
	if (this->GetUseScaledGradient()) {
		ScalesType gradientScales = this->GetGradientScales();
		for (unsigned int i = 0; i < this->GetSpaceDimension(); i++) {
			(*xi)[i] = gradientScales[i] * (*xi)[i];
		}
	}

	if (this->GetUseUnitLengthGradient()) {
		double len = (*xi)[0] * (*xi)[0];
		for (unsigned int i = 1; i < this->GetSpaceDimension(); i++) {
			len += (*xi)[i] * (*xi)[i];
		}
		len = vcl_sqrt( len / this->GetSpaceDimension() );
		for (unsigned int i = 0; i < this->GetSpaceDimension(); i++) {
			(*xi)[i] /= len;
		}
	}
	// cout << "Xi = " << *xi << endl;
}
Esempio n. 4
0
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