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 87 of file averager.cpp.

Referenced by NEW().

00088         : norm_image(0)
00089 {
00090 
00091 }


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 93 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().

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

EMData * TomoAverager::finish (  )  [virtual]

Finish up the averaging and return the result.

Returns:
The averaged image.

Implements EMAN::Averager.

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

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

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 Thu Nov 17 12:45:16 2011 for EMAN2 by  doxygen 1.4.7