#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 | |
Cmp * | NEW () |
Static Public Attributes | |
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.
Implements EMAN::Cmp. Definition at line 92 of file cmp.cpp. References dm, 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::Dict::set_default(), sqrt(), and EMAN::Cmp::validate_input_args(). 00093 { 00094 ENTERFUNC; 00095 if (image->is_complex() || with->is_complex()) 00096 throw ImageFormatException( "Complex images not supported by CMP::CccCmp"); 00097 validate_input_args(image, with); 00098 00099 const float *const d1 = image->get_const_data(); 00100 const float *const d2 = with->get_const_data(); 00101 00102 float negative = (float)params.set_default("negative", 1); 00103 if (negative) negative=-1.0; else negative=1.0; 00104 00105 double avg1 = 0.0, var1 = 0.0, avg2 = 0.0, var2 = 0.0, ccc = 0.0; 00106 long n = 0; 00107 size_t totsize = image->get_xsize()*image->get_ysize()*image->get_zsize(); 00108 00109 bool has_mask = false; 00110 EMData* mask = 0; 00111 if (params.has_key("mask")) { 00112 mask = params["mask"]; 00113 if(mask!=0) {has_mask=true;} 00114 } 00115 00116 if (has_mask) { 00117 const float *const dm = mask->get_const_data(); 00118 for (size_t i = 0; i < totsize; ++i) { 00119 if (dm[i] > 0.5) { 00120 avg1 += double(d1[i]); 00121 var1 += d1[i]*double(d1[i]); 00122 avg2 += double(d2[i]); 00123 var2 += d2[i]*double(d2[i]); 00124 ccc += d1[i]*double(d2[i]); 00125 n++; 00126 } 00127 } 00128 } else { 00129 for (size_t i = 0; i < totsize; ++i) { 00130 avg1 += double(d1[i]); 00131 var1 += d1[i]*double(d1[i]); 00132 avg2 += double(d2[i]); 00133 var2 += d2[i]*double(d2[i]); 00134 ccc += d1[i]*double(d2[i]); 00135 } 00136 n = totsize; 00137 } 00138 00139 avg1 /= double(n); 00140 var1 = var1/double(n) - avg1*avg1; 00141 avg2 /= double(n); 00142 var2 = var2/double(n) - avg2*avg2; 00143 ccc = ccc/double(n) - avg1*avg2; 00144 ccc /= sqrt(var1*var2); 00145 ccc *= negative; 00146 return static_cast<float>(ccc); 00147 EXITFUNC; 00148 }
|
|
Implements EMAN::Cmp. Definition at line 165 of file cmp.h. 00166 { 00167 return "Cross-correlation coefficient (default -1 * ccc)"; 00168 }
|
|
Get the Cmp's name. Each Cmp is identified by a unique name.
Implements EMAN::Cmp. Definition at line 160 of file cmp.h. 00161 {
00162 return NAME;
00163 }
|
|
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::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 }
|
|
Definition at line 170 of file cmp.h. 00171 { 00172 return new CccCmp(); 00173 }
|
|
|