Public Member Functions | Static Public Member Functions | Static Public Attributes
EMAN::RotationalAligner Class Reference

rotational alignment using angular correlation More...

#include <aligner.h>

Inheritance diagram for EMAN::RotationalAligner:
Inheritance graph
Collaboration diagram for EMAN::RotationalAligner:
Collaboration graph

List of all members.

Public Member Functions

virtual EMDataalign (EMData *this_img, EMData *to_img, const string &cmp_name="dot", const Dict &cmp_params=Dict()) const
 To align 'this_img' with another image passed in through its parameters.
virtual EMDataalign (EMData *this_img, EMData *to_img) const
virtual string get_name () const
 Get the Aligner's name.
virtual string get_desc () const
virtual TypeDict get_param_types () const

Static Public Member Functions

static AlignerNEW ()
static EMDataalign_180_ambiguous (EMData *this_img, EMData *to_img, int rfp_mode=2, int zscore=0)

Static Public Attributes

static const string NAME = "rotational"

Detailed Description

rotational alignment using angular correlation

rfp_modeEither 0,1 or 2. A temporary flag for testing the rotational foot print. O is the original eman1 way. 1 is just using calc_ccf without padding. 2 is using calc_mutual_correlation without padding

Definition at line 285 of file aligner.h.

Member Function Documentation

EMData * RotationalAligner::align ( EMData this_img,
EMData to_img,
const string &  cmp_name = "dot",
const Dict cmp_params = Dict() 
) const [virtual]

To align 'this_img' with another image passed in through its parameters.

The alignment uses a user-given comparison method to compare the two images. If none is given, a default one is used.

this_imgThe image to be compared.
to_img'this_img" is aligned with 'to_img'.
cmp_nameThe comparison method to compare the two images.
cmp_paramsThe parameter dictionary for comparison method.
The aligned image.

Implements EMAN::Aligner.

Definition at line 440 of file aligner.cpp.

References align_180_ambiguous(), EMAN::EMData::cmp(), EMAN::EMData::get_attr(), EMAN::Transform::get_rotation(), InvalidParameterException, EMAN::Aligner::params, EMAN::EMData::process(), EMAN::EMData::set_attr(), and EMAN::Dict::set_default().

