#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 | |
| Cmp * | NEW () |
Static Public Attributes | |
| const string | NAME = "quadmindot" |
| negative | Returns -1 * dot product, default true | |
| normalize | Returns normalized dot product -1.0 - 1.0 |
Definition at line 359 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.
Implements EMAN::Cmp. Definition at line 685 of file cmp.cpp. References EMAN::EMData::get_array_offsets(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), InvalidValueException, nx, ny, EMAN::EMData::set_array_offsets(), EMAN::Dict::set_default(), sqrt(), EMAN::Cmp::validate_input_args(), x, and y. 00686 {
00687 ENTERFUNC;
00688 validate_input_args(image, with);
00689
00690 if (image->get_zsize()!=1) throw InvalidValueException(0, "QuadMinDotCmp supports 2D only");
00691
00692 int nx=image->get_xsize();
00693 int ny=image->get_ysize();
00694
00695 int normalize = params.set_default("normalize", 0);
00696 float negative = (float)params.set_default("negative", 1);
00697
00698 if (negative) negative=-1.0; else negative=1.0;
00699
00700 double result[4] = { 0,0,0,0 }, sq1[4] = { 0,0,0,0 }, sq2[4] = { 0,0,0,0 } ;
00701
00702 vector<int> image_saved_offsets = image->get_array_offsets();
00703 vector<int> with_saved_offsets = with->get_array_offsets();
00704 image->set_array_offsets(-nx/2,-ny/2);
00705 with->set_array_offsets(-nx/2,-ny/2);
00706 int i,x,y;
00707 for (y=-ny/2; y<ny/2; y++) {
00708 for (x=-nx/2; x<nx/2; x++) {
00709 int quad=(x<0?0:1) + (y<0?0:2);
00710 result[quad]+=(*image)(x,y)*(*with)(x,y);
00711 if (normalize) {
00712 sq1[quad]+=(*image)(x,y)*(*image)(x,y);
00713 sq2[quad]+=(*with)(x,y)*(*with)(x,y);
00714 }
00715 }
00716 }
00717 image->set_array_offsets(image_saved_offsets);
00718 with->set_array_offsets(with_saved_offsets);
00719
00720 if (normalize) {
00721 for (i=0; i<4; i++) result[i]/=sqrt(sq1[i]*sq2[i]);
00722 } else {
00723 for (i=0; i<4; i++) result[i]/=nx*ny/4;
00724 }
00725
00726 float worst=static_cast<float>(result[0]);
00727 for (i=1; i<4; i++) if (static_cast<float>(result[i])<worst) worst=static_cast<float>(result[i]);
00728
00729 EXITFUNC;
00730 return (float) (negative*worst);
00731 }
|
|
|
Implements EMAN::Cmp. Definition at line 369 of file cmp.h. 00370 {
00371 return "Caclultes dot product for each quadrant and returns worst value (default -1 * dot product)";
00372 }
|
|
|
Get the Cmp's name. Each Cmp is identified by a unique name.
Implements EMAN::Cmp. Definition at line 364 of file cmp.h. 00365 {
00366 return NAME;
00367 }
|
|
|
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 379 of file cmp.h. References EMAN::TypeDict::put(). 00380 {
00381 TypeDict d;
00382 d.put("negative", EMObject::INT, "If set, returns -1 * dot product. Default = true (smaller is better)");
00383 d.put("normalize", EMObject::INT, "If set, returns normalized dot product -1.0 - 1.0.");
00384 return d;
00385 }
|
|
|
Definition at line 374 of file cmp.h. 00375 {
00376 return new QuadMinDotCmp();
00377 }
|
|
|
|
1.3.9.1