Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

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

AlignerNEW ()

Static Public Attributes

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:
tx maximum transltion in x direction, must by less than (n/2 - 1 - r2)
tu maximum transltion in y direction, must by less than (n/2 - 1 - r2)
r1 inner ring
r2 outer ring
Author:
John Flanagan
Date:
Feb 9th 2011

Definition at line 1038 of file aligner.h.


Member Function Documentation

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().

01045                 {
01046                         return align(this_img, to_img, "sqeuclidean", Dict());
01047                 }

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_img The image to be compared.
to_img 'this_img" is aligned with 'to_img'.
cmp_name The comparison method to compare the two images.
cmp_params The 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::EMData::process(), EMAN::EMData::process_inplace(), EMAN::EMData::set_attr(), EMAN::Dict::set_default(), EMAN::EMData::unwrap(), x, and y.

00933 {
00934         if (cmp_name != "dot" && cmp_name != "ccc") throw InvalidParameterException("Resample aligner only works for dot and ccc");
00935         
00936         int maxtx = params.set_default("tx", 0);
00937         int maxty = params.set_default("ty", 0);
00938         int r1 = params.set_default("r1",-1);
00939         int r2 = params.set_default("r2",-1);
00940         
00941         if(this_img->get_xsize()/2 - 1 - r2 - maxtx <= 0 || (r2 == -1 && maxtx > 0)){
00942                 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++
00943                 throw InvalidParameterException("nx/2 - 1 - r2 - tx must be greater than or = 0");
00944         }
00945         if(this_img->get_ysize()/2 - 1 - r2 - maxty <= 0 || (r2 == -1 && maxty > 0)){
00946                 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++
00947                 throw InvalidParameterException("ny/2 - 1 - r2 - ty must be greater than or = 0");
00948         }
00949         
00950 //      float best_peak = -numeric_limits<float>::infinity();
00951         float best_peak = -1.0e37;
00952         int best_peak_index = 0;
00953         int best_tx = 0;
00954         int best_ty = 0;
00955         int polarxsize = 0;
00956         bool flip = false;
00957         
00958         for(int x = -maxtx; x <= maxtx; x++){
00959                 for(int y = -maxty; y <= maxty; y++){
00960 
00961                         EMData * to_polar = to->unwrap(r1,r2,-1,0,0,true);
00962                         EMData * this_img_polar = this_img->unwrap(r1,r2,-1,x,y,true);
00963                         EMData * cfflip = this_img_polar->calc_ccfx(to_polar, 0, this_img_polar->get_ysize(), false, true);
00964                         EMData * cf = this_img_polar->calc_ccfx(to_polar, 0, this_img_polar->get_ysize());
00965                         
00966                         polarxsize = this_img_polar->get_xsize();
00967                         
00968                         //take out the garbage
00969                         delete to_polar; to_polar = 0;
00970                         delete this_img_polar; this_img_polar = 0;
00971         
00972                         float *data = cf->get_data();
00973                         float peak = 0;
00974                         int peak_index = 0;
00975                         Util::find_max(data, polarxsize, &peak, &peak_index);
00976                         delete cf; cf = 0;
00977 
00978                         if(peak > best_peak) {
00979                                 best_peak = peak;
00980                                 best_peak_index = peak_index;
00981                                 best_tx = x;
00982                                 best_ty = y;
00983                                 flip = false;
00984                         }
00985                         
00986                         data = cfflip->get_data();
00987                         Util::find_max(data, polarxsize, &peak, &peak_index);
00988                         delete cfflip; cfflip = 0;
00989 
00990                         if(peak > best_peak) {
00991                                 best_peak = peak;
00992                                 best_peak_index = peak_index;
00993                                 best_tx = x;
00994                                 best_ty = y;
00995                                 flip = true;
00996                         }
00997                 }
00998         }
00999         
01000         float rot_angle = (float) (best_peak_index * 360.0f / polarxsize);
01001                                 
01002         //return the result
01003         Transform tmptt(Dict("type","2d","alpha",0,"tx",-best_tx,"ty",-best_ty));
01004         Transform tmprot(Dict("type","2d","alpha",rot_angle,"tx",0,"ty",0));
01005         Transform total = tmprot*tmptt;
01006         EMData * rotimg=this_img->process("xform",Dict("transform",(Transform*)&total));
01007         rotimg->set_attr("xform.align2d",&total);
01008         if(flip == true) {
01009                 rotimg->process_inplace("xform.flip",Dict("axis", "x"));
01010         }
01011         
01012         return rotimg;
01013         
01014 }

virtual string EMAN::RotateTranslateFlipAlignerPawel::get_desc  )  const [inline, virtual]
 

Implements EMAN::Aligner.

Definition at line 1054 of file aligner.h.

01055                 {
01056                         return "Performs rotational alignment, translation align, and flip by resampling to polar coordinates in real space.";
01057                 }

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.

01050                 {
01051                         return NAME;
01052                 }

virtual TypeDict EMAN::RotateTranslateFlipAlignerPawel::get_param_types  )  const [inline, virtual]
 

Implements EMAN::Aligner.

Definition at line 1064 of file aligner.h.

References EMAN::TypeDict::put().

01065                 {
01066                         TypeDict d;
01067                         //d.put("usedot", EMObject::INT);
01068                         d.put("tx", EMObject::INT, "Maximum x translation in pixels, Default = 0");
01069                         d.put("ty", EMObject::INT, "Maximum y translation in pixels, Default = 0");
01070                         d.put("r1", EMObject::INT, "Inner ring, pixels");
01071                         d.put("r2", EMObject::INT, "Outer ring, pixels");
01072                         return d;
01073                 }

Aligner* EMAN::RotateTranslateFlipAlignerPawel::NEW  )  [inline, static]
 

Definition at line 1059 of file aligner.h.

01060                 {
01061                         return new RotateTranslateFlipAlignerPawel();
01062                 }


Member Data Documentation

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

Definition at line 75 of file aligner.cpp.


The documentation for this class was generated from the following files:
Generated on Tue Jun 11 13:47:46 2013 for EMAN2 by  doxygen 1.3.9.1