Пример #1
0
ResultAlign2D get_rotational_alignment(const cv::Mat &input,
                          cv::Mat &m_to_align,bool apply) {
  IMP_LOG_TERSE(
          "starting 2D rotational alignment" << std::endl);
  IMP_USAGE_CHECK((input.rows==m_to_align.rows) &&
                  (input.cols==m_to_align.cols),
                  "em2d::align_rotational: Matrices have different size.");

  cv::Mat polar1,polar2,corr;
  // Build maps for resampling
  PolarResamplingParameters polar_params(input.rows,input.cols);
  polar_params.set_estimated_number_of_angles(std::min(input.rows,input.cols));

  polar_params.create_maps_for_resampling();
  do_resample_polar(input,polar1,polar_params);  // subject image
  do_resample_polar(m_to_align,polar2,polar_params); // projection image

  ResultAlign2D RA= get_translational_alignment(polar1,polar2);
  algebra::Vector2D shift=RA.first.get_translation();
  // column shift[0] is the optimal angle to bring m_to_align to input
  double angle =shift[0]*polar_params.get_angle_step();
  RA.first.set_rotation(angle);
  RA.first.set_translation(algebra::Vector2D(0.0,0.0));
  // Apply the rotation if requested
  if(apply) {
    cv::Mat result;
    get_transformed(m_to_align,result,RA.first);
    result.copyTo(m_to_align);
  }
  IMP_LOG_VERBOSE("Rotational alingment: Transformation= "
          << RA.first << " cross_correlation = " << RA.second << std::endl);
  return RA;
}
Пример #2
0
void ProjectionFinder::do_preprocess_subject(unsigned int i) {
  IMP_LOG_TERSE("ProjectionFinder: Preprocessing subject " << i << std::endl);

  if (params_.coarse_registration_method == ALIGN2D_PREPROCESSING) {
    cv::Mat autoc, polar_autoc;
    get_fft_using_optimal_size(subjects_[i]->get_data(), SUBJECTS_[i]);
    get_autocorrelation2d(subjects_[i]->get_data(), autoc);
    do_resample_polar(autoc, polar_autoc, polar_params_);
    get_fft_using_optimal_size(polar_autoc, SUBJECTS_POLAR_AUTOC_[i]);
  }
  if (params_.coarse_registration_method == ALIGN2D_WITH_CENTERS) {
    do_preprocess_for_fast_coarse_registration(
        subjects_[i]->get_data(), subjects_cog_[i], SUBJECTS_POLAR_AUTOC_[i]);
  }
}