EMAN2
Public Member Functions | Static Public Member Functions | Static Public Attributes
EMAN::RotateTranslateFlipAlignerPawel Class Reference

Rotational, translational alignment by resampling to polar coordinates. More...

#include <aligner.h>

Inheritance diagram for EMAN::RotateTranslateFlipAlignerPawel:
Inheritance graph
[legend]
Collaboration diagram for EMAN::RotateTranslateFlipAlignerPawel:
Collaboration graph
[legend]

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 Public Attributes

static const string NAME = "rotate_translate_flip_resample"

Detailed Description

Rotational, translational alignment by resampling to polar coordinates.

translation if found by varing to origin using for polar coordinate resampling in real space

Parameters:
txmaximum transltion in x direction, must by less than (n/2 - 1 - r2)
tumaximum transltion in y direction, must by less than (n/2 - 1 - r2)
r1inner ring
r2outer ring
Author:
John Flanagan
Date:
Feb 9th 2011

Definition at line 1038 of file aligner.h.


Member Function Documentation

EMData * RotateTranslateFlipAlignerPawel::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.

Parameters:
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.
Returns:
The aligned image.

Implements EMAN::Aligner.

Definition at line 931 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::Aligner::params, EMAN::EMData::process(), EMAN::EMData::process_inplace(), EMAN::EMData::set_attr(), EMAN::Dict::set_default(), EMAN::EMData::unwrap(), x, and y.

Referenced by align().

{
        if (cmp_name != "dot" && cmp_name != "ccc") throw InvalidParameterException("Resample aligner only works for dot and ccc");
        
        int maxtx = params.set_default("tx", 0);
        int maxty = params.set_default("ty", 0);
        int r1 = params.set_default("r1",-1);
        int r2 = params.set_default("r2",-1);
        
        if(this_img->get_xsize()/2 - 1 - r2 - maxtx <= 0 || (r2 == -1 && maxtx > 0)){
                cout << "\nRunTimeError: nx/2 - 1 - r2 - tx must be greater than or = 0\n" << endl; // For some reason the expection message is not being print, stupid C++
                throw InvalidParameterException("nx/2 - 1 - r2 - tx must be greater than or = 0");
        }
        if(this_img->get_ysize()/2 - 1 - r2 - maxty <= 0 || (r2 == -1 && maxty > 0)){
                cout << "\nRunTimeError:ny/2 - 1 - r2 - ty must be greater than or = 0\n" << endl; // For some reason the expection message is not being print, stupid C++
                throw InvalidParameterException("ny/2 - 1 - r2 - ty must be greater than or = 0");
        }
        
//      float best_peak = -numeric_limits<float>::infinity();
        float best_peak = -1.0e37;
        int best_peak_index = 0;
        int best_tx = 0;
        int best_ty = 0;
        int polarxsize = 0;
        bool flip = false;
        
        for(int x = -maxtx; x <= maxtx; x++){
                for(int y = -maxty; y <= maxty; y++){

                        EMData * to_polar = to->unwrap(r1,r2,-1,0,0,true);
                        EMData * this_img_polar = this_img->unwrap(r1,r2,-1,x,y,true);
                        EMData * cfflip = this_img_polar->calc_ccfx(to_polar, 0, this_img_polar->get_ysize(), false, true);
                        EMData * cf = this_img_polar->calc_ccfx(to_polar, 0, this_img_polar->get_ysize());
                        
                        polarxsize = this_img_polar->get_xsize();
                        
                        //take out the garbage
                        delete to_polar; to_polar = 0;
                        delete this_img_polar; this_img_polar = 0;
        
                        float *data = cf->get_data();
                        float peak = 0;
                        int peak_index = 0;
                        Util::find_max(data, polarxsize, &peak, &peak_index);
                        delete cf; cf = 0;

                        if(peak > best_peak) {
                                best_peak = peak;
                                best_peak_index = peak_index;
                                best_tx = x;
                                best_ty = y;
                                flip = false;
                        }
                        
                        data = cfflip->get_data();
                        Util::find_max(data, polarxsize, &peak, &peak_index);
                        delete cfflip; cfflip = 0;

                        if(peak > best_peak) {
                                best_peak = peak;
                                best_peak_index = peak_index;
                                best_tx = x;
                                best_ty = y;
                                flip = true;
                        }
                }
        }
        
        float rot_angle = (float) (best_peak_index * 360.0f / polarxsize);
                                
        //return the result
        Transform tmptt(Dict("type","2d","alpha",0,"tx",-best_tx,"ty",-best_ty));
        Transform tmprot(Dict("type","2d","alpha",rot_angle,"tx",0,"ty",0));
        Transform total = tmprot*tmptt;
        EMData * rotimg=this_img->process("xform",Dict("transform",(Transform*)&total));
        rotimg->set_attr("xform.align2d",&total);
        if(flip == true) {
                rotimg->process_inplace("xform.flip",Dict("axis", "x"));
        }
        
        return rotimg;
        
}
virtual EMData* EMAN::RotateTranslateFlipAlignerPawel::align ( EMData this_img,
EMData to_img 
) const [inline, virtual]

Implements EMAN::Aligner.

Definition at line 1044 of file aligner.h.

References align().

                {
                        return align(this_img, to_img, "sqeuclidean", Dict());
                }
virtual string EMAN::RotateTranslateFlipAlignerPawel::get_desc ( ) const [inline, virtual]

Implements EMAN::Aligner.

Definition at line 1054 of file aligner.h.

                {
                        return "Performs rotational alignment, translation align, and flip by resampling to polar coordinates in real space.";
                }
virtual string EMAN::RotateTranslateFlipAlignerPawel::get_name ( ) const [inline, virtual]

Get the Aligner's name.

Each Aligner is identified by a unique name.

Returns:
The Aligner's name.

Implements EMAN::Aligner.

Definition at line 1049 of file aligner.h.

References NAME.

                {
                        return NAME;
                }
virtual TypeDict EMAN::RotateTranslateFlipAlignerPawel::get_param_types ( ) const [inline, virtual]

Implements EMAN::Aligner.

Definition at line 1064 of file aligner.h.

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

                {
                        TypeDict d;
                        //d.put("usedot", EMObject::INT);
                        d.put("tx", EMObject::INT, "Maximum x translation in pixels, Default = 0");
                        d.put("ty", EMObject::INT, "Maximum y translation in pixels, Default = 0");
                        d.put("r1", EMObject::INT, "Inner ring, pixels");
                        d.put("r2", EMObject::INT, "Outer ring, pixels");
                        return d;
                }
static Aligner* EMAN::RotateTranslateFlipAlignerPawel::NEW ( ) [inline, static]

Definition at line 1059 of file aligner.h.

                {
                        return new RotateTranslateFlipAlignerPawel();
                }

Member Data Documentation

const string RotateTranslateFlipAlignerPawel::NAME = "rotate_translate_flip_resample" [static]

Definition at line 1075 of file aligner.h.

Referenced by get_name().


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