Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Attributes
EMAN::CtfCWautoAverager Class Reference

CtfCWautoAverager averages the images with CTF correction with a Wiener filter. More...

#include <averager.h>

Inheritance diagram for EMAN::CtfCWautoAverager:
Inheritance graph
Collaboration diagram for EMAN::CtfCWautoAverager:
Collaboration graph

List of all members.

Public Member Functions

 CtfCWautoAverager ()
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
void set_params (const Dict &new_params)
 Set the Averager parameters using a key/value dictionary.

Static Public Member Functions

static AveragerNEW ()

Static Public Attributes

static const string NAME = "ctfw.auto"

Protected Attributes

int nimg

Detailed Description

CtfCWautoAverager averages the images with CTF correction with a Wiener filter.

The Weiner filter is estimated directly from the data.

Definition at line 461 of file averager.h.

Constructor & Destructor Documentation

CtfCWautoAverager::CtfCWautoAverager ( )

Definition at line 716 of file averager.cpp.

Referenced by NEW().

        : nimg(0)


Member Function Documentation

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

To add an image to the Averager.

This image will be averaged in this function.

imageThe image to be averaged.

Implements EMAN::Averager.

Definition at line 723 of file averager.cpp.

References EMAN::EMData::add(), b, EMAN::Ctf::bfactor, EMAN::Ctf::compute_2d_complex(), copy(), EMAN::EMData::copy_head(), EMAN::Ctf::CTF_AMP, EMAN::Ctf::CTF_SNR, EMAN::EMData::do_fft(), EMAN::EMData::get_attr(), EMAN::EMData::get_data(), get_name(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMUtil::is_same_size(), LOGERR, nimg, EMAN::EMData::process_inplace(), snrsum, and EMAN::EMData::to_zero().

        if (!image) {

        EMData *fft=image->do_fft();

        if (nimg >= 1 && !EMUtil::is_same_size(fft, result)) {
                LOGERR("%s Averager can only process images of the same size", get_name().c_str());

        if (nimg == 1) {
                result = fft->copy_head();

        Ctf *ctf = (Ctf *)image->get_attr("ctf");
//string cc=ctf->to_string();
//FILE *out=fopen("ctf.txt","a");
        float b=ctf->bfactor;
        ctf->bfactor=100.0;                     // FIXME - this is a temporary fixed B-factor which does a (very) little sharpening

//      if (nimg==1) unlink("snr.hdf");

        EMData *snr = result -> copy();
//      snr->write_image("snr.hdf",-1);
        EMData *ctfi = result-> copy();

        ctf->bfactor=b; // return to its original value

        float *outd = result->get_data();
        float *ind = fft->get_data();
        float *snrd = snr->get_data();
        float *ctfd = ctfi->get_data();

        size_t sz=snr->get_xsize()*snr->get_ysize();
        for (size_t i = 0; i < sz; i+=2) {
                if (snrd[i]<0) snrd[i]=0.001;   // Used to be 0. See ctfcauto averager
                if (ctfd[i]<.05) ctfd[i]=0.05f;
//              {
//                      if (snrd[i]<=0) ctfd[i]=.05f;
//                      else ctfd[i]=snrd[i]*10.0f;
//              }

        if (nimg==1) {
                float *ssnrd=snrsum->get_data();
                // we're only using the real component, and we need to start with 1.0
                for (size_t i = 0; i < sz; i+=2) { ssnrd[i]=1.0; ssnrd[i+1]=0.0; }
//      snr->write_image("snr.hdf",-1);

        delete ctf;
        delete fft;
        delete snr;
        delete ctfi;
EMData * CtfCWautoAverager::finish ( ) [virtual]

Finish up the averaging and return the result.

The averaged image.

Implements EMAN::Averager.

Definition at line 796 of file averager.cpp.

References EMAN::EMData::calc_radial_dist(), EMAN::EMData::do_ift(), EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), nimg, nx, ny, EMAN::Averager::result, EMAN::EMData::set_attr(), snrsum, and EMAN::EMData::update().

/*      EMData *tmp=result->do_ift();
        delete tmp;

        delete tmp;*/

        //size_t sz=result->get_xsize()*result->get_ysize();
        int nx=result->get_xsize();
        int ny=result->get_ysize();     
        float *snrsd=snrsum->get_data();
        float *outd=result->get_data();

        int rm=(ny-2)*(ny-2)/4;
        for (int j=0; j<ny; j++) {
                for (int i=0; i<nx; i+=2) {
                        size_t ii=i+j*nx;
                        if ((j<ny/2 && i*i/4+j*j>rm) ||(j>=ny/2 && i*i/4+(ny-j)*(ny-j)>rm) || snrsd[ii]==0) { outd[ii]=outd[ii+1]=0; continue; }
                        outd[ii]/=snrsd[ii];            // snrsd contains total SNR

        delete snrsum;
        EMData *ret=result->do_ift();
        delete result;
        return ret;
string EMAN::CtfCWautoAverager::get_desc ( ) const [inline, virtual]

Implements EMAN::Averager.

Definition at line 474 of file averager.h.

                        return "Averaging with autmatic CTF correction. Does not require a structure factor, but only works with EMAN2's CTF model";
string EMAN::CtfCWautoAverager::get_name ( ) const [inline, virtual]

Get the Averager's name.

Each Averager is identified by a unique name.

The Averager's name.

Implements EMAN::Averager.

Definition at line 469 of file averager.h.

References NAME.

Referenced by add_image().

                        return NAME;
static Averager* EMAN::CtfCWautoAverager::NEW ( ) [inline, static]

Definition at line 479 of file averager.h.

References CtfCWautoAverager().

                        return new CtfCWautoAverager();
void EMAN::CtfCWautoAverager::set_params ( const Dict new_params) [inline, virtual]

Set the Averager parameters using a key/value dictionary.

new_paramsA dictionary containing the new parameters.

Reimplemented from EMAN::Averager.

Definition at line 484 of file averager.h.

References EMAN::Averager::params.

                        params = new_params;
//                      outfile = params["outfile"];

Member Data Documentation

const string CtfCWautoAverager::NAME = "ctfw.auto" [static]

Definition at line 490 of file averager.h.

Referenced by get_name().

Definition at line 494 of file averager.h.

Referenced by add_image(), and finish().

Definition at line 493 of file averager.h.

Referenced by add_image(), and finish().

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