Referenced by align().

        if (!to) throw InvalidParameterException("Can not rotational align - the image to align to is NULL");
        if(EMData::usecuda == 1) {
                //if(!this_img->getcudarwdata()) this_img->copy_to_cuda();
                //if(!to->getcudarwdata()) to->copy_to_cuda();

        // Perform 180 ambiguous alignment
        int rfp_mode = params.set_default("rfp_mode",2);
        int zscore = params.set_default("zscore",0);
        int ambig180 = params.set_default("ambig180",0);
        EMData* rot_aligned = RotationalAligner::align_180_ambiguous(this_img,to,rfp_mode,zscore);
        Transform * tmp = rot_aligned->get_attr("xform.align2d");
        Dict rot = tmp->get_rotation("2d");
        float rotate_angle_solution = rot["alpha"];
        delete tmp;

        // Don't resolve the 180 degree ambiguity here
        if (ambig180) {
                return rot_aligned;
        EMData *rot_align_180 = rot_aligned->process("math.rotate.180");

        // Generate the comparison metrics for both rotational candidates
        float rot_cmp = rot_aligned->cmp(cmp_name, to, cmp_params);
        float rot_180_cmp = rot_align_180->cmp(cmp_name, to, cmp_params);

        // Decide on the result
        float score = 0.0;
        EMData* result = NULL;
        if (rot_cmp < rot_180_cmp){
                result = rot_aligned;
                score = rot_cmp;
                delete rot_align_180; rot_align_180 = 0;
        } else {
                result = rot_align_180;
                score = rot_180_cmp;
                delete rot_aligned; rot_aligned = 0;
                rotate_angle_solution = rotate_angle_solution-180.0f;

//      Transform* t = get_align_attr("xform.align2d",result);
//      t->set_rotation(Dict("type","2d","alpha",rotate_angle_solution));
        Transform tmp2(Dict("type","2d","alpha",rotate_angle_solution));
        return result;
virtual EMData* EMAN::RotationalAligner::align ( EMData this_img,
EMData to_img 
) const [inline, virtual]

Implements EMAN::Aligner.

Definition at line 291 of file aligner.h.

References align().

                        return align(this_img, to_img, "dot", Dict());
EMData * RotationalAligner::align_180_ambiguous ( EMData this_img,
EMData to_img,
int  rfp_mode = 2,
int  zscore = 0 
) [static]

Definition at line 386 of file aligner.cpp.

References EMAN::EMData::calc_ccfx(), data, EMAN::Util::find_max(), EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), InvalidParameterException, EMAN::EMData::make_rotational_footprint(), EMAN::EMData::make_rotational_footprint_cmc(), EMAN::EMData::make_rotational_footprint_e1(), EMAN::EMData::process(), and EMAN::EMData::set_attr().

Referenced by EMAN::RotateTranslateAligner::align(), and align().


        // Make translationally invariant rotational footprints
        EMData* this_img_rfp, * to_rfp;
        if (rfp_mode == 0) {
                this_img_rfp = this_img->make_rotational_footprint_e1();
                to_rfp = to->make_rotational_footprint_e1();
        } else if (rfp_mode == 1) {
                this_img_rfp = this_img->make_rotational_footprint();
                to_rfp = to->make_rotational_footprint();
        } else if (rfp_mode == 2) {
                this_img_rfp = this_img->make_rotational_footprint_cmc();
                to_rfp = to->make_rotational_footprint_cmc();
        } else {
                throw InvalidParameterException("rfp_mode must be 0,1 or 2");
        int this_img_rfp_nx = this_img_rfp->get_xsize();

        // Do row-wise correlation, returning a sum.
        EMData *cf = this_img_rfp->calc_ccfx(to_rfp, 0, this_img->get_ysize(),false,false,zscore);
// cf->process_inplace("normalize");
// cf->write_image("ralisum.hdf",-1);
// EMData *cf2 = this_img_rfp->calc_ccfx(to_rfp, 0, this_img->get_ysize(),true);
// cf2->write_image("ralistack.hdf",-1);
// delete cf2;

        // Delete them, they're no longer needed
        delete this_img_rfp; this_img_rfp = 0;
        delete to_rfp; to_rfp = 0;

        // Now solve the rotational alignment by finding the max in the column sum
        float *data = cf->get_data();
        float peak = 0;
        int peak_index = 0;
        Util::find_max(data, this_img_rfp_nx, &peak, &peak_index);

        if( cf ) {
                delete cf;
                cf = 0;
        float rot_angle = (float) (peak_index * 180.0f / this_img_rfp_nx);

        // Return the result
        Transform tmp(Dict("type","2d","alpha",rot_angle));
//      Transform* t = get_set_align_attr("xform.align2d",cf,this_img);
//      Dict d("type","2d","alpha",rot_angle);
//      t->set_rotation(d);
        return cf;
virtual string EMAN::RotationalAligner::get_desc ( ) const [inline, virtual]

Implements EMAN::Aligner.

Definition at line 301 of file aligner.h.

                        return "Performs rotational alignment, even on poorly centered images, but leaves a 180 degree ambiguity which requires a translational alignment to resolve. Usually called internally by rotate_translate aligner.";
virtual string EMAN::RotationalAligner::get_name ( ) const [inline, virtual]

Get the Aligner's name.

Each Aligner is identified by a unique name.

The Aligner's name.

Implements EMAN::Aligner.

Definition at line 296 of file aligner.h.

References NAME.

                        return NAME;
virtual TypeDict EMAN::RotationalAligner::get_param_types ( ) const [inline, virtual]

Implements EMAN::Aligner.

Definition at line 313 of file aligner.h.

References EMAN::EMObject::INT, and EMAN::TypeDict::put().

                        TypeDict d;
                        d.put("rfp_mode", EMObject::INT,"Either 0,1 or 2. A temporary flag for testing the rotational foot print. O is the original eman1 way. 1 is just using calc_ccf without padding. 2 is using calc_mutual_correlation without padding.");
                        d.put("zscore", EMObject::INT,"Either 0 or 1. If set, will convert per-radius CCF curves into Z-score significnace curves before averaging. In theory this should produce better results by focusing on radii with more alignment information. (default=false)");
                        d.put("ambig180", EMObject::INT,"Either 0 or 1. If set, will not try and resolve the 180 degree ambiguity. If not set, it will assume the particle is well centered and resolve the ambiguity that way. default=false");
                        return d;
static Aligner* EMAN::RotationalAligner::NEW ( ) [inline, static]

Definition at line 306 of file aligner.h.

                        return new RotationalAligner();

Member Data Documentation

const string RotationalAligner::NAME = "rotational" [static]

Definition at line 322 of file aligner.h.

Referenced by get_name().

The documentation for this class was generated from the following files: