EMAN2
Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
EMAN::LodCmp Class Reference

#include <cmp.h>

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

Public Member Functions

float cmp (EMData *image, EMData *with) const
 To compare 'image' with another image passed in through its parameters. More...
 
string get_name () const
 Get the Cmp's name. More...
 
string get_desc () const
 
TypeDict get_param_types () const
 Get Cmp parameter information in a dictionary. More...
 
- Public Member Functions inherited from EMAN::Cmp
virtual ~Cmp ()
 
virtual Dict get_params () const
 Get the Cmp parameters in a key/value dictionary. More...
 
virtual void set_params (const Dict &new_params)
 Set the Cmp parameters using a key/value dictionary. More...
 

Static Public Member Functions

static CmpNEW ()
 

Static Public Attributes

static const string NAME = "lod"
 

Additional Inherited Members

- Protected Member Functions inherited from EMAN::Cmp
void validate_input_args (const EMData *image, const EMData *with) const
 
- Protected Attributes inherited from EMAN::Cmp
Dict params
 

Detailed Description

Definition at line 186 of file cmp.h.

Member Function Documentation

◆ cmp()

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
imageThe first image to be compared.
withThe second image to be comppared.
Returns
The comparison result. Smaller better by default

Implements EMAN::Cmp.

Definition at line 189 of file cmp.cpp.

190{
191 ENTERFUNC;
192 if (image->is_complex() || with->is_complex())
193 throw ImageFormatException( "Complex images not yet supported by CMP::LodCmp");
194 validate_input_args(image, with);
195
196 const float *const d1 = image->get_const_data();
197 const float *const d2 = with->get_const_data();
198
199 float negative = (float)params.set_default("negative", 1);
200 if (negative) negative=-1.0; else negative=1.0;
201
202 double avg1 = 0.0, sig1 = 0.0, avg2 = 0.0, sig2 = 0.0, lod = 0.0;
203 long n = 0;
204 size_t totsize = image->get_xsize()*image->get_ysize()*image->get_zsize();
205 size_t i;
206
207 bool has_mask = false;
208 EMData* mask = 0;
209 if (params.has_key("mask")) {
210 mask = params["mask"];
211 if(mask!=0) {has_mask=true;}
212 }
213
214 int normalize = 0;
215 if (params.has_key("normalize")) {
216 normalize = params["normalize"];
217 }
218
219 if (normalize) {
220 if (has_mask) {
221 const float *const dm = mask->get_const_data();
222 for (i = 0; i < totsize; ++i) {
223 if (dm[i] > 0.5) {
224 avg1 += double(d1[i]);
225 avg2 += double(d2[i]);
226 n++;
227 }
228 }
229 } else {
230 for (i = 0; i < totsize; ++i) {
231 avg1 += double(d1[i]);
232 avg2 += double(d2[i]);
233 }
234 n = totsize;
235 }
236
237 avg1 /= double(n);
238 avg2 /= double(n);
239
240 if (has_mask) {
241 const float *const dm = mask->get_const_data();
242 for (i = 0; i < totsize; ++i) {
243 if (dm[i] > 0.5) {
244 sig1 += fabs(double(d1[i])-avg1);
245 sig2 += fabs(double(d2[i])-avg2);
246 }
247 }
248 } else {
249 for (i = 0; i < totsize; ++i) {
250 sig1 += fabs(double(d1[i])-avg1);
251 sig2 += fabs(double(d2[i])-avg2);
252 }
253 }
254 } else {
255 avg1 = 0.0; avg2 = 0.0;
256 sig1 = 1.0; sig2 = 1.0;
257 }
258
259 if (has_mask) {
260 const float *const dm = mask->get_const_data();
261 for (i = 0; i < totsize; ++i) {
262 if (dm[i] > 0.5) {
263 lod += fabs((double(d1[i])-avg1)/sig1 - (double(d2[i])-avg2)/sig2);
264 }
265 }
266 } else {
267 for (i = 0; i < totsize; ++i) {
268 lod += fabs((double(d1[i])-avg1)/sig1 - (double(d2[i])-avg2)/sig2);
269 }
270 }
271
272 lod *= (-0.5);
273 lod *= negative;
274 return static_cast<float>(lod);
275 EXITFUNC;
276}
void validate_input_args(const EMData *image, const EMData *with) const
Definition: cmp.cpp:81
Dict params
Definition: cmp.h:132
type set_default(const string &key, type val)
Default setting behavior This can be achieved using a template - d.woolford Jan 2008 (before there wa...
Definition: emobject.h:569
bool has_key(const string &key) const
Ask the Dictionary if it as a particular key.
Definition: emobject.h:511
EMData stores an image's data and defines core image processing routines.
Definition: emdata.h:82
#define ImageFormatException(desc)
Definition: exception.h:147
#define ENTERFUNC
Definition: log.h:48
#define EXITFUNC
Definition: log.h:49
#define dm(i)
Definition: projector.cpp:1606

References dm, ENTERFUNC, EXITFUNC, EMAN::Dict::has_key(), ImageFormatException, EMAN::Cmp::params, EMAN::Dict::set_default(), and EMAN::Cmp::validate_input_args().

◆ get_desc()

string EMAN::LodCmp::get_desc ( ) const
inlinevirtual

Implements EMAN::Cmp.

Definition at line 196 of file cmp.h.

197 {
198 return "L^1 normalized difference (positive by default)";
199 }

◆ get_name()

string EMAN::LodCmp::get_name ( ) const
inlinevirtual

Get the Cmp's name.

Each Cmp is identified by a unique name.

Returns
The Cmp's name.

Implements EMAN::Cmp.

Definition at line 191 of file cmp.h.

192 {
193 return NAME;
194 }
static const string NAME
Definition: cmp.h:216

References NAME.

◆ get_param_types()

TypeDict EMAN::LodCmp::get_param_types ( ) const
inlinevirtual

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 207 of file cmp.h.

208 {
209 TypeDict d;
210 d.put("negative", EMObject::INT, "If set (which is the default), returns Lod. (The smaller the better)");
211 d.put("normalize", EMObject::INT, "If set, normalizes maps prior to computing the difference. Default=0 (no normalization)");
212 d.put("mask", EMObject::EMDATA, "image mask");
213 return d;
214 }

References EMAN::EMObject::EMDATA, EMAN::EMObject::INT, and EMAN::TypeDict::put().

◆ NEW()

static Cmp * EMAN::LodCmp::NEW ( )
inlinestatic

Definition at line 201 of file cmp.h.

202 {
203 return new LodCmp();
204 }

Member Data Documentation

◆ NAME

const string LodCmp::NAME = "lod"
static

Definition at line 216 of file cmp.h.

Referenced by get_name().


The documentation for this class was generated from the following files: