EMAN2
Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
EMAN::QuadMinDotCmp Class Reference

This will calculate the dot product for each quadrant of the image and return the worst value. More...

#include <cmp.h>

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

Public Member Functions

float cmp (EMData *image, EMData *with) const
 To compare 'image' with another image passed in through its parameters. More...
 
string get_name () const
 Get the Cmp's name. More...
 
string get_desc () const
 
TypeDict get_param_types () const
 Get Cmp parameter information in a dictionary. More...
 
- Public Member Functions inherited from EMAN::Cmp
virtual ~Cmp ()
 
virtual Dict get_params () const
 Get the Cmp parameters in a key/value dictionary. More...
 
virtual void set_params (const Dict &new_params)
 Set the Cmp parameters using a key/value dictionary. More...
 

Static Public Member Functions

static CmpNEW ()
 

Static Public Attributes

static const string NAME = "quadmindot"
 

Additional Inherited Members

- Protected Member Functions inherited from EMAN::Cmp
void validate_input_args (const EMData *image, const EMData *with) const
 
- Protected Attributes inherited from EMAN::Cmp
Dict params
 

Detailed Description

This will calculate the dot product for each quadrant of the image and return the worst value.

Author
Steve Ludtke (sludt.nosp@m.ke@b.nosp@m.cm.tm.nosp@m.c.ed.nosp@m.u)
Date
2005-07-13
Parameters
negativeReturns -1 * dot product, default true
normalizeReturns normalized dot product -1.0 - 1.0

Definition at line 488 of file cmp.h.

Member Function Documentation

◆ cmp()

float QuadMinDotCmp::cmp ( EMData image,
EMData with 
) const
virtual

To compare 'image' with another image passed in through its parameters.

An optional transformation may be used to transform the 2 images.

Parameters
imageThe first image to be compared.
withThe second image to be comppared.
Returns
The comparison result. Smaller better by default

Implements EMAN::Cmp.

Definition at line 988 of file cmp.cpp.

989{
990 ENTERFUNC;
991 validate_input_args(image, with);
992
993 if (image->get_zsize()!=1) throw InvalidValueException(0, "QuadMinDotCmp supports 2D only");
994
995 int nx=image->get_xsize();
996 int ny=image->get_ysize();
997
998 int normalize = params.set_default("normalize", 0);
999 float negative = (float)params.set_default("negative", 1);
1000
1001 if (negative) negative=-1.0; else negative=1.0;
1002
1003 double result[4] = { 0,0,0,0 }, sq1[4] = { 0,0,0,0 }, sq2[4] = { 0,0,0,0 } ;
1004
1005 vector<int> image_saved_offsets = image->get_array_offsets();
1006 vector<int> with_saved_offsets = with->get_array_offsets();
1007 image->set_array_offsets(-nx/2,-ny/2);
1008 with->set_array_offsets(-nx/2,-ny/2);
1009 int i,x,y;
1010 for (y=-ny/2; y<ny/2; y++) {
1011 for (x=-nx/2; x<nx/2; x++) {
1012 int quad=(x<0?0:1) + (y<0?0:2);
1013 result[quad]+=(*image)(x,y)*(*with)(x,y);
1014 if (normalize) {
1015 sq1[quad]+=(*image)(x,y)*(*image)(x,y);
1016 sq2[quad]+=(*with)(x,y)*(*with)(x,y);
1017 }
1018 }
1019 }
1020 image->set_array_offsets(image_saved_offsets);
1021 with->set_array_offsets(with_saved_offsets);
1022
1023 if (normalize) {
1024 for (i=0; i<4; i++) result[i]/=sqrt(sq1[i]*sq2[i]);
1025 } else {
1026 for (i=0; i<4; i++) result[i]/=nx*ny/4;
1027 }
1028
1029 float worst=static_cast<float>(result[0]);
1030 for (i=1; i<4; i++) if (static_cast<float>(result[i])<worst) worst=static_cast<float>(result[i]);
1031
1032 EXITFUNC;
1033 return (float) (negative*worst);
1034}
void validate_input_args(const EMData *image, const EMData *with) const
Definition: cmp.cpp:81
Dict params
Definition: cmp.h:132
type set_default(const string &key, type val)
Default setting behavior This can be achieved using a template - d.woolford Jan 2008 (before there wa...
Definition: emobject.h:569
EMData * sqrt() const
return square root of current image
#define InvalidValueException(val, desc)
Definition: exception.h:285
#define ENTERFUNC
Definition: log.h:48
#define EXITFUNC
Definition: log.h:49
#define y(i, j)
Definition: projector.cpp:1516
#define x(i)
Definition: projector.cpp:1517

References ENTERFUNC, EXITFUNC, InvalidValueException, EMAN::Cmp::params, EMAN::Dict::set_default(), sqrt(), EMAN::Cmp::validate_input_args(), x, and y.

◆ get_desc()

string EMAN::QuadMinDotCmp::get_desc ( ) const
inlinevirtual

Implements EMAN::Cmp.

Definition at line 498 of file cmp.h.

499 {
500 return "Calculates dot product for each quadrant and returns worst value (default -1 * dot product)";
501 }

◆ get_name()

string EMAN::QuadMinDotCmp::get_name ( ) const
inlinevirtual

Get the Cmp's name.

Each Cmp is identified by a unique name.

Returns
The Cmp's name.

Implements EMAN::Cmp.

Definition at line 493 of file cmp.h.

494 {
495 return NAME;
496 }
static const string NAME
Definition: cmp.h:516

References NAME.

◆ get_param_types()

TypeDict EMAN::QuadMinDotCmp::get_param_types ( ) const
inlinevirtual

Get Cmp parameter information in a dictionary.

Each parameter has one record in the dictionary. Each record contains its name, data-type, and description.

Returns
A dictionary containing the parameter info.

Implements EMAN::Cmp.

Definition at line 508 of file cmp.h.

509 {
510 TypeDict d;
511 d.put("negative", EMObject::INT, "If set, returns -1 * dot product. Default = true (smaller is better)");
512 d.put("normalize", EMObject::INT, "If set, returns normalized dot product -1.0 - 1.0.");
513 return d;
514 }

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

◆ NEW()

static Cmp * EMAN::QuadMinDotCmp::NEW ( )
inlinestatic

Definition at line 503 of file cmp.h.

504 {
505 return new QuadMinDotCmp();
506 }

Member Data Documentation

◆ NAME

const string QuadMinDotCmp::NAME = "quadmindot"
static

Definition at line 516 of file cmp.h.

Referenced by get_name().


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