#include <cmp.h>
Inheritance diagram for EMAN::LodCmp:
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 = "lod" |
|
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 179 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(), and EMAN::Cmp::validate_input_args(). 00180 { 00181 ENTERFUNC; 00182 if (image->is_complex() || with->is_complex()) 00183 throw ImageFormatException( "Complex images not yet supported by CMP::LodCmp"); 00184 validate_input_args(image, with); 00185 00186 const float *const d1 = image->get_const_data(); 00187 const float *const d2 = with->get_const_data(); 00188 00189 float negative = (float)params.set_default("negative", 1); 00190 if (negative) negative=-1.0; else negative=1.0; 00191 00192 double avg1 = 0.0, sig1 = 0.0, avg2 = 0.0, sig2 = 0.0, lod = 0.0; 00193 long n = 0; 00194 size_t totsize = image->get_xsize()*image->get_ysize()*image->get_zsize(); 00195 size_t i; 00196 00197 bool has_mask = false; 00198 EMData* mask = 0; 00199 if (params.has_key("mask")) { 00200 mask = params["mask"]; 00201 if(mask!=0) {has_mask=true;} 00202 } 00203 00204 int normalize = 0; 00205 if (params.has_key("normalize")) { 00206 normalize = params["normalize"]; 00207 } 00208 00209 if (normalize) { 00210 if (has_mask) { 00211 const float *const dm = mask->get_const_data(); 00212 for (i = 0; i < totsize; ++i) { 00213 if (dm[i] > 0.5) { 00214 avg1 += double(d1[i]); 00215 avg2 += double(d2[i]); 00216 n++; 00217 } 00218 } 00219 } else { 00220 for (i = 0; i < totsize; ++i) { 00221 avg1 += double(d1[i]); 00222 avg2 += double(d2[i]); 00223 } 00224 n = totsize; 00225 } 00226 00227 avg1 /= double(n); 00228 avg2 /= double(n); 00229 00230 if (has_mask) { 00231 const float *const dm = mask->get_const_data(); 00232 for (i = 0; i < totsize; ++i) { 00233 if (dm[i] > 0.5) { 00234 sig1 += fabs(double(d1[i])-avg1); 00235 sig2 += fabs(double(d2[i])-avg2); 00236 } 00237 } 00238 } else { 00239 for (i = 0; i < totsize; ++i) { 00240 sig1 += fabs(double(d1[i])-avg1); 00241 sig2 += fabs(double(d2[i])-avg2); 00242 } 00243 } 00244 } else { 00245 avg1 = 0.0; avg2 = 0.0; 00246 sig1 = 1.0; sig2 = 1.0; 00247 } 00248 00249 if (has_mask) { 00250 const float *const dm = mask->get_const_data(); 00251 for (i = 0; i < totsize; ++i) { 00252 if (dm[i] > 0.5) { 00253 lod += fabs((double(d1[i])-avg1)/sig1 - (double(d2[i])-avg2)/sig2); 00254 } 00255 } 00256 } else { 00257 for (i = 0; i < totsize; ++i) { 00258 lod += fabs((double(d1[i])-avg1)/sig1 - (double(d2[i])-avg2)/sig2); 00259 } 00260 } 00261 00262 lod *= (-0.5); 00263 lod *= negative; 00264 return static_cast<float>(lod); 00265 EXITFUNC; 00266 }
|
|
Implements EMAN::Cmp. Definition at line 200 of file cmp.h. 00201 { 00202 return "L^1 normalized difference (positive by default)"; 00203 }
|
|
Get the Cmp's name. Each Cmp is identified by a unique name.
Implements EMAN::Cmp. Definition at line 195 of file cmp.h. 00196 {
00197 return NAME;
00198 }
|
|
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 211 of file cmp.h. References EMAN::TypeDict::put(). 00212 { 00213 TypeDict d; 00214 d.put("negative", EMObject::INT, "If set (which is the default), returns Lod. (The smaller the better)"); 00215 d.put("normalize", EMObject::INT, "If set, normalizes maps prior to computing the difference. Default=0 (no normalization)"); 00216 d.put("mask", EMObject::EMDATA, "image mask"); 00217 return d; 00218 }
|
|
Definition at line 205 of file cmp.h. 00206 { 00207 return new LodCmp(); 00208 }
|
|
|