EMAN2
Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Attributes
EMAN::FourierWeightAverager Class Reference

FourierWeightAverager makes an average of a set of images in Fourier space using a per-image radial weight. More...

#include <averager.h>

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

List of all members.

Public Member Functions

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

Static Public Member Functions

static AveragerNEW ()

Static Public Attributes

static const string NAME = "weightedfourier"

Private Attributes

EMDatanormimage
int freenorm
int nimg

Detailed Description

FourierWeightAverager makes an average of a set of images in Fourier space using a per-image radial weight.

The provided XYData object for each inserted image should range from x=0 - 0.5*sqrt(2), and contains the radial weights from 0 - Nyquist at the point. If the x range is insufficient, values will be clamped at the ends of the available x-range. 2-D Images only, but will work with rectangular images.

Parameters:
normimageAfter finish() will contain the sum of the weights in each Fourier location. Size must be ((nx+1)/2,y)

Definition at line 218 of file averager.h.


Constructor & Destructor Documentation

FourierWeightAverager::FourierWeightAverager ( )

Definition at line 302 of file averager.cpp.

Referenced by NEW().

        : normimage(0), freenorm(0), nimg(0)
{

}

Member Function Documentation

void FourierWeightAverager::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 308 of file averager.cpp.

References EMAN::EMData::do_fft(), freenorm, EMAN::EMData::get_attr(), EMAN::EMData::get_complex_at(), get_name(), EMAN::EMData::get_value_at(), EMAN::EMData::get_xsize(), EMAN::XYData::get_yatx(), EMAN::EMData::get_ysize(), EMAN::Util::hypot2(), EMAN::EMUtil::is_same_size(), LOGERR, nimg, normimage, nx, ny, EMAN::Averager::params, EMAN::Averager::result, EMAN::EMData::set_complex(), EMAN::EMData::set_complex_at(), EMAN::Dict::set_default(), EMAN::EMData::set_value_at(), EMAN::EMData::to_zero(), v, weight, x, and y.

{
        if (!image) {
                return;
        }



        EMData *img=image->do_fft();
        if (nimg >= 1 && !EMUtil::is_same_size(img, result)) {
                LOGERR("%sAverager can only process same-size Image",
                           get_name().c_str());
                return;
        }
        
        nimg++;

        int nx = img->get_xsize();
        int ny = img->get_ysize();
        int nz = 1;
//      size_t image_size = (size_t)nx * ny * nz;

        XYData *weight=(XYData *)image->get_attr("avg_weight");
        
        if (nimg == 1) {
                result = new EMData(nx,ny,nz);
                result->set_complex(true);
                result->to_zero();

                normimage = params.set_default("normimage", (EMData*)0);
                if (normimage==0) { normimage=new EMData(nx/2,ny,nz); freenorm=1; }
                normimage->to_zero();
        }

        // We're using routines that handle complex image wraparound for us, so we iterate over the half-plane
        for (int y=-ny/2; y<ny/2; y++) {
                for (int x=0; x<nx/2; x++) {
                        std::complex<float> v=img->get_complex_at(x,y);
                        float r=Util::hypot2(y/(float)ny,x/(float)nx);
                        float wt=weight->get_yatx(r);
                        result->set_complex_at(x,y,result->get_complex_at(x,y)+v*wt);
                        normimage->set_value_at(x,y+ny/2,normimage->get_value_at(x,y+ny/2)+wt);
                }
        }

        delete img;
}
EMData * FourierWeightAverager::finish ( ) [virtual]

Finish up the averaging and return the result.

Returns:
The averaged image.

Implements EMAN::Averager.

Definition at line 356 of file averager.cpp.

References EMAN::EMData::do_ift(), freenorm, EMAN::EMData::get_complex_at(), EMAN::EMData::get_value_at(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), nimg, norm(), normimage, nx, ny, EMAN::Averager::result, EMAN::EMData::set_attr(), EMAN::EMData::set_complex_at(), EMAN::EMData::update(), x, and y.

{
        EMData *ret = (EMData *)0;
        
        if (result && nimg >= 1) {
        // We're using routines that handle complex image wraparound for us, so we iterate over the half-plane
                int nx = result->get_xsize();
                int ny = result->get_ysize();
                
                for (int y=-ny/2; y<ny/2; y++) {
                        for (int x=0; x<nx/2; x++) {
                                float norm=normimage->get_value_at(x,y+ny/2);
                                if (norm<=0) result->set_complex_at(x,y,0.0f);
                                else result->set_complex_at(x,y,result->get_complex_at(x,y)/norm);
                        }
                }

                result->update();
//              result->mult(1.0f/(float)result->get_attr("sigma"));
//              result->write_image("tmp.hdf",0);
//              printf("%g %g %g\n",(float)result->get_attr("sigma"),(float)result->get_attr("minimum"),(float)result->get_attr("maximum"));
                ret=result->do_ift();
                delete result;
                result=(EMData*) 0;
        }
        ret->set_attr("ptcl_repr",nimg);

        if (freenorm) { delete normimage; normimage=(EMData*)0; }
        nimg=0;

        return ret;
}
string EMAN::FourierWeightAverager::get_desc ( ) const [inline, virtual]

Implements EMAN::Averager.

Definition at line 231 of file averager.h.

                {
                        return "Weighted mean of images in Fourier space. Each image must have weighting curve in its header, an XYData object called 'avg_weight'.";
                }
string EMAN::FourierWeightAverager::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 226 of file averager.h.

References NAME.

Referenced by add_image().

                {
                        return NAME;
                }
TypeDict EMAN::FourierWeightAverager::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 241 of file averager.h.

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

                {
                        TypeDict d;
//                      d.put("weight", EMObject::XYDATA, "Radial weight. X: 0 - 0.5*sqrt(2). Y contains weights.");
                        d.put("normimage", EMObject::EMDATA, "After finish() will contain the sum of the weights in each Fourier location. Size must be ((nx+1)/2,y)");
                        return d;
                }
static Averager* EMAN::FourierWeightAverager::NEW ( ) [inline, static]

Definition at line 236 of file averager.h.

References FourierWeightAverager().

                {
                        return new FourierWeightAverager();
                }

Member Data Documentation

Definition at line 253 of file averager.h.

Referenced by add_image(), and finish().

const string FourierWeightAverager::NAME = "weightedfourier" [static]

Definition at line 249 of file averager.h.

Referenced by get_name().

Definition at line 254 of file averager.h.

Referenced by add_image(), and finish().

Definition at line 252 of file averager.h.

Referenced by add_image(), and finish().


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