EMAN2
Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
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]

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 = "ccc"
 

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

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.nosp@m..goo.nosp@m.dyear.nosp@m.@uth.nosp@m..tmc..nosp@m.edu)
Date
2005-10-03
Parameters
negativeReturns -1 * ccc, default true

Definition at line 152 of file cmp.h.

Member Function Documentation

◆ cmp()

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 113 of file cmp.cpp.

114{
115 ENTERFUNC;
116 if (image==0 || with==0) throw ImageFormatException("NULL image provided to CCC cmp");
117 if (image->is_complex() || with->is_complex())
118 throw ImageFormatException( "Complex images not supported by CMP::CccCmp");
119 validate_input_args(image, with);
120
121 const float *const d1 = image->get_const_data();
122 const float *const d2 = with->get_const_data();
123
124 float negative = (float)params.set_default("negative", 1);
125 if (negative) negative=-1.0; else negative=1.0;
126
127 double avg1 = 0.0, var1 = 0.0, avg2 = 0.0, var2 = 0.0, ccc = 0.0;
128 long n = 0;
129 size_t totsize = image->get_xsize()*image->get_ysize()*image->get_zsize();
130
131 bool has_mask = false;
132 EMData* mask = 0;
133 if (params.has_key("mask")) {
134 mask = params["mask"];
135 if(mask!=0) {has_mask=true;}
136 }
137#ifdef EMAN2_USING_CUDA
138 if (image->getcudarwdata() && with->getcudarwdata()) {
139 //cout << "CUDA ccc cmp" << endl;
140 float* maskdata = 0;
141 if(has_mask && !mask->getcudarwdata()){
142 mask->copy_to_cuda();
143 maskdata = mask->getcudarwdata();
144 }
145 float ccc = ccc_cmp_cuda(image->getcudarwdata(), with->getcudarwdata(), maskdata, image->get_xsize(), image->get_ysize(), image->get_zsize());
146 ccc *= negative;
147 //cout << "CUDA CCC is: " << ccc << endl;
148 return ccc;
149 }
150#endif
151 if (has_mask) {
152 const float *const dm = mask->get_const_data();
153 for (size_t i = 0; i < totsize; ++i) {
154 if (dm[i] > 0.5) {
155 avg1 += double(d1[i]);
156 var1 += d1[i]*double(d1[i]);
157 avg2 += double(d2[i]);
158 var2 += d2[i]*double(d2[i]);
159 ccc += d1[i]*double(d2[i]);
160 n++;
161 }
162 }
163 } else {
164 for (size_t i = 0; i < totsize; ++i) {
165 avg1 += double(d1[i]);
166 var1 += d1[i]*double(d1[i]);
167 avg2 += double(d2[i]);
168 var2 += d2[i]*double(d2[i]);
169 ccc += d1[i]*double(d2[i]);
170 }
171 n = totsize;
172 }
173
174 avg1 /= double(n);
175 var1 = var1/double(n) - avg1*avg1;
176 avg2 /= double(n);
177 var2 = var2/double(n) - avg2*avg2;
178 ccc = ccc/double(n) - avg1*avg2;
179 ccc /= sqrt(var1*var2);
180 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
181 ccc *= negative;
182 return static_cast<float>(ccc);
183 EXITFUNC;
184}
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
bool has_key(const string &key) const
Ask the Dictionary if it as a particular key.
Definition: emobject.h:511
EMData stores an image's data and defines core image processing routines.
Definition: emdata.h:82
static int goodf(const float *p_f)
Check whether a number is a good float.
Definition: util.h:1112
float ccc_cmp_cuda(const float *data1, const float *data2, const float *dm, const int &nx, const int &ny, const int &nz)
EMData * sqrt() const
return square root of current image
#define ImageFormatException(desc)
Definition: exception.h:147
#define ENTERFUNC
Definition: log.h:48
#define EXITFUNC
Definition: log.h:49
#define dm(i)
Definition: projector.cpp:1606

References ccc_cmp_cuda(), dm, ENTERFUNC, EXITFUNC, EMAN::Util::goodf(), EMAN::Dict::has_key(), ImageFormatException, EMAN::Cmp::params, EMAN::Dict::set_default(), sqrt(), and EMAN::Cmp::validate_input_args().

◆ get_desc()

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

Implements EMAN::Cmp.

Definition at line 162 of file cmp.h.

163 {
164 return "Cross-correlation coefficient (default -1 * ccc)";
165 }

◆ get_name()

string EMAN::CccCmp::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 157 of file cmp.h.

158 {
159 return NAME;
160 }
static const string NAME
Definition: cmp.h:181

References NAME.

◆ get_param_types()

TypeDict EMAN::CccCmp::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 173 of file cmp.h.

174 {
175 TypeDict d;
176 d.put("negative", EMObject::INT, "If set, returns -1 * ccc product. Set by default so smaller is better");
177 d.put("mask", EMObject::EMDATA, "image mask");
178 return d;
179 }

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

◆ NEW()

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

Definition at line 167 of file cmp.h.

168 {
169 return new CccCmp();
170 }

Member Data Documentation

◆ NAME

const string CccCmp::NAME = "ccc"
static

Definition at line 181 of file cmp.h.

Referenced by get_name().


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