#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 422 of file averager.h.
CtfCAutoAverager::CtfCAutoAverager | ( | ) |
Definition at line 835 of file averager.cpp.
Referenced by NEW().
00836 : nimg(0) 00837 { 00838 00839 }
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 842 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(), EMAN::Averager::result, snrsum, and EMAN::EMData::to_zero().
00843 { 00844 if (!image) { 00845 return; 00846 } 00847 00848 00849 00850 EMData *fft=image->do_fft(); 00851 00852 if (nimg >= 1 && !EMUtil::is_same_size(fft, result)) { 00853 LOGERR("%s Averager can only process images of the same size", get_name().c_str()); 00854 return; 00855 } 00856 00857 nimg++; 00858 if (nimg == 1) { 00859 result = fft->copy_head(); 00860 result->to_zero(); 00861 } 00862 00863 Ctf *ctf = (Ctf *)image->get_attr("ctf"); 00864 float b=ctf->bfactor; 00865 ctf->bfactor=0; // NO B-FACTOR CORRECTION ! 00866 00867 EMData *snr = result -> copy(); 00868 ctf->compute_2d_complex(snr,Ctf::CTF_SNR); 00869 EMData *ctfi = result-> copy(); 00870 ctf->compute_2d_complex(ctfi,Ctf::CTF_AMP); 00871 00872 ctf->bfactor=b; // return to its original value 00873 00874 float *outd = result->get_data(); 00875 float *ind = fft->get_data(); 00876 float *snrd = snr->get_data(); 00877 float *ctfd = ctfi->get_data(); 00878 00879 size_t sz=snr->get_xsize()*snr->get_ysize(); 00880 for (size_t i = 0; i < sz; i+=2) { 00881 if (snrd[i]<=0) snrd[i]=0.001; // used to be 0. Trying to insure that there is always at least a little signal used. In cases with dense particles, SNR may be dramatically underestimated 00882 ctfd[i]=fabs(ctfd[i]); 00883 00884 // This limits the maximum possible amplification in CTF correction to 10x 00885 if (ctfd[i]<.05) ctfd[i]=0.05f; 00886 // { 00887 // if (snrd[i]<=0) ctfd[i]=.05f; 00888 // else ctfd[i]=snrd[i]*10.0f; 00889 // } 00890 00891 // SNR weight and CTF correction 00892 outd[i]+=ind[i]*snrd[i]/ctfd[i]; 00893 outd[i+1]+=ind[i+1]*snrd[i]/ctfd[i]; 00894 } 00895 00896 if (nimg==1) { 00897 snrsum=snr->copy_head(); 00898 float *ssnrd=snrsum->get_data(); 00899 // we're only using the real component, for Wiener filter we put 1.0 in R, but for just SNR weight we use 0 00900 for (size_t i = 0; i < sz; i+=2) { ssnrd[i]=0.0; ssnrd[i+1]=0.0; } 00901 } 00902 snr->process_inplace("math.absvalue"); 00903 snrsum->add(*snr); 00904 00905 delete ctf; 00906 delete fft; 00907 delete snr; 00908 delete ctfi; 00909 }
EMData * CtfCAutoAverager::finish | ( | ) | [virtual] |
Finish up the averaging and return the result.
Implements EMAN::Averager.
Definition at line 911 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().
00912 { 00913 /* EMData *tmp=result->do_ift(); 00914 tmp->write_image("ctfcw.hdf",0); 00915 delete tmp; 00916 00917 tmp=snrsum->do_ift(); 00918 tmp->write_image("ctfcw.hdf",1); 00919 delete tmp;*/ 00920 00921 // snrsum->write_image("snrsum.hdf",-1); 00922 //size_t sz=result->get_xsize()*result->get_ysize(); 00923 int nx=result->get_xsize(); 00924 int ny=result->get_ysize(); 00925 float *snrsd=snrsum->get_data(); 00926 float *outd=result->get_data(); 00927 00928 int rm=(ny-2)*(ny-2)/4; 00929 for (int j=0; j<ny; j++) { 00930 for (int i=0; i<nx; i+=2) { 00931 size_t ii=i+j*nx; 00932 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; } 00933 // we aren't wiener filtering, but if the total SNR is too low, we don't want TOO much exaggeration of noise 00934 if (snrsd[ii]<.05) { 00935 outd[ii]*=20.0; // 1/0.05 00936 outd[ii+1]*=20.0; 00937 } 00938 else { 00939 outd[ii]/=snrsd[ii]; // snrsd contains total SNR 00940 outd[ii+1]/=snrsd[ii]; 00941 } 00942 } 00943 } 00944 result->update(); 00945 result->set_attr("ptcl_repr",nimg); 00946 result->set_attr("ctf_snr_total",snrsum->calc_radial_dist(snrsum->get_ysize()/2,0,1,false)); 00947 result->set_attr("ctf_wiener_filtered",0); 00948 00949 /* snrsum->write_image("snr.hdf",-1); 00950 result->write_image("avg.hdf",-1);*/ 00951 00952 delete snrsum; 00953 EMData *ret=result->do_ift(); 00954 delete result; 00955 result=NULL; 00956 return ret; 00957 }
string EMAN::CtfCAutoAverager::get_desc | ( | ) | const [inline, virtual] |
Implements EMAN::Averager.
Definition at line 435 of file averager.h.
00436 { 00437 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"; 00438 }
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 430 of file averager.h.
References NAME.
Referenced by add_image().
00431 { 00432 return NAME; 00433 }
static Averager* EMAN::CtfCAutoAverager::NEW | ( | ) | [inline, static] |
Definition at line 440 of file averager.h.
References CtfCAutoAverager().
00441 { 00442 return new CtfCAutoAverager(); 00443 }
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 445 of file averager.h.
References EMAN::Averager::params.
00446 { 00447 params = new_params; 00448 // outfile = params["outfile"]; 00449 }
const string CtfCAutoAverager::NAME = "ctf.auto" [static] |
int EMAN::CtfCAutoAverager::nimg [protected] |
EMData* EMAN::CtfCAutoAverager::snrsum [protected] |