Example #1
0
void gmmreg_base::save_transformed(const char* filename,
    const vnl_vector<double>& params, const char* f_config) {
  std::ofstream outfile(filename, std::ios_base::out);
  perform_transform(params);
  denormalize_all();
  transformed_model.print(outfile);

  char section_correspondence[256] = "CORRESPONDENCE";
  int num = GetPrivateProfileInt(section_correspondence,
                                 "num_of_thresholds", 0, f_config);
  if (num > 0) {
    char s_min[256], s_max[256], s_pairs[256];
    GetPrivateProfileString(section_correspondence,
        "min_threshold", NULL, s_min, 255, f_config);
    GetPrivateProfileString(section_correspondence,
        "max_threshold", NULL, s_max, 255, f_config);
    GetPrivateProfileString(section_correspondence,
        "matched_pairs", NULL, s_pairs, 255, f_config);
    std::ofstream f_pair(s_pairs, std::ios_base::out);
    double min_threshold, max_threshold, interval;
    min_threshold = atof(s_min);
    max_threshold = atof(s_max);
    if (num == 1) {
      interval = 0.0f;
    } else {
      interval = (max_threshold - min_threshold) / (num - 1);
    }
    //vnl_matrix<double> working_M, working_S;
    vnl_matrix<double> dist;
    vnl_matrix<int> pairs;
    ComputeSquaredDistanceMatrix(transformed_model, scene, dist);
    for (int i = 0; i < num; ++i) {
      double threshold  = min_threshold + i*interval;
      //int n_match = find_working_pair(model, scene, transformed_model,
      //                                threshold, working_M, working_S);
      pick_indices(dist, pairs, threshold*threshold);
      //printf("%f : %d\n",threshold, n_match);
      f_pair << "distance threshold : " << threshold << std::endl;
      f_pair << "# of matched point pairs : " << pairs.cols() << std::endl;
      int j;
      for (j = 0; j < pairs.cols(); ++j) {
        f_pair.width(6);
        f_pair << std::left << pairs(0, j);
      }
      f_pair << std::endl;
      for (j = 0; j < pairs.cols(); ++j) {
        f_pair.width(6);
        f_pair << std::left << pairs(1, j);
      }
      f_pair << std::endl;
    }
  }
  std::cout << "Please find the transformed model set in "
            << filename << std::endl;
}
Example #2
0
int find_working_pair(const vnl_matrix<double>&M, const vnl_matrix<double>&S,
    const vnl_matrix<double>&Transformed_M, const double threshold,
    vnl_matrix<double>&working_M, vnl_matrix<double>&working_S) {
  vnl_matrix<double> dist;
  ComputeSquaredDistanceMatrix(Transformed_M, S, dist);
  std::vector<int> row_index, col_index;
  pick_indices(dist, row_index, col_index, threshold);
  select_points(M, row_index, working_M);
  select_points(S, col_index, working_S);
  return row_index.size();
}
Example #3
0
void f(const vnl_matrix<double>& model,
    const vnl_matrix<double>& scene, double threshold,
    vnl_matrix<double>& extracted_model,
    vnl_matrix<double>& extracted_scene) {
  vnl_matrix<double> dist;
  vnl_matrix<int> pairs;
  ComputeSquaredDistanceMatrix(model, scene, dist);
  pick_indices(dist, pairs, threshold*threshold);
  std::cout << "distance threshold : " << threshold << std::endl;
  int j, n = pairs.cols();
  int d = model.cols();
  extracted_model.set_size(n,d);
  extracted_scene.set_size(n,d);
  std::cout << "# of matched point pairs : " << n << std::endl;
  for (j=0; j<n; ++j) {
    extracted_model.set_row(j,model.get_row(pairs(0,j)));
  }
  for (j=0; j<n; ++j) {
    extracted_scene.set_row(j,scene.get_row(pairs(1,j)));
  }
}