EMAN::TomoAverager Class Reference

TomoAverager averages a list of volumes in Fourier space. More...

#include <averager.h>

Inheritance diagram for EMAN::TomoAverager:

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

Collaboration graph
[legend]
List of all members.

Public Member Functions

 TomoAverager ()
void add_image (EMData *image)
 To add an image to the Averager.
EMDatafinish ()
 Finish up the averaging and return the result.
string get_name () const
 Get the Averager's name.
string get_desc () const
TypeDict get_param_types () const
 Get Averager parameter information in a dictionary.
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.

Static Public Member Functions

static AveragerNEW ()

Static Public Attributes

static const string NAME = "mean.tomo"

Private Attributes

EMDatanorm_image
float thresh_sigma

Detailed Description

TomoAverager averages a list of volumes in Fourier space.

It excludes values near zero from the average, assuming they are part of the missing-cone/wedge. A threshold

Parameters:
thresh_sigma a number, multiplied by the standard deviation of the image, below-which values are considered zero

Definition at line 216 of file averager.h.


Constructor & Destructor Documentation

TomoAverager::TomoAverager (  ) 

Definition at line 89 of file averager.cpp.

Referenced by NEW().

00090         : norm_image(0)
00091 {
00092 
00093 }


Member Function Documentation

void TomoAverager::add_image ( EMData image  )  [virtual]

To add an image to the Averager.

This image will be averaged in this function.

Parameters:
image The image to be averaged.

Implements EMAN::Averager.

Definition at line 95 of file averager.cpp.

References EMAN::EMData::copy_head(), data, EMAN::EMData::do_fft(), EMAN::EMData::get_data(), get_name(), EMAN::EMData::is_complex(), EMAN::EMUtil::is_same_size(), LOGERR, norm_image, nx, ny, EMAN::Averager::params, EMAN::Averager::result, EMAN::EMData::set_attr(), EMAN::Dict::set_default(), thresh_sigma, and EMAN::EMData::to_zero().

00096 {
00097         if (!image) {
00098                 return;
00099         }
00100 
00101         if (!image->is_complex()) {
00102                 image=image->do_fft();
00103                 image->set_attr("free_me",(int)1);
00104         }
00105                 
00106         if (result!=0 && !EMUtil::is_same_size(image, result)) {
00107                 LOGERR("%s Averager can only process same-size Images",
00108                            get_name().c_str());
00109                 return;
00110         }
00111 
00112         int nx = image->get_xsize();
00113         int ny = image->get_ysize();
00114         int nz = image->get_zsize();
00115         size_t image_size = (size_t)nx * ny * nz;
00116 
00117         if (norm_image == 0) {
00118                 printf("init average %d %d %d",nx,ny,nz);
00119                 result = image->copy_head();
00120                 result->to_zero();
00121                 
00122                 norm_image = image->copy_head();
00123                 norm_image->to_zero();
00124                 
00125                 thresh_sigma = (float)params.set_default("thresh_sigma", 0.01);
00126         }
00127 
00128         float *result_data = result->get_data();
00129         float *norm_data = norm_image->get_data();
00130         float *data = image->get_data();
00131         float thresh=image->get_attr("sigma");
00132         thresh=2.0f*thresh*thresh*thresh_sigma;
00133         
00134         // Add any values above threshold to the result image, and add 1 to the corresponding pixels in the norm image
00135         for (size_t j = 0; j < image_size; j+=2) {
00136                 float f=data[j];        // real
00137                 float g=data[j+1];      // imag
00138                 float inten=f*f+g*g;
00139                 
00140                 if (inten<thresh) continue;
00141                 
00142                 result_data[j]  +=f;
00143                 result_data[j+1]+=g;
00144                 
00145                 norm_data[j]  +=1.0;
00146                 norm_data[j+1]+=1.0;
00147         }
00148         
00149         if (image->has_attr("free_me")) delete image;
00150 }

EMData * TomoAverager::finish (  )  [virtual]

Finish up the averaging and return the result.

Returns:
The averaged image.

Implements EMAN::Averager.

Definition at line 152 of file averager.cpp.

References EMAN::EMData::do_ift(), EMAN::EMData::get_attr(), EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), norm_image, nx, ny, EMAN::Averager::params, EMAN::Averager::result, EMAN::EMData::set_attr(), EMAN::Dict::set_default(), EMAN::EMData::update(), and EMAN::EMData::write_image().

00153 {
00154         if (norm_image==0 || result==0) return NULL;
00155         
00156         int nx = result->get_xsize();
00157         int ny = result->get_ysize();
00158         int nz = result->get_zsize();
00159         size_t image_size = (size_t)nx * ny * nz;
00160         
00161         float *result_data = result->get_data();
00162         float *norm_data = norm_image->get_data();
00163         
00164         printf("finish average %d %d %d",nx,ny,nz);
00165         // normalize the average
00166         for (size_t j = 0; j < image_size; j++) {
00167                 if (norm_data[j]==0.0) result_data[j]=0.0;
00168                 else result_data[j]/=norm_data[j];
00169         }
00170         
00171         norm_image->update();
00172         result->update();
00173         
00174         EMData *ret = result->do_ift();
00175         ret->set_attr("ptcl_repr",norm_image->get_attr("maximum"));
00176         if ((int)params.set_default("save_norm", 0)) 
00177                 norm_image->write_image("norm.hdf");
00178         
00179         delete result;
00180         delete norm_image;
00181         result=0;
00182         norm_image=0;
00183         
00184         return ret;
00185 }

string EMAN::TomoAverager::get_desc (  )  const [inline, virtual]

Implements EMAN::Averager.

Definition at line 229 of file averager.h.

00230                 {
00231                         return "Average of volumes in Fourier space, excluding any pixels with near 0 intensity.";
00232                 }

string EMAN::TomoAverager::get_name (  )  const [inline, virtual]

Get the Averager's name.

Each Averager is identified by a unique name.

Returns:
The Averager's name.

Implements EMAN::Averager.

Definition at line 224 of file averager.h.

References NAME.

Referenced by add_image().

00225                 {
00226                         return NAME;
00227                 }

TypeDict EMAN::TomoAverager::get_param_types (  )  const [inline, virtual]

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 239 of file averager.h.

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

00240                 {
00241                         TypeDict d;
00242                         d.put("thresh_sigma", EMObject::FLOAT, "multiplied by the standard deviation of the image, below-which values are considered zero. Default = .01");
00243                         d.put("save_norm", EMObject::INT, "If set, will save the normalization volume as norm.hdf. Mainly for debugging purposes.");
00244                         return d;
00245                 }

virtual void EMAN::TomoAverager::mult ( const float &   )  [inline, virtual]

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:
s the scaling factor.
Exceptions:
NullPointerException if the EMData pointer (result) is NULL

Reimplemented from EMAN::Averager.

Definition at line 247 of file averager.h.

00247 { }

static Averager* EMAN::TomoAverager::NEW (  )  [inline, static]

Definition at line 234 of file averager.h.

References TomoAverager().

00235                 {
00236                         return new TomoAverager();
00237                 }


Member Data Documentation

const string TomoAverager::NAME = "mean.tomo" [static]

Definition at line 249 of file averager.h.

Referenced by get_name().

EMData* EMAN::TomoAverager::norm_image [private]

Definition at line 252 of file averager.h.

Referenced by add_image(), and finish().

float EMAN::TomoAverager::thresh_sigma [private]

Definition at line 253 of file averager.h.

Referenced by add_image().


The documentation for this class was generated from the following files:
Generated on Fri Aug 10 16:34:54 2012 for EMAN2 by  doxygen 1.4.7