#include <cmp.h>
Inheritance diagram for EMAN::QuadMinDotCmp:
Public Member Functions | |
float | cmp (EMData *image, EMData *with) const |
To compare 'image' with another image passed in through its parameters. | |
string | get_name () const |
Get the Cmp's name. | |
string | get_desc () const |
TypeDict | get_param_types () const |
Get Cmp parameter information in a dictionary. | |
Static Public Member Functions | |
static Cmp * | NEW () |
Static Public Attributes | |
static const string | NAME = "quadmindot" |
negative | Returns -1 * dot product, default true | |
normalize | Returns normalized dot product -1.0 - 1.0 |
Definition at line 403 of file cmp.h.
To compare 'image' with another image passed in through its parameters.
An optional transformation may be used to transform the 2 images.
image | The first image to be compared. | |
with | The second image to be comppared. |
Implements EMAN::Cmp.
Definition at line 812 of file cmp.cpp.
References ENTERFUNC, EXITFUNC, EMAN::EMData::get_array_offsets(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), InvalidValueException, nx, ny, EMAN::Cmp::params, EMAN::EMData::set_array_offsets(), EMAN::Dict::set_default(), sqrt(), EMAN::Cmp::validate_input_args(), x, and y.
00813 { 00814 ENTERFUNC; 00815 validate_input_args(image, with); 00816 00817 if (image->get_zsize()!=1) throw InvalidValueException(0, "QuadMinDotCmp supports 2D only"); 00818 00819 int nx=image->get_xsize(); 00820 int ny=image->get_ysize(); 00821 00822 int normalize = params.set_default("normalize", 0); 00823 float negative = (float)params.set_default("negative", 1); 00824 00825 if (negative) negative=-1.0; else negative=1.0; 00826 00827 double result[4] = { 0,0,0,0 }, sq1[4] = { 0,0,0,0 }, sq2[4] = { 0,0,0,0 } ; 00828 00829 vector<int> image_saved_offsets = image->get_array_offsets(); 00830 vector<int> with_saved_offsets = with->get_array_offsets(); 00831 image->set_array_offsets(-nx/2,-ny/2); 00832 with->set_array_offsets(-nx/2,-ny/2); 00833 int i,x,y; 00834 for (y=-ny/2; y<ny/2; y++) { 00835 for (x=-nx/2; x<nx/2; x++) { 00836 int quad=(x<0?0:1) + (y<0?0:2); 00837 result[quad]+=(*image)(x,y)*(*with)(x,y); 00838 if (normalize) { 00839 sq1[quad]+=(*image)(x,y)*(*image)(x,y); 00840 sq2[quad]+=(*with)(x,y)*(*with)(x,y); 00841 } 00842 } 00843 } 00844 image->set_array_offsets(image_saved_offsets); 00845 with->set_array_offsets(with_saved_offsets); 00846 00847 if (normalize) { 00848 for (i=0; i<4; i++) result[i]/=sqrt(sq1[i]*sq2[i]); 00849 } else { 00850 for (i=0; i<4; i++) result[i]/=nx*ny/4; 00851 } 00852 00853 float worst=static_cast<float>(result[0]); 00854 for (i=1; i<4; i++) if (static_cast<float>(result[i])<worst) worst=static_cast<float>(result[i]); 00855 00856 EXITFUNC; 00857 return (float) (negative*worst); 00858 }
string EMAN::QuadMinDotCmp::get_desc | ( | ) | const [inline, virtual] |
string EMAN::QuadMinDotCmp::get_name | ( | ) | const [inline, virtual] |
TypeDict EMAN::QuadMinDotCmp::get_param_types | ( | ) | const [inline, virtual] |
Get Cmp parameter information in a dictionary.
Each parameter has one record in the dictionary. Each record contains its name, data-type, and description.
Implements EMAN::Cmp.
Definition at line 423 of file cmp.h.
References EMAN::EMObject::INT, and EMAN::TypeDict::put().
00424 { 00425 TypeDict d; 00426 d.put("negative", EMObject::INT, "If set, returns -1 * dot product. Default = true (smaller is better)"); 00427 d.put("normalize", EMObject::INT, "If set, returns normalized dot product -1.0 - 1.0."); 00428 return d; 00429 }
static Cmp* EMAN::QuadMinDotCmp::NEW | ( | ) | [inline, static] |
const string QuadMinDotCmp::NAME = "quadmindot" [static] |