#include <cmp.h>


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 () |
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 79 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().
00080 { 00081 ENTERFUNC; 00082 if (image->is_complex() || with->is_complex()) 00083 throw ImageFormatException( "Complex images not supported by CMP::CccCmp"); 00084 validate_input_args(image, with); 00085 00086 const float *const d1 = image->get_const_data(); 00087 const float *const d2 = with->get_const_data(); 00088 00089 float negative = (float)params.set_default("negative", 1); 00090 if (negative) negative=-1.0; else negative=1.0; 00091 00092 double avg1 = 0.0, var1 = 0.0, avg2 = 0.0, var2 = 0.0, ccc = 0.0; 00093 long n = 0; 00094 size_t totsize = image->get_xsize()*image->get_ysize()*image->get_zsize(); 00095 00096 bool has_mask = false; 00097 EMData* mask = 0; 00098 if (params.has_key("mask")) { 00099 mask = params["mask"]; 00100 if(mask!=0) {has_mask=true;} 00101 } 00102 00103 if (has_mask) { 00104 const float *const dm = mask->get_const_data(); 00105 for (size_t i = 0; i < totsize; ++i) { 00106 if (dm[i] > 0.5) { 00107 avg1 += double(d1[i]); 00108 var1 += d1[i]*double(d1[i]); 00109 avg2 += double(d2[i]); 00110 var2 += d2[i]*double(d2[i]); 00111 ccc += d1[i]*double(d2[i]); 00112 n++; 00113 } 00114 } 00115 } else { 00116 for (size_t i = 0; i < totsize; ++i) { 00117 avg1 += double(d1[i]); 00118 var1 += d1[i]*double(d1[i]); 00119 avg2 += double(d2[i]); 00120 var2 += d2[i]*double(d2[i]); 00121 ccc += d1[i]*double(d2[i]); 00122 } 00123 n = totsize; 00124 } 00125 00126 avg1 /= double(n); 00127 var1 = var1/double(n) - avg1*avg1; 00128 avg2 /= double(n); 00129 var2 = var2/double(n) - avg2*avg2; 00130 ccc = ccc/double(n) - avg1*avg2; 00131 ccc /= sqrt(var1*var2); 00132 ccc *= negative; 00133 return static_cast<float>(ccc); 00134 EXITFUNC; 00135 }
| string EMAN::CccCmp::get_name | ( | ) | const [inline, virtual] |
| string EMAN::CccCmp::get_desc | ( | ) | const [inline, virtual] |
| static Cmp* EMAN::CccCmp::NEW | ( | ) | [inline, static] |
| 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 }
1.5.6