#include <cmp.h>
Inheritance diagram for EMAN::CccCmp:
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 Cmp * | NEW () |
Static Public Attributes | |
static const string | NAME = "ccc" |
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.
negative Returns -1 * ccc, default true
Definition at line 155 of file cmp.h.
To compare 'image' with another image passed in through its parameters.
An optional transformation may be used to transform the 2 images.
image | The first image to be compared. | |
with | The second image to be comppared. |
Implements EMAN::Cmp.
Definition at line 90 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(), sqrt(), and EMAN::Cmp::validate_input_args().
00091 { 00092 ENTERFUNC; 00093 if (image->is_complex() || with->is_complex()) 00094 throw ImageFormatException( "Complex images not supported by CMP::CccCmp"); 00095 validate_input_args(image, with); 00096 00097 const float *const d1 = image->get_const_data(); 00098 const float *const d2 = with->get_const_data(); 00099 00100 float negative = (float)params.set_default("negative", 1); 00101 if (negative) negative=-1.0; else negative=1.0; 00102 00103 double avg1 = 0.0, var1 = 0.0, avg2 = 0.0, var2 = 0.0, ccc = 0.0; 00104 long n = 0; 00105 size_t totsize = image->get_xsize()*image->get_ysize()*image->get_zsize(); 00106 00107 bool has_mask = false; 00108 EMData* mask = 0; 00109 if (params.has_key("mask")) { 00110 mask = params["mask"]; 00111 if(mask!=0) {has_mask=true;} 00112 } 00113 00114 if (has_mask) { 00115 const float *const dm = mask->get_const_data(); 00116 for (size_t i = 0; i < totsize; ++i) { 00117 if (dm[i] > 0.5) { 00118 avg1 += double(d1[i]); 00119 var1 += d1[i]*double(d1[i]); 00120 avg2 += double(d2[i]); 00121 var2 += d2[i]*double(d2[i]); 00122 ccc += d1[i]*double(d2[i]); 00123 n++; 00124 } 00125 } 00126 } else { 00127 for (size_t i = 0; i < totsize; ++i) { 00128 avg1 += double(d1[i]); 00129 var1 += d1[i]*double(d1[i]); 00130 avg2 += double(d2[i]); 00131 var2 += d2[i]*double(d2[i]); 00132 ccc += d1[i]*double(d2[i]); 00133 } 00134 n = totsize; 00135 } 00136 00137 avg1 /= double(n); 00138 var1 = var1/double(n) - avg1*avg1; 00139 avg2 /= double(n); 00140 var2 = var2/double(n) - avg2*avg2; 00141 ccc = ccc/double(n) - avg1*avg2; 00142 ccc /= sqrt(var1*var2); 00143 ccc *= negative; 00144 return static_cast<float>(ccc); 00145 EXITFUNC; 00146 }
string EMAN::CccCmp::get_desc | ( | ) | const [inline, virtual] |
string EMAN::CccCmp::get_name | ( | ) | const [inline, virtual] |
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.
Implements EMAN::Cmp.
Definition at line 176 of file cmp.h.
References EMAN::EMObject::EMDATA, EMAN::EMObject::INT, and EMAN::TypeDict::put().
00177 { 00178 TypeDict d; 00179 d.put("negative", EMObject::INT, "If set, returns -1 * ccc product. Set by default so smaller is better"); 00180 d.put("mask", EMObject::EMDATA, "image mask"); 00181 return d; 00182 }
static Cmp* EMAN::CccCmp::NEW | ( | ) | [inline, static] |
const string CccCmp::NAME = "ccc" [static] |