Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

EMAN::LodCmp Class Reference

#include <cmp.h>

Inheritance diagram for EMAN::LodCmp:

Inheritance graph
[legend]
Collaboration diagram for EMAN::LodCmp:

Collaboration graph
[legend]
List of all members.

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

CmpNEW ()

Static Public Attributes

const string NAME = "lod"

Member Function Documentation

float LodCmp::cmp EMData image,
EMData with
const [virtual]
 

To compare 'image' with another image passed in through its parameters.

An optional transformation may be used to transform the 2 images.

Parameters:
image The first image to be compared.
with The second image to be comppared.
Returns:
The comparison result. Smaller better by default

Implements EMAN::Cmp.

Definition at line 180 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().

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

string EMAN::LodCmp::get_desc  )  const [inline, virtual]
 

Implements EMAN::Cmp.

Definition at line 200 of file cmp.h.

00201                 {
00202                         return "L^1 normalized difference (positive by default)";
00203                 }

string EMAN::LodCmp::get_name  )  const [inline, virtual]
 

Get the Cmp's name.

Each Cmp is identified by a unique name.

Returns:
The Cmp's name.

Implements EMAN::Cmp.

Definition at line 195 of file cmp.h.

00196                 {
00197                         return NAME;
00198                 }

TypeDict EMAN::LodCmp::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.

Returns:
A dictionary containing the parameter info.

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                 }

Cmp* EMAN::LodCmp::NEW  )  [inline, static]
 

Definition at line 205 of file cmp.h.

00206                 {
00207                         return new LodCmp();
00208                 }


Member Data Documentation

const string LodCmp::NAME = "lod" [static]
 

Definition at line 48 of file cmp.cpp.


The documentation for this class was generated from the following files:
Generated on Tue Jun 11 13:41:56 2013 for EMAN2 by  doxygen 1.3.9.1