#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 512 of file averager.h.
CtfCAutoAverager::CtfCAutoAverager | ( | ) |
Definition at line 756 of file averager.cpp.
Referenced by NEW().
00757 : nimg(0) 00758 { 00759 00760 }
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 763 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().
00764 { 00765 if (!image) { 00766 return; 00767 } 00768 00769 00770 00771 EMData *fft=image->do_fft(); 00772 00773 if (nimg >= 1 && !EMUtil::is_same_size(fft, result)) { 00774 LOGERR("%s Averager can only process images of the same size", get_name().c_str()); 00775 return; 00776 } 00777 00778 nimg++; 00779 if (nimg == 1) { 00780 result = fft->copy_head(); 00781 result->to_zero(); 00782 } 00783 00784 Ctf *ctf = (Ctf *)image->get_attr("ctf"); 00785 float b=ctf->bfactor; 00786 ctf->bfactor=0; // NO B-FACTOR CORRECTION ! 00787 00788 EMData *snr = result -> copy(); 00789 ctf->compute_2d_complex(snr,Ctf::CTF_SNR); 00790 EMData *ctfi = result-> copy(); 00791 ctf->compute_2d_complex(ctfi,Ctf::CTF_AMP); 00792 00793 ctf->bfactor=b; // return to its original value 00794 00795 float *outd = result->get_data(); 00796 float *ind = fft->get_data(); 00797 float *snrd = snr->get_data(); 00798 float *ctfd = ctfi->get_data(); 00799 00800 size_t sz=snr->get_xsize()*snr->get_ysize(); 00801 for (size_t i = 0; i < sz; i+=2) { 00802 if (snrd[i]<0) snrd[i]=0; 00803 ctfd[i]=fabs(ctfd[i]); 00804 00805 // This limits the maximum possible amplification in CTF correction to 10x 00806 if (ctfd[i]<.05) ctfd[i]=0.05f; 00807 // { 00808 // if (snrd[i]<=0) ctfd[i]=.05f; 00809 // else ctfd[i]=snrd[i]*10.0f; 00810 // } 00811 00812 // SNR weight and CTF correction 00813 outd[i]+=ind[i]*snrd[i]/ctfd[i]; 00814 outd[i+1]+=ind[i+1]*snrd[i]/ctfd[i]; 00815 } 00816 00817 if (nimg==1) { 00818 snrsum=snr->copy_head(); 00819 float *ssnrd=snrsum->get_data(); 00820 // we're only using the real component, for Wiener filter we put 1.0 in R, but for just SNR weight we use 0 00821 for (size_t i = 0; i < sz; i+=2) { ssnrd[i]=0.0; ssnrd[i+1]=0.0; } 00822 } 00823 snr->process_inplace("math.absvalue"); 00824 snrsum->add(*snr); 00825 00826 delete ctf; 00827 delete fft; 00828 delete snr; 00829 delete ctfi; 00830 }
EMData * CtfCAutoAverager::finish | ( | ) | [virtual] |
Finish up the averaging and return the result.
Implements EMAN::Averager.
Definition at line 832 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().
00833 { 00834 /* EMData *tmp=result->do_ift(); 00835 tmp->write_image("ctfcw.hdf",0); 00836 delete tmp; 00837 00838 tmp=snrsum->do_ift(); 00839 tmp->write_image("ctfcw.hdf",1); 00840 delete tmp;*/ 00841 00842 // snrsum->write_image("snrsum.hdf",-1); 00843 //size_t sz=result->get_xsize()*result->get_ysize(); 00844 int nx=result->get_xsize(); 00845 int ny=result->get_ysize(); 00846 float *snrsd=snrsum->get_data(); 00847 float *outd=result->get_data(); 00848 00849 int rm=(ny-2)*(ny-2)/4; 00850 for (int j=0; j<ny; j++) { 00851 for (int i=0; i<nx; i+=2) { 00852 size_t ii=i+j*nx; 00853 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; } 00854 // we aren't wiener filtering, but if the total SNR is too low, we don't want TOO much exaggeration of noise 00855 if (snrsd[ii]<.05) { 00856 outd[ii]*=20.0; // 1/0.05 00857 outd[ii+1]*=20.0; 00858 } 00859 else { 00860 outd[ii]/=snrsd[ii]; // snrsd contains total SNR 00861 outd[ii+1]/=snrsd[ii]; 00862 } 00863 } 00864 } 00865 result->update(); 00866 result->set_attr("ptcl_repr",nimg); 00867 result->set_attr("ctf_snr_total",snrsum->calc_radial_dist(snrsum->get_ysize()/2,0,1,false)); 00868 result->set_attr("ctf_wiener_filtered",0); 00869 00870 /* snrsum->write_image("snr.hdf",-1); 00871 result->write_image("avg.hdf",-1);*/ 00872 00873 delete snrsum; 00874 EMData *ret=result->do_ift(); 00875 delete result; 00876 result=NULL; 00877 return ret; 00878 }
string EMAN::CtfCAutoAverager::get_desc | ( | ) | const [inline, virtual] |
Implements EMAN::Averager.
Definition at line 525 of file averager.h.
00526 { 00527 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"; 00528 }
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 520 of file averager.h.
References NAME.
Referenced by add_image().
00521 { 00522 return NAME; 00523 }
static Averager* EMAN::CtfCAutoAverager::NEW | ( | ) | [inline, static] |
Definition at line 530 of file averager.h.
References CtfCAutoAverager().
00531 { 00532 return new CtfCAutoAverager(); 00533 }
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 535 of file averager.h.
References EMAN::Averager::params.
00536 { 00537 params = new_params; 00538 // outfile = params["outfile"]; 00539 }
const string CtfCAutoAverager::NAME = "ctf.auto" [static] |
int EMAN::CtfCAutoAverager::nimg [protected] |
EMData* EMAN::CtfCAutoAverager::snrsum [protected] |