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

ImageAverager averages a list of images. More...

#include <averager.h>

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

Public Member Functions

 MinMaxAverager ()
 
void add_image (EMData *image)
 To add an image to the Averager. More...
 
EMDatafinish ()
 Finish up the averaging and return the result. More...
 
string get_name () const
 Get the Averager's name. More...
 
string get_desc () const
 
TypeDict get_param_types () const
 Get Averager parameter information in a dictionary. More...
 
virtual void mult (const float &)
 Multiply the result image by some floating point constant This is useful when weighting the input images prior to calling add_image - a situation where it is likely you want to divide by the sum of the weights. More...
 
- Public Member Functions inherited from EMAN::Averager
 Averager ()
 
virtual ~Averager ()
 
virtual void add_image_list (const vector< EMData * > &images)
 To add multiple images to the Averager. More...
 
virtual void set_params (const Dict &new_params)
 Set the Averager parameters using a key/value dictionary. More...
 

Static Public Member Functions

static AveragerNEW ()
 

Static Public Attributes

static const string NAME = "minmax"
 

Private Attributes

int ismax
 
int isabs
 
int nimg
 

Additional Inherited Members

- Protected Attributes inherited from EMAN::Averager
Dict params
 
EMDataresult
 

Detailed Description

ImageAverager averages a list of images.

It optionally makes a sigma image.

Parameters
maxIf set, will find the max value, otherwise finds min

Definition at line 400 of file averager.h.

Constructor & Destructor Documentation

◆ MinMaxAverager()

MinMaxAverager::MinMaxAverager ( )

Definition at line 849 of file averager.cpp.

850 : nimg(0),ismax(0),isabs(0)
851{
852
853}

Referenced by NEW().

Member Function Documentation

◆ add_image()

void MinMaxAverager::add_image ( EMData image)
virtual

To add an image to the Averager.

This image will be averaged in this function.

Parameters
imageThe image to be averaged.

Reimplemented from EMAN::Averager.

Definition at line 855 of file averager.cpp.

856{
857 if (!image) {
858 return;
859 }
860
861 if (nimg >= 1 && !EMUtil::is_same_size(image, result)) {
862 LOGERR("%sAverager can only process same-size Image",
863 get_name().c_str());
864 return;
865 }
866 EMData *owner = params.set_default("owner", (EMData*)0);
867
868 float thisown = image->get_attr_default("ortid",(float)nimg);
869 nimg++;
870
871 size_t nxyz = image->get_size();
872
873 if (nimg == 1) {
874 result = image->copy();
875 if (owner) owner->to_value(thisown);
876 return;
877 }
878
879 float *rdata = result->get_data();
880 float *data = image->get_data();
881 float *owndata = 0;
882 if (owner) owndata=owner->get_data();
883
884 ismax=(int)params.set_default("max",0);
885 isabs=(int)params.set_default("abs",0);
886
887
888 for (size_t i=0; i<nxyz; i++) {
889 float v = isabs?fabs(data[i]):data[i];
890 float rv = isabs?fabs(rdata[i]):rdata[i];
891 if ((ismax && v>rv) || (!ismax && v<rv)) {
892 rdata[i]=data[i];
893 if (owndata) owndata[i]=thisown;
894 }
895 }
896
897}
#define rdata(i)
Definition: analyzer.cpp:592
EMData * result
Definition: averager.h:158
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
EMData stores an image's data and defines core image processing routines.
Definition: emdata.h:82
static bool is_same_size(const EMData *image1, const EMData *image2)
Check whether two EMData images are of the same size.
Definition: emutil.cpp:1224
string get_name() const
Get the Averager's name.
Definition: averager.h:408
#define LOGERR
Definition: log.h:51

References get_name(), EMAN::EMUtil::is_same_size(), isabs, ismax, LOGERR, nimg, EMAN::Averager::params, rdata, EMAN::Averager::result, and EMAN::Dict::set_default().

◆ finish()

EMData * MinMaxAverager::finish ( )
virtual

Finish up the averaging and return the result.

Returns
The averaged image.

Implements EMAN::Averager.

Definition at line 899 of file averager.cpp.

900{
901 result->update();
902 result->set_attr("ptcl_repr",nimg);
903
904 if (result && nimg >= 1) return result;
905
906 return NULL;
907}

References nimg, and EMAN::Averager::result.

◆ get_desc()

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

Implements EMAN::Averager.

Definition at line 413 of file averager.h.

414 {
415 return "Finds the minimum or maximum value in each pixel";
416 }

◆ get_name()

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

Get the Averager's name.

Each Averager is identified by a unique name.

Returns
The Averager's name.

Implements EMAN::Averager.

Definition at line 408 of file averager.h.

409 {
410 return NAME;
411 }
static const string NAME
Definition: averager.h:434

References NAME.

Referenced by add_image().

◆ get_param_types()

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

Get Averager 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.

Reimplemented from EMAN::Averager.

Definition at line 423 of file averager.h.

424 {
425 TypeDict d;
426 d.put("max", EMObject::INT, "If set, will find the max value, otherwise finds min");
427 d.put("abs", EMObject::INT, "If set, will find the value with the min or max absolute value. The actual value is preserved.");
428 d.put("owner", EMObject::EMDATA, "Contains the number of the input image which 'owns' the max/min value. Value will be insertion sequence number unless 'ortid' is set in each image being averaged.");
429 return d;
430 }

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

◆ mult()

virtual void EMAN::MinMaxAverager::mult ( const float &  s)
inlinevirtual

Multiply the result image by some floating point constant This is useful when weighting the input images prior to calling add_image - a situation where it is likely you want to divide by the sum of the weights.

Hence call mult after all of the weighted images have been added.

Parameters
sthe scaling factor.
Exceptions
NullPointerExceptionif the EMData pointer (result) is NULL

Reimplemented from EMAN::Averager.

Definition at line 432 of file averager.h.

432{ }

◆ NEW()

static Averager * EMAN::MinMaxAverager::NEW ( )
inlinestatic

Definition at line 418 of file averager.h.

419 {
420 return new MinMaxAverager();
421 }

References MinMaxAverager().

Member Data Documentation

◆ isabs

int EMAN::MinMaxAverager::isabs
private

Definition at line 438 of file averager.h.

Referenced by add_image().

◆ ismax

int EMAN::MinMaxAverager::ismax
private

Definition at line 437 of file averager.h.

Referenced by add_image().

◆ NAME

const string MinMaxAverager::NAME = "minmax"
static

Definition at line 434 of file averager.h.

Referenced by get_name().

◆ nimg

int EMAN::MinMaxAverager::nimg
private

Definition at line 439 of file averager.h.

Referenced by add_image(), and finish().


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