Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

EMAN::CccCmp Class Reference
[a function or class that is CUDA enabled]

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

CmpNEW ()

Static Public Attributes

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:
negative Returns -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:
image The first image to be compared.
with The second image to be comppared.
Returns:
The comparison result. Smaller better by default

Implements EMAN::Cmp.

Definition at line 105 of file cmp.cpp.

References ccc_cmp_cuda(), dm, 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::Dict::set_default(), sqrt(), and EMAN::Cmp::validate_input_args().

00106 {
00107         ENTERFUNC;
00108         if (image->is_complex() || with->is_complex())
00109                 throw ImageFormatException( "Complex images not supported by CMP::CccCmp");
00110         validate_input_args(image, with);
00111 
00112         const float *const d1 = image->get_const_data();
00113         const float *const d2 = with->get_const_data();
00114 
00115         float negative = (float)params.set_default("negative", 1);
00116         if (negative) negative=-1.0; else negative=1.0;
00117 
00118         double avg1 = 0.0, var1 = 0.0, avg2 = 0.0, var2 = 0.0, ccc = 0.0;
00119         long n = 0;
00120         size_t totsize = image->get_xsize()*image->get_ysize()*image->get_zsize();
00121 
00122         bool has_mask = false;
00123         EMData* mask = 0;
00124         if (params.has_key("mask")) {
00125                 mask = params["mask"];
00126                 if(mask!=0) {has_mask=true;}
00127         }
00128 #ifdef EMAN2_USING_CUDA
00129         if (image->getcudarwdata() && with->getcudarwdata()) {
00130                 //cout << "CUDA ccc cmp" << endl;
00131                 float* maskdata = 0;
00132                 if(has_mask && !mask->getcudarwdata()){
00133                         mask->copy_to_cuda();
00134                         maskdata = mask->getcudarwdata();
00135                 }
00136                 float ccc = ccc_cmp_cuda(image->getcudarwdata(), with->getcudarwdata(), maskdata, image->get_xsize(), image->get_ysize(), image->get_zsize());
00137                 ccc *= negative;
00138                 //cout << "CUDA CCC is: " << ccc << endl;
00139                 return ccc;
00140         }
00141 #endif
00142         if (has_mask) {
00143                 const float *const dm = mask->get_const_data();
00144                 for (size_t i = 0; i < totsize; ++i) {
00145                         if (dm[i] > 0.5) {
00146                                 avg1 += double(d1[i]);
00147                                 var1 += d1[i]*double(d1[i]);
00148                                 avg2 += double(d2[i]);
00149                                 var2 += d2[i]*double(d2[i]);
00150                                 ccc += d1[i]*double(d2[i]);
00151                                 n++;
00152                         }
00153                 }
00154         } else {
00155                 for (size_t i = 0; i < totsize; ++i) {
00156                         avg1 += double(d1[i]);
00157                         var1 += d1[i]*double(d1[i]);
00158                         avg2 += double(d2[i]);
00159                         var2 += d2[i]*double(d2[i]);
00160                         ccc += d1[i]*double(d2[i]);
00161                 }
00162                 n = totsize;
00163         }
00164 
00165         avg1 /= double(n);
00166         var1 = var1/double(n) - avg1*avg1;
00167         avg2 /= double(n);
00168         var2 = var2/double(n) - avg2*avg2;
00169         ccc = ccc/double(n) - avg1*avg2;
00170         ccc /= sqrt(var1*var2);
00171         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
00172         ccc *= negative;
00173         return static_cast<float>(ccc);
00174         EXITFUNC;
00175 }

string EMAN::CccCmp::get_desc  )  const [inline, virtual]
 

Implements EMAN::Cmp.

Definition at line 166 of file cmp.h.

00167                 {
00168                         return "Cross-correlation coefficient (default -1 * ccc)";
00169                 }

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.

00162                 {
00163                         return NAME;
00164                 }

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::TypeDict::put().

00178                 {
00179                         TypeDict d;
00180                         d.put("negative", EMObject::INT, "If set, returns -1 * ccc product. Set by default so smaller is better");
00181                         d.put("mask", EMObject::EMDATA, "image mask");
00182                         return d;
00183                 }

Cmp* EMAN::CccCmp::NEW  )  [inline, static]
 

Definition at line 171 of file cmp.h.

00172                 {
00173                         return new CccCmp();
00174                 }


Member Data Documentation

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

Definition at line 47 of file cmp.cpp.


The documentation for this class was generated from the following files:
Generated on Tue Jun 11 13:41:55 2013 for EMAN2 by  doxygen 1.3.9.1