void get_projection(em2d::Image *img, const ParticlesTemp &ps, const RegistrationResult ®, const ProjectingOptions &options, MasksManagerPtr masks, String name) { IMP_LOG_VERBOSE("Generating projection in a em2d::Image" << std::endl); if (masks == MasksManagerPtr()) { masks = MasksManagerPtr( new MasksManager(options.resolution, options.pixel_size)); masks->create_masks(ps); IMP_LOG_VERBOSE("Masks generated from get_projection()" << std::endl); } algebra::Vector3D translation = options.pixel_size * reg.get_shift_3d(); algebra::Rotation3D R = reg.get_rotation(); do_project_particles(ps, img->get_data(), R, translation, options, masks); if (options.normalize) em2d::do_normalize(img, true); reg.set_in_image(img->get_header()); img->get_header().set_object_pixel_size(options.pixel_size); if (options.save_images) { if (name.empty()) { IMP_THROW("get_projection: File name string is empty ", IOException); } if (options.srw == Pointer<ImageReaderWriter>()) { IMP_THROW( "The options class does not have an " "ImageReaderWriter assigned. Create an ImageReaderWriter " "and assigned to the srw member of ProjectingOptions.", IOException); } img->write(name, options.srw); } }
void Fine2DRegistrationRestraint::setup( ParticlesTemp &ps, const ProjectingParameters ¶ms, Model *scoring_model, // ScoreFunctionPtr score_function, ScoreFunction *score_function, MasksManagerPtr masks) { IMP_LOG_TERSE("Initializing Fine2DRegistrationRestraint" << std::endl); ps_ = ps; params_ = params; // Generate all the projection masks for the structure if (masks == MasksManagerPtr()) { // Create the masks masks_ = MasksManagerPtr(new MasksManager(params.resolution, params.pixel_size)); masks_->create_masks(ps); IMP_LOG_VERBOSE("Created " << masks_->get_number_of_masks() << " masks withing Fine2DRegistrationRestraint " << std::endl); } else { masks_ = masks; IMP_LOG_VERBOSE("masks given to Fine2DRegistrationRestraint " << std::endl); } // Create a particle for the projection parameters to be optimized subj_params_particle_ = new Particle(scoring_model); PP_ = ProjectionParameters::setup_particle(subj_params_particle_); PP_.set_parameters_optimized(true); // Add an score state to the model IMP_NEW(ProjectionParametersScoreState, pp_score_state, (subj_params_particle_)); scoring_model->add_score_state(pp_score_state); score_function_ = score_function; }
void do_project_particles(const ParticlesTemp &ps, cv::Mat &m2, const algebra::Rotation3D &R, const algebra::Vector3D &translation, const ProjectingOptions &options, MasksManagerPtr masks) { IMP_LOG_VERBOSE("Projecting particles" << std::endl); if (m2.empty()) { IMP_THROW("Cannot project on a empty matrix", ValueException); } if (masks == MasksManagerPtr()) { // Create the masks masks = MasksManagerPtr( new MasksManager(options.resolution, options.pixel_size)); masks->create_masks(ps); } // Centroid unsigned long n_particles = ps.size(); // core::XYZRsTemp xyzrs(ps); core::XYZRs xyzrs(ps); algebra::Vector3D centroid = core::get_centroid(xyzrs); // clear data before creating a new projection if (options.clear_matrix_before_projecting) m2.setTo(0.0); // Project double invp = 1.0 / options.pixel_size; for (unsigned long i = 0; i < n_particles; i++) { // Coordinates respect to the centroid algebra::Vector3D p = xyzrs[i].get_coordinates() - centroid; // Pixel after transformation to project in Z axis // Not necessary to compute pz, is going to be ignored double pix_x = invp * (R.get_rotated_one_coordinate(p, 0) + translation[0]); double pix_y = invp * (R.get_rotated_one_coordinate(p, 1) + translation[1]); IMP_USAGE_CHECK(!IMP::isnan(pix_x) || !IMP::isnan(pix_y), "do_project_particles: " << n_particles << " resolution " << options.resolution << " pixel size " << options.pixel_size << std::endl); // Apply mask ProjectionMaskPtr mask = masks->find_mask(atom::Mass(ps[i]).get_mass()); algebra::Vector2D pix(pix_x, pix_y); mask->apply(m2, pix); } IMP_LOG_VERBOSE("END of do_project_particles" << std::endl); }
IMPEM2D_BEGIN_NAMESPACE CollisionCrossSection::CollisionCrossSection(unsigned int n_projections, double resolution, double pixel_size, double projection_image_size) : Object("CollisionCrossSection%1%"), n_projections_(n_projections), resolution_(resolution), pixel_size_(pixel_size), img_size_(projection_image_size), particles_set_(false) { regs_ = em2d::get_evenly_distributed_registration_results(n_projections_); average_projection_.create(img_size_, img_size_, CV_64FC1); masks_manager_ = MasksManagerPtr(new MasksManager); masks_manager_->setup_kernel(resolution_, pixel_size_); }