#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 5939 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 5949 of file processor.h.
05950 { 05951 return "Replace a source image with Fourier noise using amplitude information that is stored in a profile."; 05952 }
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 5944 of file processor.h.
References NAME.
05945 { 05946 return NAME; 05947 }
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 5959 of file processor.h.
References EMAN::EMObject::FLOATARRAY, and EMAN::TypeDict::put().
05960 { 05961 TypeDict d; 05962 d.put("profile", EMObject::FLOATARRAY, "The noise profile, squared amplitude. As in, what is the EMAN2CTF.background attribute"); 05963 return d; 05964 }
static Processor* EMAN::TestImageFourierNoiseProfile::NEW | ( | ) | [inline, static] |
Definition at line 5954 of file processor.h.
05955 { 05956 return new TestImageFourierNoiseProfile(); 05957 }
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 7057 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.
07057 { 07058 07059 if (params.has_key("profile")==false) throw InvalidParameterException("You must supply the profile argument"); 07060 07061 if (!image->is_complex()) { 07062 int nx = image->get_xsize(); 07063 int offset = 2 - nx%2; 07064 07065 image->set_size(nx+offset,image->get_ysize(),image->get_zsize()); 07066 image->set_complex(true); 07067 if (1 == offset) image->set_fftodd(true); 07068 else image->set_fftodd(false); 07069 image->set_fftpad(true); 07070 } 07071 image->to_zero(); 07072 image->ri2ap(); 07073 07074 vector<float> profile = params["profile"]; 07075 transform(profile.begin(),profile.end(),profile.begin(),sqrtf); 07076 07077 int i = static_cast<int>(profile.size()); 07078 07079 float * d = image->get_data(); 07080 int nx = image->get_xsize(); 07081 int ny = image->get_ysize(); 07082 int nxy = image->get_ysize()*nx; 07083 int nzon2 = image->get_zsize()/2; 07084 int nyon2 = image->get_ysize()/2; 07085 float rx, ry, rz, amp, phase; 07086 int length; 07087 int twox; 07088 for (int z = 0; z< image->get_zsize(); ++z) { 07089 for (int y = 0; y < image->get_ysize(); ++y) { 07090 for (int x = 0; x < image->get_xsize()/2; ++x) { 07091 rx = (float)x; 07092 ry = (float)nyon2 - (float)y; 07093 rz = (float)nzon2 - (float)z; 07094 length = static_cast<int>(sqrt(rx*rx + ry*ry + rz*rz)); 07095 07096 twox = 2*x; 07097 size_t idx1 = twox + y*nx+(size_t)z*nxy; 07098 size_t idx2 = idx1 + 1; 07099 07100 07101 if (length >= i) { 07102 d[idx1] = 0; 07103 d[idx2] = 0; 07104 continue; 07105 } 07106 amp = profile[length]; 07107 phase = Util::get_frand(0,1)*2*M_PI; 07108 07109 07110 d[idx1] = amp; 07111 d[idx2] = phase; 07112 07113 } 07114 } 07115 } 07116 07117 image->ap2ri(); 07118 if (image->get_ndim() == 2) { 07119 bool yodd = image->get_ysize() % 2 == 1; 07120 07121 int yit = image->get_ysize()/2-1; 07122 int offset = 1; 07123 if (yodd) { 07124 offset = 0; 07125 } 07126 for (int y = 0; y < yit; ++y) { 07127 int bot_idx = (y+offset)*nx; 07128 int top_idx = (ny-1-y)*nx; 07129 float r1 = d[bot_idx]; 07130 float i1 = d[bot_idx+1]; 07131 float r2 = d[top_idx]; 07132 float i2 = d[top_idx+1]; 07133 float r = (r1 + r2)/2.0f; 07134 float i = (i1 + i2)/2.0f; 07135 d[bot_idx] = r; 07136 d[top_idx] = r; 07137 d[bot_idx+1] = i; 07138 d[top_idx+1] = -i; 07139 07140 bot_idx = (y+offset)*nx+nx-2; 07141 top_idx = (ny-1-y)*nx+nx-2; 07142 r1 = d[bot_idx]; 07143 i1 = d[bot_idx+1]; 07144 r2 = d[top_idx]; 07145 i2 = d[top_idx+1]; 07146 r = (r1 + r2)/2.0f; 07147 i = (i1 + i2)/2.0f; 07148 d[bot_idx] = r; 07149 d[top_idx] = r; 07150 d[bot_idx+1] = i; 07151 d[top_idx+1] = -i; 07152 } 07153 07154 d[1] = 0; // 0 phase for this componenet 07155 d[nx-1] = 0; // 0 phase for this component 07156 d[ny/2*nx+nx-1] = 0;// 0 phase for this component 07157 d[ny/2*nx+1] = 0;// 0 phase for this component 07158 } 07159 07160 if (image->get_ndim() != 1) image->process_inplace("xform.fourierorigin.tocorner"); 07161 image->do_ift_inplace(); 07162 image->depad(); 07163 }
const string TestImageFourierNoiseProfile::NAME = "testimage.noise.fourier.profile" [static] |