#include <processor.h>
Inheritance diagram for EMAN::CTFSNRWeightProcessor:
Public Member Functions | |
virtual void | process_inplace (EMData *image) |
To process an image in-place. | |
virtual string | get_name () const |
Get the processor's name. | |
virtual string | get_desc () const |
Get the descrition of this specific processor. | |
virtual TypeDict | get_param_types () const |
Get processor parameter information in a dictionary. | |
Static Public Member Functions | |
static Processor * | NEW () |
Static Public Attributes | |
static const string | NAME = "ctf.snr.weight" |
Definition at line 5974 of file processor.h.
virtual string EMAN::CTFSNRWeightProcessor::get_desc | ( | ) | const [inline, virtual] |
Get the descrition of this specific processor.
This function must be overwritten by a subclass.
Implements EMAN::Processor.
Definition at line 5984 of file processor.h.
05985 { 05986 return "Weight the amplitudes of an image based on radial noise and snr curves "; 05987 }
virtual string EMAN::CTFSNRWeightProcessor::get_name | ( | ) | const [inline, virtual] |
Get the processor's name.
Each processor is identified by a unique name.
Implements EMAN::Processor.
Definition at line 5979 of file processor.h.
References NAME.
05980 { 05981 return NAME; 05982 }
virtual TypeDict EMAN::CTFSNRWeightProcessor::get_param_types | ( | ) | const [inline, virtual] |
Get processor parameter information in a dictionary.
Each parameter has one record in the dictionary. Each record contains its name, data-type, and description.
Reimplemented from EMAN::Processor.
Definition at line 5994 of file processor.h.
References EMAN::EMObject::FLOAT, EMAN::EMObject::FLOATARRAY, and EMAN::TypeDict::put().
05995 { 05996 TypeDict d; 05997 d.put("noise", EMObject::FLOATARRAY, "The noise profile, squared amplitude. As in, what is the EMAN2CTF.background attribute"); 05998 d.put("snr", EMObject::FLOATARRAY, "Squared amplitude divided by squared noise amplitude. As in, what is the EMAN2CTF.snr attribute"); 05999 d.put("boost", EMObject::FLOAT, "Multiplicative signal boost"); 06000 return d; 06001 }
static Processor* EMAN::CTFSNRWeightProcessor::NEW | ( | ) | [inline, static] |
Definition at line 5989 of file processor.h.
05990 { 05991 return new CTFSNRWeightProcessor(); 05992 }
void CTFSNRWeightProcessor::process_inplace | ( | EMData * | image | ) | [virtual] |
To process an image in-place.
For those processors which can only be processed out-of-place, override this function to just print out some error message to remind user call the out-of-place version.
image | The image to be processed. |
Implements EMAN::Processor.
Definition at line 6966 of file processor.cpp.
References EMAN::EMData::ap2ri(), EMAN::EMData::calc_radial_dist(), EMAN::EMData::copy(), EMAN::EMData::depad(), EMAN::EMData::do_fft_inplace(), EMAN::EMData::do_ift_inplace(), EMAN::EMData::get_data(), EMAN::EMData::get_ndim(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), EMAN::Dict::has_key(), InvalidParameterException, EMAN::EMData::is_complex(), EMAN::length(), EMAN::Processor::params, EMAN::EMData::process_inplace(), EMAN::EMData::ri2ap(), EMAN::EMData::ri2inten(), EMAN::Dict::set_default(), sqrt(), and x.
06966 { 06967 if (params.has_key("noise")==false) throw InvalidParameterException("You must supply the noise argument"); 06968 if (params.has_key("snr")==false) throw InvalidParameterException("You must supply the snr argument"); 06969 06970 float boost = params.set_default("boost",1.0f); 06971 06972 if (!image->is_complex()) { 06973 image->do_fft_inplace(); 06974 } 06975 EMData* cpy = image->copy(); 06976 cpy->ri2inten(); 06977 vector<float> sf = cpy->calc_radial_dist(cpy->get_ysize()/2,0.0,1.0,1); 06978 transform(sf.begin(),sf.end(),sf.begin(),sqrtf); 06979 delete cpy; 06980 06981 image->ri2ap(); 06982 06983 vector<float> noise = params["noise"]; 06984 vector<float> snr = params["snr"]; 06985 06986 // copy(snr.begin(), snr.end(), ostream_iterator<float>(cout, "\n")); 06987 // copy(noise.begin(), noise.end(), ostream_iterator<float>(cout, "\n")); 06988 06989 for(vector<float>::iterator it = noise.begin(); it != noise.end(); ++it){ 06990 if ((*it) == 0) *it = 1; 06991 } 06992 for(vector<float>::iterator it = snr.begin(); it != snr.end(); ++it){ 06993 if ((*it) < 0) *it = 0; 06994 } 06995 // Subtract the mean from the data and store it in data_mm 06996 transform(snr.begin(),snr.end(),noise.begin(),snr.begin(),std::multiplies<float>()); 06997 transform(snr.begin(),snr.end(),snr.begin(),sqrtf); 06998 // copy(snr.begin(), snr.end(), ostream_iterator<float>(cout, "\n")); 06999 // copy(noise.begin(), noise.end(), ostream_iterator<float>(cout, "\n")); 07000 07001 int i = static_cast<int>(snr.size()); 07002 07003 float * d = image->get_data(); 07004 int nx = image->get_xsize(); 07005 // int ny = image->get_ysize(); 07006 int nxy = image->get_ysize()*nx; 07007 int nzon2 = image->get_zsize()/2; 07008 int nyon2 = image->get_ysize()/2; 07009 float rx, ry, rz, amp; 07010 int length; 07011 int twox; 07012 image->process_inplace("xform.fourierorigin.tocenter"); 07013 for (int z = 0; z< image->get_zsize(); ++z) { 07014 for (int y = 0; y < image->get_ysize(); ++y) { 07015 for (int x = 0; x < image->get_xsize()/2; ++x) { 07016 rx = (float)x; 07017 ry = (float)nyon2 - (float)y; 07018 rz = (float)nzon2 - (float)z; 07019 length = static_cast<int>(sqrt(rx*rx + ry*ry + rz*rz)); 07020 07021 twox = 2*x; 07022 size_t idx1 = twox + y*nx+(size_t)z*nxy; 07023 if (length >= i || length >= (int)sf.size()) { 07024 d[idx1] = 0; 07025 continue; 07026 } else { 07027 amp = boost*snr[length]; 07028 // if (amp > 0) amp =sqrtf(amp); 07029 // else amp = 0; 07030 } 07031 07032 if (sf[length] == 0) { 07033 d[idx1] = 0; 07034 continue; 07035 } 07036 07037 // size_t idx2 = idx1 + 1; 07038 // cout << d[idx1] << " " << sf[length] << endl; 07039 d[idx1] /= sf[length]; 07040 if (d[idx1] < 0) { 07041 d[idx1] *= amp; 07042 }else { 07043 d[idx1] *= -amp; 07044 } 07045 // d[idx2] = phase; 07046 07047 } 07048 } 07049 } 07050 07051 image->ap2ri(); 07052 if (image->get_ndim() != 1) image->process_inplace("xform.fourierorigin.tocorner"); 07053 image->do_ift_inplace(); 07054 image->depad(); 07055 }
const string CTFSNRWeightProcessor::NAME = "ctf.snr.weight" [static] |