#include <averager.h>
Inheritance diagram for EMAN::CtfCAutoAverager:
Public Member Functions | |
CtfCAutoAverager () | |
void | add_image (EMData *image) |
To add an image to the Averager. | |
EMData * | finish () |
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 Averager * | NEW () |
Static Public Attributes | |
static const string | NAME = "ctf.auto" |
Protected Attributes | |
EMData * | snrsum |
int | nimg |
The Weiner filter is estimated directly from the data.
Definition at line 426 of file averager.h.
CtfCAutoAverager::CtfCAutoAverager | ( | ) |
Definition at line 576 of file averager.cpp.
Referenced by NEW().
00577 : nimg(0) 00578 { 00579 00580 }
void CtfCAutoAverager::add_image | ( | EMData * | image | ) | [virtual] |
To add an image to the Averager.
This image will be averaged in this function.
image | The image to be averaged. |
Implements EMAN::Averager.
Definition at line 583 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::Averager::result, snrsum, and EMAN::EMData::to_zero().
00584 { 00585 if (!image) { 00586 return; 00587 } 00588 00589 00590 00591 EMData *fft=image->do_fft(); 00592 00593 if (nimg >= 1 && !EMUtil::is_same_size(fft, result)) { 00594 LOGERR("%s Averager can only process images of the same size", get_name().c_str()); 00595 return; 00596 } 00597 00598 nimg++; 00599 if (nimg == 1) { 00600 result = fft->copy_head(); 00601 result->to_zero(); 00602 } 00603 00604 Ctf *ctf = (Ctf *)image->get_attr("ctf"); 00605 float b=ctf->bfactor; 00606 ctf->bfactor=0; // NO B-FACTOR CORRECTION ! 00607 00608 EMData *snr = result -> copy(); 00609 ctf->compute_2d_complex(snr,Ctf::CTF_SNR); 00610 EMData *ctfi = result-> copy(); 00611 ctf->compute_2d_complex(ctfi,Ctf::CTF_AMP); 00612 00613 ctf->bfactor=b; // return to its original value 00614 00615 float *outd = result->get_data(); 00616 float *ind = fft->get_data(); 00617 float *snrd = snr->get_data(); 00618 float *ctfd = ctfi->get_data(); 00619 00620 size_t sz=snr->get_xsize()*snr->get_ysize(); 00621 for (size_t i = 0; i < sz; i+=2) { 00622 if (snrd[i]<0) snrd[i]=0; 00623 ctfd[i]=fabs(ctfd[i]); 00624 00625 // This limits the maximum possible amplification in CTF correction to 10x 00626 if (ctfd[i]<.05) { 00627 if (snrd[i]<=0) ctfd[i]=.05f; 00628 else ctfd[i]=snrd[i]*10.0f; 00629 } 00630 00631 // SNR weight and CTF correction 00632 outd[i]+=ind[i]*snrd[i]/ctfd[i]; 00633 outd[i+1]+=ind[i+1]*snrd[i]/ctfd[i]; 00634 } 00635 00636 if (nimg==1) { 00637 snrsum=snr->copy_head(); 00638 float *ssnrd=snrsum->get_data(); 00639 // we're only using the real component, for Wiener filter we put 1.0 in R, but for just SNR weight we use 0 00640 for (size_t i = 0; i < sz; i+=2) { ssnrd[i]=0.0; ssnrd[i+1]=0.0; } 00641 } 00642 snrsum->add(*snr); 00643 00644 delete ctf; 00645 delete fft; 00646 delete snr; 00647 delete ctfi; 00648 }
EMData * CtfCAutoAverager::finish | ( | ) | [virtual] |
Finish up the averaging and return the result.
Implements EMAN::Averager.
Definition at line 650 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, EMAN::Averager::result, EMAN::EMData::set_attr(), snrsum, and EMAN::EMData::update().
00651 { 00652 /* EMData *tmp=result->do_ift(); 00653 tmp->write_image("ctfcw.hdf",0); 00654 delete tmp; 00655 00656 tmp=snrsum->do_ift(); 00657 tmp->write_image("ctfcw.hdf",1); 00658 delete tmp;*/ 00659 00660 // snrsum->write_image("snrsum.hdf",-1); 00661 size_t sz=result->get_xsize()*result->get_ysize(); 00662 float *snrsd=snrsum->get_data(); 00663 float *outd=result->get_data(); 00664 00665 for (size_t i=0; i<sz; i+=2) { 00666 if (snrsd[i]==0) outd[i]=outd[i+1]=0; 00667 // we aren't wiener filtering, but if the total SNR is too low, we don't want TOO much exaggeration of noise 00668 if (snrsd[i]<.05) { 00669 outd[i]*=20.0; // 1/0.05 00670 outd[i+1]*=20.0; 00671 } 00672 else { 00673 outd[i]/=snrsd[i]; // snrsd contains total SNR 00674 outd[i+1]/=snrsd[i]; 00675 } 00676 } 00677 result->update(); 00678 result->set_attr("ptcl_repr",nimg); 00679 result->set_attr("ctf_snr_total",snrsum->calc_radial_dist(snrsum->get_ysize()/2,0,1,false)); 00680 result->set_attr("ctf_wiener_filtered",0); 00681 00682 /* snrsum->write_image("snr.hdf",-1); 00683 result->write_image("avg.hdf",-1);*/ 00684 00685 delete snrsum; 00686 EMData *ret=result->do_ift(); 00687 delete result; 00688 result=NULL; 00689 return ret; 00690 }
string EMAN::CtfCAutoAverager::get_desc | ( | ) | const [inline, virtual] |
Implements EMAN::Averager.
Definition at line 439 of file averager.h.
00440 { 00441 return "Averaging with automatic CTF correction and SNR weight. No B-factor correction (as this is best done in 3-D). Does not require a structure factor, but only works with EMAN2's CTF model"; 00442 }
string EMAN::CtfCAutoAverager::get_name | ( | ) | const [inline, virtual] |
Get the Averager's name.
Each Averager is identified by a unique name.
Implements EMAN::Averager.
Definition at line 434 of file averager.h.
References NAME.
Referenced by add_image().
00435 { 00436 return NAME; 00437 }
static Averager* EMAN::CtfCAutoAverager::NEW | ( | ) | [inline, static] |
Definition at line 444 of file averager.h.
References CtfCAutoAverager().
00445 { 00446 return new CtfCAutoAverager(); 00447 }
void EMAN::CtfCAutoAverager::set_params | ( | const Dict & | new_params | ) | [inline, virtual] |
Set the Averager parameters using a key/value dictionary.
new_params | A dictionary containing the new parameters. |
Reimplemented from EMAN::Averager.
Definition at line 449 of file averager.h.
References EMAN::Averager::params.
00450 { 00451 params = new_params; 00452 // outfile = params["outfile"]; 00453 }
const string CtfCAutoAverager::NAME = "ctf.auto" [static] |
int EMAN::CtfCAutoAverager::nimg [protected] |
EMData* EMAN::CtfCAutoAverager::snrsum [protected] |