#include <averager.h>
Inheritance diagram for EMAN::CtfCWautoAverager:
Public Member Functions | |
CtfCWautoAverager () | |
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 | |
Averager * | NEW () |
Static Public Attributes | |
const string | NAME = "ctfw.auto" |
Protected Attributes | |
EMData * | snrsum |
int | nimg |
The Weiner filter is estimated directly from the data.
Definition at line 465 of file averager.h.
|
Definition at line 479 of file averager.cpp. 00480 : nimg(0) 00481 { 00482 00483 }
|
|
To add an image to the Averager. This image will be averaged in this function.
Implements EMAN::Averager. Definition at line 486 of file averager.cpp. References EMAN::EMData::add(), b, EMAN::Ctf::bfactor, EMAN::Ctf::compute_2d_complex(), copy(), EMAN::EMData::copy_head(), 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(). 00487 { 00488 if (!image) { 00489 return; 00490 } 00491 00492 00493 00494 EMData *fft=image->do_fft(); 00495 00496 if (nimg >= 1 && !EMUtil::is_same_size(fft, result)) { 00497 LOGERR("%s Averager can only process images of the same size", get_name().c_str()); 00498 return; 00499 } 00500 00501 nimg++; 00502 if (nimg == 1) { 00503 result = fft->copy_head(); 00504 result->to_zero(); 00505 } 00506 00507 Ctf *ctf = (Ctf *)image->get_attr("ctf"); 00508 //string cc=ctf->to_string(); 00509 //FILE *out=fopen("ctf.txt","a"); 00510 //fprintf(out,"%s\n",cc.c_str()); 00511 //fclose(out); 00512 float b=ctf->bfactor; 00513 ctf->bfactor=100.0; // FIXME - this is a temporary fixed B-factor which does a (very) little sharpening 00514 00515 // if (nimg==1) unlink("snr.hdf"); 00516 00517 EMData *snr = result -> copy(); 00518 ctf->compute_2d_complex(snr,Ctf::CTF_SNR); 00519 // snr->write_image("snr.hdf",-1); 00520 EMData *ctfi = result-> copy(); 00521 ctf->compute_2d_complex(ctfi,Ctf::CTF_AMP); 00522 00523 ctf->bfactor=b; // return to its original value 00524 00525 float *outd = result->get_data(); 00526 float *ind = fft->get_data(); 00527 float *snrd = snr->get_data(); 00528 float *ctfd = ctfi->get_data(); 00529 00530 size_t sz=snr->get_xsize()*snr->get_ysize(); 00531 for (size_t i = 0; i < sz; i+=2) { 00532 if (snrd[i]<0) snrd[i]=0; 00533 ctfd[i]=fabs(ctfd[i]); 00534 if (ctfd[i]<.05) ctfd[i]=0.05f; 00535 // { 00536 // if (snrd[i]<=0) ctfd[i]=.05f; 00537 // else ctfd[i]=snrd[i]*10.0f; 00538 // } 00539 outd[i]+=ind[i]*snrd[i]/ctfd[i]; 00540 outd[i+1]+=ind[i+1]*snrd[i]/ctfd[i]; 00541 } 00542 00543 if (nimg==1) { 00544 snrsum=snr->copy_head(); 00545 float *ssnrd=snrsum->get_data(); 00546 // we're only using the real component, and we need to start with 1.0 00547 for (size_t i = 0; i < sz; i+=2) { ssnrd[i]=1.0; ssnrd[i+1]=0.0; } 00548 } 00549 // snr->write_image("snr.hdf",-1); 00550 snr->process_inplace("math.absvalue"); 00551 snrsum->add(*snr); 00552 00553 delete ctf; 00554 delete fft; 00555 delete snr; 00556 delete ctfi; 00557 }
|
|
Finish up the averaging and return the result.
Implements EMAN::Averager. Definition at line 559 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::EMData::set_attr(), snrsum, and EMAN::EMData::update(). 00560 { 00561 /* EMData *tmp=result->do_ift(); 00562 tmp->write_image("ctfcw.hdf",0); 00563 delete tmp; 00564 00565 tmp=snrsum->do_ift(); 00566 tmp->write_image("ctfcw.hdf",1); 00567 delete tmp;*/ 00568 00569 //snrsum->write_image("snrsum.hdf",-1); 00570 //size_t sz=result->get_xsize()*result->get_ysize(); 00571 int nx=result->get_xsize(); 00572 int ny=result->get_ysize(); 00573 float *snrsd=snrsum->get_data(); 00574 float *outd=result->get_data(); 00575 00576 int rm=(ny-2)*(ny-2)/4; 00577 for (int j=0; j<ny; j++) { 00578 for (int i=0; i<nx; i+=2) { 00579 size_t ii=i+j*nx; 00580 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; } 00581 outd[ii]/=snrsd[ii]; // snrsd contains total SNR 00582 outd[ii+1]/=snrsd[ii]; 00583 } 00584 } 00585 00586 result->update(); 00587 result->set_attr("ptcl_repr",nimg); 00588 result->set_attr("ctf_snr_total",snrsum->calc_radial_dist(snrsum->get_ysize()/2,0,1,false)); 00589 result->set_attr("ctf_wiener_filtered",1); 00590 00591 delete snrsum; 00592 EMData *ret=result->do_ift(); 00593 delete result; 00594 result=NULL; 00595 return ret; 00596 }
|
|
Implements EMAN::Averager. Definition at line 478 of file averager.h. 00479 { 00480 return "Averaging with autmatic CTF correction. Does not require a structure factor, but only works with EMAN2's CTF model"; 00481 }
|
|
Get the Averager's name. Each Averager is identified by a unique name.
Implements EMAN::Averager. Definition at line 473 of file averager.h. Referenced by add_image(). 00474 {
00475 return NAME;
00476 }
|
|
Definition at line 483 of file averager.h. 00484 { 00485 return new CtfCWautoAverager(); 00486 }
|
|
Set the Averager parameters using a key/value dictionary.
Reimplemented from EMAN::Averager. Definition at line 488 of file averager.h. 00489 { 00490 params = new_params; 00491 // outfile = params["outfile"]; 00492 }
|
|
Definition at line 51 of file averager.cpp. |
|
Definition at line 498 of file averager.h. Referenced by add_image(), and finish(). |
|
Definition at line 497 of file averager.h. Referenced by add_image(), and finish(). |