#include <processor.h>
Inheritance diagram for EMAN::TestImageFourierNoiseProfile:
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 = "testimage.noise.fourier.profile" |
Definition at line 5941 of file processor.h.
virtual string EMAN::TestImageFourierNoiseProfile::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 5951 of file processor.h.
05952 { 05953 return "Replace a source image with Fourier noise using amplitude information that is stored in a profile."; 05954 }
virtual string EMAN::TestImageFourierNoiseProfile::get_name | ( | ) | const [inline, virtual] |
Get the processor's name.
Each processor is identified by a unique name.
Implements EMAN::Processor.
Definition at line 5946 of file processor.h.
References NAME.
05947 { 05948 return NAME; 05949 }
virtual TypeDict EMAN::TestImageFourierNoiseProfile::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 5961 of file processor.h.
References EMAN::EMObject::FLOATARRAY, and EMAN::TypeDict::put().
05962 { 05963 TypeDict d; 05964 d.put("profile", EMObject::FLOATARRAY, "The noise profile, squared amplitude. As in, what is the EMAN2CTF.background attribute"); 05965 return d; 05966 }
static Processor* EMAN::TestImageFourierNoiseProfile::NEW | ( | ) | [inline, static] |
Definition at line 5956 of file processor.h.
05957 { 05958 return new TestImageFourierNoiseProfile(); 05959 }
void TestImageFourierNoiseProfile::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 7072 of file processor.cpp.
References EMAN::EMData::ap2ri(), EMAN::EMData::depad(), EMAN::EMData::do_ift_inplace(), EMAN::EMData::get_data(), EMAN::Util::get_frand(), 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, phase(), EMAN::EMData::process_inplace(), EMAN::EMData::ri2ap(), EMAN::EMData::set_complex(), EMAN::EMData::set_fftodd(), EMAN::EMData::set_fftpad(), EMAN::EMData::set_size(), sqrt(), EMAN::EMData::to_zero(), and x.
07072 { 07073 07074 if (params.has_key("profile")==false) throw InvalidParameterException("You must supply the profile argument"); 07075 07076 if (!image->is_complex()) { 07077 int nx = image->get_xsize(); 07078 int offset = 2 - nx%2; 07079 07080 image->set_size(nx+offset,image->get_ysize(),image->get_zsize()); 07081 image->set_complex(true); 07082 if (1 == offset) image->set_fftodd(true); 07083 else image->set_fftodd(false); 07084 image->set_fftpad(true); 07085 } 07086 image->to_zero(); 07087 image->ri2ap(); 07088 07089 vector<float> profile = params["profile"]; 07090 transform(profile.begin(),profile.end(),profile.begin(),sqrtf); 07091 07092 int i = static_cast<int>(profile.size()); 07093 07094 float * d = image->get_data(); 07095 int nx = image->get_xsize(); 07096 int ny = image->get_ysize(); 07097 int nxy = image->get_ysize()*nx; 07098 int nzon2 = image->get_zsize()/2; 07099 int nyon2 = image->get_ysize()/2; 07100 float rx, ry, rz, amp, phase; 07101 int length; 07102 int twox; 07103 for (int z = 0; z< image->get_zsize(); ++z) { 07104 for (int y = 0; y < image->get_ysize(); ++y) { 07105 for (int x = 0; x < image->get_xsize()/2; ++x) { 07106 rx = (float)x; 07107 ry = (float)nyon2 - (float)y; 07108 rz = (float)nzon2 - (float)z; 07109 length = static_cast<int>(sqrt(rx*rx + ry*ry + rz*rz)); 07110 07111 twox = 2*x; 07112 size_t idx1 = twox + y*nx+(size_t)z*nxy; 07113 size_t idx2 = idx1 + 1; 07114 07115 07116 if (length >= i) { 07117 d[idx1] = 0; 07118 d[idx2] = 0; 07119 continue; 07120 } 07121 amp = profile[length]; 07122 phase = Util::get_frand(0,1)*2*M_PI; 07123 07124 07125 d[idx1] = amp; 07126 d[idx2] = phase; 07127 07128 } 07129 } 07130 } 07131 07132 image->ap2ri(); 07133 if (image->get_ndim() == 2) { 07134 bool yodd = image->get_ysize() % 2 == 1; 07135 07136 int yit = image->get_ysize()/2-1; 07137 int offset = 1; 07138 if (yodd) { 07139 offset = 0; 07140 } 07141 for (int y = 0; y < yit; ++y) { 07142 int bot_idx = (y+offset)*nx; 07143 int top_idx = (ny-1-y)*nx; 07144 float r1 = d[bot_idx]; 07145 float i1 = d[bot_idx+1]; 07146 float r2 = d[top_idx]; 07147 float i2 = d[top_idx+1]; 07148 float r = (r1 + r2)/2.0f; 07149 float i = (i1 + i2)/2.0f; 07150 d[bot_idx] = r; 07151 d[top_idx] = r; 07152 d[bot_idx+1] = i; 07153 d[top_idx+1] = -i; 07154 07155 bot_idx = (y+offset)*nx+nx-2; 07156 top_idx = (ny-1-y)*nx+nx-2; 07157 r1 = d[bot_idx]; 07158 i1 = d[bot_idx+1]; 07159 r2 = d[top_idx]; 07160 i2 = d[top_idx+1]; 07161 r = (r1 + r2)/2.0f; 07162 i = (i1 + i2)/2.0f; 07163 d[bot_idx] = r; 07164 d[top_idx] = r; 07165 d[bot_idx+1] = i; 07166 d[top_idx+1] = -i; 07167 } 07168 07169 d[1] = 0; // 0 phase for this componenet 07170 d[nx-1] = 0; // 0 phase for this component 07171 d[ny/2*nx+nx-1] = 0;// 0 phase for this component 07172 d[ny/2*nx+1] = 0;// 0 phase for this component 07173 } 07174 07175 if (image->get_ndim() != 1) image->process_inplace("xform.fourierorigin.tocorner"); 07176 image->do_ift_inplace(); 07177 image->depad(); 07178 }
const string TestImageFourierNoiseProfile::NAME = "testimage.noise.fourier.profile" [static] |