em2d::Images get_projections(const ParticlesTemp &ps, const RegistrationResults ®istration_values, int rows, int cols, const ProjectingOptions &options, Strings names) { IMP_LOG_VERBOSE("Generating projections from registration results" << std::endl); if (options.save_images && (names.size() < registration_values.size())) { IMP_THROW("get_projections: Insufficient number of image names provided", IOException); } unsigned long n_projs = registration_values.size(); em2d::Images projections(n_projs); // Precomputation of all the possible projection masks for the particles MasksManagerPtr masks( new MasksManager(options.resolution, options.pixel_size)); masks->create_masks(ps); for (unsigned long i = 0; i < n_projs; ++i) { IMP_NEW(em2d::Image, img, ()); img->set_size(rows, cols); img->set_was_used(true); String name = ""; if (options.save_images) name = names[i]; get_projection(img, ps, registration_values[i], options, masks, name); projections[i] = img; } return projections; }
void write_registration_results(String filename, const RegistrationResults &results) { std::ofstream f(filename.c_str(), std::ios::out | std::ios::binary); results[0].write_comment_line(f); f << results.size() << std::endl; for (unsigned int i = 0; i < results.size(); ++i) { results[i].write(f); } f.close(); }
RegistrationResults get_random_registration_results(unsigned int n, double maximum_shift) { RegistrationResults results; for (unsigned int i = 0; i < n; ++i) { RegistrationResult rr; rr.set_random_registration(i, maximum_shift); results.push_back(rr); } return results; }
RegistrationResults get_evenly_distributed_registration_results( unsigned int n_projections) { algebra::SphericalVector3Ds vs; em2d::internal::semispherical_even_distribution(n_projections, vs); RegistrationResults results; for (unsigned int i = 0; i < n_projections; ++i) { algebra::Rotation3D R = em2d::internal::get_rotation_from_projection_direction(vs[i]); algebra::Vector2D shift(0.0, 0.0); results.push_back(RegistrationResult(R, shift, i, 0)); } return results; }
void ProjectionFinder::get_coarse_registrations_for_subject( unsigned int i,RegistrationResults &coarse_RRs) { IMP_LOG_TERSE("ProjectionFinder: Coarse registration for subject " << i << std::endl); algebra::Transformation2D best_2d_transformation; double max_ccc=0.0; unsigned int projection_index = 0; coarse_RRs.resize(projections_.size()); for(unsigned long j=0;j<projections_.size();++j) { ResultAlign2D RA; // Method without preprocessing if(params_.coarse_registration_method == ALIGN2D_NO_PREPROCESSING) { RA=get_complete_alignment(subjects_[i]->get_data(), projections_[j]->get_data(),false); } // Methods with preprocessing and FFT alignment if(params_.coarse_registration_method == ALIGN2D_PREPROCESSING) { RA=get_complete_alignment_no_preprocessing(subjects_[i]->get_data(), SUBJECTS_[i], SUBJECTS_POLAR_AUTOC_[i], projections_[j]->get_data(), PROJECTIONS_POLAR_AUTOC_[j]); } // Method with centers of gravity alignment if(params_.coarse_registration_method == ALIGN2D_WITH_CENTERS) { RA = get_complete_alignment_with_centers_no_preprocessing( subjects_cog_[i], projections_cog_[j], SUBJECTS_POLAR_AUTOC_[i], PROJECTIONS_POLAR_AUTOC_[j]); // get_complete_alignment_with_centers_no_preprocessing returns a value of // Cross correlation from the rotational alignment but not the ccc. // compute the ccc here: cv::Mat aux; get_transformed(projections_[j]->get_data(),aux,RA.first); RA.second=get_cross_correlation_coefficient(subjects_[i]->get_data(),aux); } // Set result algebra::Vector2D shift(0.,0.); // Get values from the image algebra::Vector3D euler = projections_[j]->get_header().get_euler_angles(); algebra::Rotation3D R = algebra::get_rotation_from_fixed_zyz(euler[0], euler[1], euler[2]); RegistrationResult projection_result(R,shift,j,i); projection_result.set_ccc(RA.second); // The coarse registration is based on maximizing the // cross-correlation-coefficient, but any other score can be calculated // at this point. IMP_NEW(Image,aux,()); aux->set_was_used(true); get_transformed(projections_[j]->get_data(), aux->get_data(), RA.first); if(variances_.size() > 0) { score_function_->set_variance_image(variances_[i]); } double score = score_function_->get_score(subjects_[i], aux); projection_result.set_score(score); // add the 2D alignment transformation to the registration result // for the projection projection_result.add_in_plane_transformation(RA.first); // and store coarse_RRs[j]=projection_result; IMP_LOG_VERBOSE( "Coarse registration: " << coarse_RRs[j] << std::endl); if(RA.second>max_ccc) { max_ccc = RA.second; best_2d_transformation = RA.first; projection_index = j; } ///******/ // cv::Mat xx; // get_transformed(projections_[j]->get_data(),xx,RA.first); // std::ostringstream strmm; // strmm << "individual-" << i << "-" << j << ".spi"; // write_matrix(xx,strmm.str()); ///******/ } if(params_.save_match_images) { IMP_NEW(em2d::Image,match,()); get_transformed(projections_[projection_index]->get_data(), match->get_data(), best_2d_transformation); do_normalize(match,true); coarse_RRs[projection_index].set_in_image(match->get_header()); std::ostringstream strm; strm << "coarse_match-"; strm.fill('0'); strm.width(4); strm << i << ".spi"; IMP_NEW(em2d::SpiderImageReaderWriter, srw, ()); match->set_name(strm.str()); //// match->set_was_used(true); match->write(strm.str(),srw); }