EMAN2
Public Member Functions | Static Public Member Functions | Static Public Attributes
EMAN::LodCmp Class Reference

#include <cmp.h>

Inheritance diagram for EMAN::LodCmp:
Inheritance graph
[legend]
Collaboration diagram for EMAN::LodCmp:
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 = "lod"

Detailed Description

Definition at line 190 of file cmp.h.


Member Function Documentation

float LodCmp::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 182 of file cmp.cpp.

References dm, ENTERFUNC, EXITFUNC, EMAN::EMData::get_const_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), EMAN::Dict::has_key(), ImageFormatException, EMAN::EMData::is_complex(), EMAN::Cmp::params, EMAN::Dict::set_default(), and EMAN::Cmp::validate_input_args().

{
        ENTERFUNC;
        if (image->is_complex() || with->is_complex())
                throw ImageFormatException( "Complex images not yet supported by CMP::LodCmp");
        validate_input_args(image, with);

        const float *const d1 = image->get_const_data();
        const float *const d2 = with->get_const_data();

        float negative = (float)params.set_default("negative", 1);
        if (negative) negative=-1.0; else negative=1.0;

        double avg1 = 0.0, sig1 = 0.0, avg2 = 0.0, sig2 = 0.0, lod = 0.0;
        long n = 0;
        size_t totsize = image->get_xsize()*image->get_ysize()*image->get_zsize();
        size_t i;
        
        bool has_mask = false;
        EMData* mask = 0;
        if (params.has_key("mask")) {
                mask = params["mask"];
                if(mask!=0) {has_mask=true;}
        }

        int normalize = 0;
        if (params.has_key("normalize")) {
                normalize = params["normalize"];
        }

        if (normalize) {
                if (has_mask) {
                        const float *const dm = mask->get_const_data();
                        for (i = 0; i < totsize; ++i) {
                                if (dm[i] > 0.5) {
                                        avg1 += double(d1[i]);
                                        avg2 += double(d2[i]);
                                        n++;
                                }
                        }
                } else {
                        for (i = 0; i < totsize; ++i) {
                                avg1 += double(d1[i]);
                                avg2 += double(d2[i]);
                        }
                        n = totsize;
                }

                avg1 /= double(n);
                avg2 /= double(n);

                if (has_mask) {
                        const float *const dm = mask->get_const_data();
                        for (i = 0; i < totsize; ++i) {
                                if (dm[i] > 0.5) {
                                        sig1 += fabs(double(d1[i])-avg1);
                                        sig2 += fabs(double(d2[i])-avg2);
                                }
                        }
                } else {
                        for (i = 0; i < totsize; ++i) {
                                sig1 += fabs(double(d1[i])-avg1);
                                sig2 += fabs(double(d2[i])-avg2);
                        }
                }
        } else {
                avg1 = 0.0; avg2 = 0.0;
                sig1 = 1.0; sig2 = 1.0;
        }

        if (has_mask) {
                const float *const dm = mask->get_const_data();
                for (i = 0; i < totsize; ++i) {
                        if (dm[i] > 0.5) {
                                lod += fabs((double(d1[i])-avg1)/sig1 - (double(d2[i])-avg2)/sig2);
                        }
                }
        } else {
                for (i = 0; i < totsize; ++i) {
                        lod += fabs((double(d1[i])-avg1)/sig1 - (double(d2[i])-avg2)/sig2);
                }
        }
        
        lod *= (-0.5);
        lod *= negative;
        return static_cast<float>(lod);
        EXITFUNC;
}
string EMAN::LodCmp::get_desc ( ) const [inline, virtual]

Implements EMAN::Cmp.

Definition at line 200 of file cmp.h.

                {
                        return "L^1 normalized difference (positive by default)";
                }
string EMAN::LodCmp::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 195 of file cmp.h.

References NAME.

                {
                        return NAME;
                }
TypeDict EMAN::LodCmp::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 211 of file cmp.h.

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

                {
                        TypeDict d;
                        d.put("negative", EMObject::INT, "If set (which is the default), returns Lod. (The smaller the better)");
                        d.put("normalize", EMObject::INT, "If set, normalizes maps prior to computing the difference. Default=0 (no normalization)");
                        d.put("mask", EMObject::EMDATA, "image mask");
                        return d;
                }
static Cmp* EMAN::LodCmp::NEW ( ) [inline, static]

Definition at line 205 of file cmp.h.

                {
                        return new LodCmp();
                }

Member Data Documentation

const string LodCmp::NAME = "lod" [static]

Definition at line 220 of file cmp.h.

Referenced by get_name().


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