#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 153 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(). 00154 { 00155 ENTERFUNC; 00156 if (image->is_complex() || with->is_complex()) 00157 throw ImageFormatException( "Complex images not yet supported by CMP::LodCmp"); 00158 validate_input_args(image, with); 00159 00160 const float *const d1 = image->get_const_data(); 00161 const float *const d2 = with->get_const_data(); 00162 00163 float negative = (float)params.set_default("negative", 1); 00164 if (negative) negative=-1.0; else negative=1.0; 00165 00166 double avg1 = 0.0, sig1 = 0.0, avg2 = 0.0, sig2 = 0.0, lod = 0.0; 00167 long n = 0; 00168 size_t totsize = image->get_xsize()*image->get_ysize()*image->get_zsize(); 00169 size_t i; 00170 00171 bool has_mask = false; 00172 EMData* mask = 0; 00173 if (params.has_key("mask")) { 00174 mask = params["mask"]; 00175 if(mask!=0) {has_mask=true;} 00176 } 00177 00178 int normalize = 0; 00179 if (params.has_key("normalize")) { 00180 normalize = params["normalize"]; 00181 } 00182 00183 if (normalize) { 00184 if (has_mask) { 00185 const float *const dm = mask->get_const_data(); 00186 for (i = 0; i < totsize; ++i) { 00187 if (dm[i] > 0.5) { 00188 avg1 += double(d1[i]); 00189 avg2 += double(d2[i]); 00190 n++; 00191 } 00192 } 00193 } else { 00194 for (i = 0; i < totsize; ++i) { 00195 avg1 += double(d1[i]); 00196 avg2 += double(d2[i]); 00197 } 00198 n = totsize; 00199 } 00200 00201 avg1 /= double(n); 00202 avg2 /= double(n); 00203 00204 if (has_mask) { 00205 const float *const dm = mask->get_const_data(); 00206 for (i = 0; i < totsize; ++i) { 00207 if (dm[i] > 0.5) { 00208 sig1 += fabs(double(d1[i])-avg1); 00209 sig2 += fabs(double(d2[i])-avg2); 00210 } 00211 } 00212 } else { 00213 for (i = 0; i < totsize; ++i) { 00214 sig1 += fabs(double(d1[i])-avg1); 00215 sig2 += fabs(double(d2[i])-avg2); 00216 } 00217 } 00218 } else { 00219 avg1 = 0.0; avg2 = 0.0; 00220 sig1 = 1.0; sig2 = 1.0; 00221 } 00222 00223 if (has_mask) { 00224 const float *const dm = mask->get_const_data(); 00225 for (i = 0; i < totsize; ++i) { 00226 if (dm[i] > 0.5) { 00227 lod += fabs((double(d1[i])-avg1)/sig1 - (double(d2[i])-avg2)/sig2); 00228 } 00229 } 00230 } else { 00231 for (i = 0; i < totsize; ++i) { 00232 lod += fabs((double(d1[i])-avg1)/sig1 - (double(d2[i])-avg2)/sig2); 00233 } 00234 } 00235 00236 lod *= (-0.5); 00237 lod *= negative; 00238 return static_cast<float>(lod); 00239 EXITFUNC; 00240 }
|
|
Implements EMAN::Cmp. Definition at line 199 of file cmp.h. 00200 { 00201 return "L^1 normalized difference (positive by default)"; 00202 }
|
|
Get the Cmp's name. Each Cmp is identified by a unique name.
Implements EMAN::Cmp. Definition at line 194 of file cmp.h. 00195 {
00196 return NAME;
00197 }
|
|
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 210 of file cmp.h. References EMAN::TypeDict::put(). 00211 { 00212 TypeDict d; 00213 d.put("negative", EMObject::INT, "If set (which is the default), returns Lod. (The smaller the better)"); 00214 d.put("normalize", EMObject::INT, "If set, normalizes maps prior to computing the difference. Default=0 (no normalization)"); 00215 d.put("mask", EMObject::EMDATA, "image mask"); 00216 return d; 00217 }
|
|
Definition at line 204 of file cmp.h. 00205 { 00206 return new LodCmp(); 00207 }
|
|
|