EMAN2
Public Member Functions | Static Public Member Functions | Static Public Attributes
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]

List of all members.

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

Static Public Attributes

static const string NAME = "quadmindot"

Detailed Description

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

Author:
Steve Ludtke (sludtke@bcm.tmc.edu)
Date:
2005-07-13
Parameters:
negativeReturns -1 * dot product, default true
normalizeReturns normalized dot product -1.0 - 1.0

Definition at line 403 of file cmp.h.


Member Function Documentation

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 814 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.

{
        ENTERFUNC;
        validate_input_args(image, with);

        if (image->get_zsize()!=1) throw InvalidValueException(0, "QuadMinDotCmp supports 2D only");

        int nx=image->get_xsize();
        int ny=image->get_ysize();

        int normalize = params.set_default("normalize", 0);
        float negative = (float)params.set_default("negative", 1);

        if (negative) negative=-1.0; else negative=1.0;

        double result[4] = { 0,0,0,0 }, sq1[4] = { 0,0,0,0 }, sq2[4] = { 0,0,0,0 } ;

        vector<int> image_saved_offsets = image->get_array_offsets();
        vector<int> with_saved_offsets = with->get_array_offsets();
        image->set_array_offsets(-nx/2,-ny/2);
        with->set_array_offsets(-nx/2,-ny/2);
        int i,x,y;
        for (y=-ny/2; y<ny/2; y++) {
                for (x=-nx/2; x<nx/2; x++) {
                        int quad=(x<0?0:1) + (y<0?0:2);
                        result[quad]+=(*image)(x,y)*(*with)(x,y);
                        if (normalize) {
                                sq1[quad]+=(*image)(x,y)*(*image)(x,y);
                                sq2[quad]+=(*with)(x,y)*(*with)(x,y);
                        }
                }
        }
        image->set_array_offsets(image_saved_offsets);
        with->set_array_offsets(with_saved_offsets);

        if (normalize) {
                for (i=0; i<4; i++) result[i]/=sqrt(sq1[i]*sq2[i]);
        } else {
                for (i=0; i<4; i++) result[i]/=nx*ny/4;
        }

        float worst=static_cast<float>(result[0]);
        for (i=1; i<4; i++) if (static_cast<float>(result[i])<worst) worst=static_cast<float>(result[i]);

        EXITFUNC;
        return (float) (negative*worst);
}
string EMAN::QuadMinDotCmp::get_desc ( ) const [inline, virtual]

Implements EMAN::Cmp.

Definition at line 413 of file cmp.h.

                {
                        return "Calculates dot product for each quadrant and returns worst value (default -1 * dot product)";
                }
string EMAN::QuadMinDotCmp::get_name ( ) const [inline, virtual]

Get the Cmp's name.

Each Cmp is identified by a unique name.

Returns:
The Cmp's name.

Implements EMAN::Cmp.

Definition at line 408 of file cmp.h.

References NAME.

                {
                        return NAME;
                }
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.

Returns:
A dictionary containing the parameter info.

Implements EMAN::Cmp.

Definition at line 423 of file cmp.h.

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

                {
                        TypeDict d;
                        d.put("negative", EMObject::INT, "If set, returns -1 * dot product. Default = true (smaller is better)");
                        d.put("normalize", EMObject::INT, "If set, returns normalized dot product -1.0 - 1.0.");
                        return d;
                }
static Cmp* EMAN::QuadMinDotCmp::NEW ( ) [inline, static]

Definition at line 418 of file cmp.h.

                {
                        return new QuadMinDotCmp();
                }

Member Data Documentation

const string QuadMinDotCmp::NAME = "quadmindot" [static]

Definition at line 431 of file cmp.h.

Referenced by get_name().


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