EMAN2
Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Attributes
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_sigmaa number, multiplied by the standard deviation of the image, below-which values are considered zero

Definition at line 262 of file averager.h.


Constructor & Destructor Documentation

TomoAverager::TomoAverager ( )

Definition at line 84 of file averager.cpp.

Referenced by NEW().

        : norm_image(0)
{

}

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:
imageThe image to be averaged.

Implements EMAN::Averager.

Definition at line 90 of file averager.cpp.

References EMAN::EMData::copy_head(), data, EMAN::EMData::do_fft(), EMAN::EMObject::f, EMAN::EMData::get_attr(), EMAN::EMData::get_data(), get_name(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), EMAN::EMData::has_attr(), 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().

{
        if (!image) {
                return;
        }

        if (!image->is_complex()) {
                image=image->do_fft();
                image->set_attr("free_me",(int)1);
        }
                
        if (result!=0 && !EMUtil::is_same_size(image, result)) {
                LOGERR("%s Averager can only process same-size Images",
                           get_name().c_str());
                return;
        }

        int nx = image->get_xsize();
        int ny = image->get_ysize();
        int nz = image->get_zsize();
        size_t image_size = (size_t)nx * ny * nz;

        if (norm_image == 0) {
                printf("init average %d %d %d",nx,ny,nz);
                result = image->copy_head();
                result->to_zero();
                
                norm_image = image->copy_head();
                norm_image->to_zero();
                
                thresh_sigma = (float)params.set_default("thresh_sigma", 0.01);
        }

        float *result_data = result->get_data();
        float *norm_data = norm_image->get_data();
        float *data = image->get_data();
        float thresh=image->get_attr("sigma");
        thresh=2.0f*thresh*thresh*thresh_sigma;
        
        // Add any values above threshold to the result image, and add 1 to the corresponding pixels in the norm image
        for (size_t j = 0; j < image_size; j+=2) {
                float f=data[j];        // real
                float g=data[j+1];      // imag
                float inten=f*f+g*g;
                
                if (inten<thresh) continue;
                
                result_data[j]  +=f;
                result_data[j+1]+=g;
                
                norm_data[j]  +=1.0;
                norm_data[j+1]+=1.0;
        }
        
        if (image->has_attr("free_me")) delete image;
}
EMData * TomoAverager::finish ( ) [virtual]

Finish up the averaging and return the result.

Returns:
The averaged image.

Implements EMAN::Averager.

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

{
        if (norm_image==0 || result==0) return NULL;
        
        int nx = result->get_xsize();
        int ny = result->get_ysize();
        int nz = result->get_zsize();
        size_t image_size = (size_t)nx * ny * nz;
        
        float *result_data = result->get_data();
        float *norm_data = norm_image->get_data();
        
        printf("finish average %d %d %d",nx,ny,nz);
        // normalize the average
        for (size_t j = 0; j < image_size; j++) {
                if (norm_data[j]==0.0) result_data[j]=0.0;
                else result_data[j]/=norm_data[j];
        }
        
        norm_image->update();
        result->update();
        
        EMData *ret = result->do_ift();
        ret->set_attr("ptcl_repr",norm_image->get_attr("maximum"));
        if ((int)params.set_default("save_norm", 0)) 
                norm_image->write_image("norm.hdf");
        
        delete result;
        delete norm_image;
        result=0;
        norm_image=0;
        
        return ret;
}
string EMAN::TomoAverager::get_desc ( ) const [inline, virtual]

Implements EMAN::Averager.

Definition at line 275 of file averager.h.

                {
                        return "Average of volumes in Fourier space, excluding any pixels with near 0 intensity.";
                }
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 270 of file averager.h.

References NAME.

Referenced by add_image().

                {
                        return NAME;
                }
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 285 of file averager.h.

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

                {
                        TypeDict d;
                        d.put("thresh_sigma", EMObject::FLOAT, "multiplied by the standard deviation of the image, below-which values are considered zero. Default = .01");
                        d.put("save_norm", EMObject::INT, "If set, will save the normalization volume as norm.hdf. Mainly for debugging purposes.");
                        return d;
                }
virtual void EMAN::TomoAverager::mult ( const float &  s) [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:
sthe scaling factor.
Exceptions:
NullPointerExceptionif the EMData pointer (result) is NULL

Reimplemented from EMAN::Averager.

Definition at line 293 of file averager.h.

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

Definition at line 280 of file averager.h.

References TomoAverager().

                {
                        return new TomoAverager();
                }

Member Data Documentation

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

Definition at line 295 of file averager.h.

Referenced by get_name().

Definition at line 298 of file averager.h.

Referenced by add_image(), and finish().

Definition at line 299 of file averager.h.

Referenced by add_image().


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