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