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

Compute the cross-correlation coefficient between two images. More...

#include <cmp.h>

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

Detailed Description

Compute the cross-correlation coefficient between two images.

The cross-correlation coefficient is defined as: <AB> - CCC = ------------- sig(A)sig(B)

where the angle brackets denote averages and "sig" is the standard deviation. In the case of a mask, only pixels under the mask are included in the calculation of averages.

For complex images, this routine currently bails.

Author:
Grant Goodyear (grant.goodyear@uth.tmc.edu)
Date:
2005-10-03
Parameters:
negativeReturns -1 * ccc, default true

Definition at line 156 of file cmp.h.


Member Function Documentation

float CccCmp::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 107 of file cmp.cpp.

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

{
        ENTERFUNC;
        if (image->is_complex() || with->is_complex())
                throw ImageFormatException( "Complex images not supported by CMP::CccCmp");
        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, var1 = 0.0, avg2 = 0.0, var2 = 0.0, ccc = 0.0;
        long n = 0;
        size_t totsize = image->get_xsize()*image->get_ysize()*image->get_zsize();

        bool has_mask = false;
        EMData* mask = 0;
        if (params.has_key("mask")) {
                mask = params["mask"];
                if(mask!=0) {has_mask=true;}
        }
#ifdef EMAN2_USING_CUDA
        if (image->getcudarwdata() && with->getcudarwdata()) {
                //cout << "CUDA ccc cmp" << endl;
                float* maskdata = 0;
                if(has_mask && !mask->getcudarwdata()){
                        mask->copy_to_cuda();
                        maskdata = mask->getcudarwdata();
                }
                float ccc = ccc_cmp_cuda(image->getcudarwdata(), with->getcudarwdata(), maskdata, image->get_xsize(), image->get_ysize(), image->get_zsize());
                ccc *= negative;
                //cout << "CUDA CCC is: " << ccc << endl;
                return ccc;
        }
#endif
        if (has_mask) {
                const float *const dm = mask->get_const_data();
                for (size_t i = 0; i < totsize; ++i) {
                        if (dm[i] > 0.5) {
                                avg1 += double(d1[i]);
                                var1 += d1[i]*double(d1[i]);
                                avg2 += double(d2[i]);
                                var2 += d2[i]*double(d2[i]);
                                ccc += d1[i]*double(d2[i]);
                                n++;
                        }
                }
        } else {
                for (size_t i = 0; i < totsize; ++i) {
                        avg1 += double(d1[i]);
                        var1 += d1[i]*double(d1[i]);
                        avg2 += double(d2[i]);
                        var2 += d2[i]*double(d2[i]);
                        ccc += d1[i]*double(d2[i]);
                }
                n = totsize;
        }

        avg1 /= double(n);
        var1 = var1/double(n) - avg1*avg1;
        avg2 /= double(n);
        var2 = var2/double(n) - avg2*avg2;
        ccc = ccc/double(n) - avg1*avg2;
        ccc /= sqrt(var1*var2);
        if (!Util::goodf(&ccc)) ccc=-2.0;               // Steve - if one image was 0, this returned nan, which messes certain things up. -2.0 is out of range, and should serve as a proxy
        ccc *= negative;
        return static_cast<float>(ccc);
        EXITFUNC;
}
string EMAN::CccCmp::get_desc ( ) const [inline, virtual]

Implements EMAN::Cmp.

Definition at line 166 of file cmp.h.

                {
                        return "Cross-correlation coefficient (default -1 * ccc)";
                }
string EMAN::CccCmp::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 161 of file cmp.h.

References NAME.

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

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

                {
                        TypeDict d;
                        d.put("negative", EMObject::INT, "If set, returns -1 * ccc product. Set by default so smaller is better");
                        d.put("mask", EMObject::EMDATA, "image mask");
                        return d;
                }
static Cmp* EMAN::CccCmp::NEW ( ) [inline, static]

Definition at line 171 of file cmp.h.

                {
                        return new CccCmp();
                }

Member Data Documentation

const string CccCmp::NAME = "ccc" [static]

Definition at line 185 of file cmp.h.

Referenced by get_name().


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