IMPEM2D_BEGIN_NAMESPACE ResultAlign2D get_complete_alignment(const cv::Mat &input, cv::Mat &m_to_align, bool apply) { IMP_LOG_TERSE("starting complete 2D alignment " << std::endl); cv::Mat autoc1, autoc2, aux1, aux2, aux3; algebra::Transformation2D transformation1, transformation2; ResultAlign2D RA; get_autocorrelation2d(input, autoc1); get_autocorrelation2d(m_to_align, autoc2); RA = get_rotational_alignment(autoc1, autoc2, false); double angle1 = RA.first.get_rotation().get_angle(); get_transformed(m_to_align, aux1, RA.first); // rotate RA = get_translational_alignment(input, aux1); algebra::Vector2D shift1 = RA.first.get_translation(); transformation1.set_rotation(angle1); transformation1.set_translation(shift1); get_transformed(m_to_align, aux2, transformation1); double ccc1 = get_cross_correlation_coefficient(input, aux2); // Check for both angles that can be the solution double angle2; if (angle1 < PI) { angle2 = angle1 + PI; } else { angle2 = angle1 - PI; } // rotate algebra::Rotation2D R2(angle2); algebra::Transformation2D tr(R2); get_transformed(m_to_align, aux3, tr); RA = get_translational_alignment(input, aux3); algebra::Vector2D shift2 = RA.first.get_translation(); transformation2.set_rotation(angle2); transformation2.set_translation(shift2); get_transformed(m_to_align, aux3, transformation2); double ccc2 = get_cross_correlation_coefficient(input, aux3); if (ccc2 > ccc1) { if (apply) { aux3.copyTo(m_to_align); } IMP_LOG_VERBOSE(" Transformation= " << transformation2 << " cross_correlation = " << ccc2 << std::endl); return em2d::ResultAlign2D(transformation2, ccc2); } else { if (apply) { aux2.copyTo(m_to_align); } IMP_LOG_VERBOSE(" Transformation= " << transformation1 << " cross_correlation = " << ccc1 << std::endl); return em2d::ResultAlign2D(transformation1, ccc1); } }
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]); } }