#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 178 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(). 00179 {
00180 ENTERFUNC;
00181 if (image->is_complex() || with->is_complex())
00182 throw ImageFormatException( "Complex images not yet supported by CMP::LodCmp");
00183 validate_input_args(image, with);
00184
00185 const float *const d1 = image->get_const_data();
00186 const float *const d2 = with->get_const_data();
00187
00188 float negative = (float)params.set_default("negative", 1);
00189 if (negative) negative=-1.0; else negative=1.0;
00190
00191 double avg1 = 0.0, sig1 = 0.0, avg2 = 0.0, sig2 = 0.0, lod = 0.0;
00192 long n = 0;
00193 size_t totsize = image->get_xsize()*image->get_ysize()*image->get_zsize();
00194 size_t i;
00195
00196 bool has_mask = false;
00197 EMData* mask = 0;
00198 if (params.has_key("mask")) {
00199 mask = params["mask"];
00200 if(mask!=0) {has_mask=true;}
00201 }
00202
00203 int normalize = 0;
00204 if (params.has_key("normalize")) {
00205 normalize = params["normalize"];
00206 }
00207
00208 if (normalize) {
00209 if (has_mask) {
00210 const float *const dm = mask->get_const_data();
00211 for (i = 0; i < totsize; ++i) {
00212 if (dm[i] > 0.5) {
00213 avg1 += double(d1[i]);
00214 avg2 += double(d2[i]);
00215 n++;
00216 }
00217 }
00218 } else {
00219 for (i = 0; i < totsize; ++i) {
00220 avg1 += double(d1[i]);
00221 avg2 += double(d2[i]);
00222 }
00223 n = totsize;
00224 }
00225
00226 avg1 /= double(n);
00227 avg2 /= double(n);
00228
00229 if (has_mask) {
00230 const float *const dm = mask->get_const_data();
00231 for (i = 0; i < totsize; ++i) {
00232 if (dm[i] > 0.5) {
00233 sig1 += fabs(double(d1[i])-avg1);
00234 sig2 += fabs(double(d2[i])-avg2);
00235 }
00236 }
00237 } else {
00238 for (i = 0; i < totsize; ++i) {
00239 sig1 += fabs(double(d1[i])-avg1);
00240 sig2 += fabs(double(d2[i])-avg2);
00241 }
00242 }
00243 } else {
00244 avg1 = 0.0; avg2 = 0.0;
00245 sig1 = 1.0; sig2 = 1.0;
00246 }
00247
00248 if (has_mask) {
00249 const float *const dm = mask->get_const_data();
00250 for (i = 0; i < totsize; ++i) {
00251 if (dm[i] > 0.5) {
00252 lod += fabs((double(d1[i])-avg1)/sig1 - (double(d2[i])-avg2)/sig2);
00253 }
00254 }
00255 } else {
00256 for (i = 0; i < totsize; ++i) {
00257 lod += fabs((double(d1[i])-avg1)/sig1 - (double(d2[i])-avg2)/sig2);
00258 }
00259 }
00260
00261 lod *= (-0.5);
00262 lod *= negative;
00263 return static_cast<float>(lod);
00264 EXITFUNC;
00265 }
|
|
|
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 }
|
|
|
|
1.3.9.1