#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 5980 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 5990 of file processor.h.
05991 { 05992 return "Replace a source image with Fourier noise using amplitude information that is stored in a profile."; 05993 }
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 5985 of file processor.h.
References NAME.
05986 { 05987 return NAME; 05988 }
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 6000 of file processor.h.
References EMAN::EMObject::FLOATARRAY, and EMAN::TypeDict::put().
06001 { 06002 TypeDict d; 06003 d.put("profile", EMObject::FLOATARRAY, "The noise profile, squared amplitude. As in, what is the EMAN2CTF.background attribute"); 06004 return d; 06005 }
static Processor* EMAN::TestImageFourierNoiseProfile::NEW | ( | ) | [inline, static] |
Definition at line 5995 of file processor.h.
05996 { 05997 return new TestImageFourierNoiseProfile(); 05998 }
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 7137 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.
07137 { 07138 07139 if (params.has_key("profile")==false) throw InvalidParameterException("You must supply the profile argument"); 07140 07141 if (!image->is_complex()) { 07142 int nx = image->get_xsize(); 07143 int offset = 2 - nx%2; 07144 07145 image->set_size(nx+offset,image->get_ysize(),image->get_zsize()); 07146 image->set_complex(true); 07147 if (1 == offset) image->set_fftodd(true); 07148 else image->set_fftodd(false); 07149 image->set_fftpad(true); 07150 } 07151 image->to_zero(); 07152 image->ri2ap(); 07153 07154 vector<float> profile = params["profile"]; 07155 transform(profile.begin(),profile.end(),profile.begin(),sqrtf); 07156 07157 int i = static_cast<int>(profile.size()); 07158 07159 float * d = image->get_data(); 07160 int nx = image->get_xsize(); 07161 int ny = image->get_ysize(); 07162 int nxy = image->get_ysize()*nx; 07163 int nzon2 = image->get_zsize()/2; 07164 int nyon2 = image->get_ysize()/2; 07165 float rx, ry, rz, amp, phase; 07166 int length; 07167 int twox; 07168 for (int z = 0; z< image->get_zsize(); ++z) { 07169 for (int y = 0; y < image->get_ysize(); ++y) { 07170 for (int x = 0; x < image->get_xsize()/2; ++x) { 07171 rx = (float)x; 07172 ry = (float)nyon2 - (float)y; 07173 rz = (float)nzon2 - (float)z; 07174 length = static_cast<int>(sqrt(rx*rx + ry*ry + rz*rz)); 07175 07176 twox = 2*x; 07177 size_t idx1 = twox + y*nx+(size_t)z*nxy; 07178 size_t idx2 = idx1 + 1; 07179 07180 07181 if (length >= i) { 07182 d[idx1] = 0; 07183 d[idx2] = 0; 07184 continue; 07185 } 07186 amp = profile[length]; 07187 phase = Util::get_frand(0,1)*2*M_PI; 07188 07189 07190 d[idx1] = amp; 07191 d[idx2] = phase; 07192 07193 } 07194 } 07195 } 07196 07197 image->ap2ri(); 07198 if (image->get_ndim() == 2) { 07199 bool yodd = image->get_ysize() % 2 == 1; 07200 07201 int yit = image->get_ysize()/2-1; 07202 int offset = 1; 07203 if (yodd) { 07204 offset = 0; 07205 } 07206 for (int y = 0; y < yit; ++y) { 07207 int bot_idx = (y+offset)*nx; 07208 int top_idx = (ny-1-y)*nx; 07209 float r1 = d[bot_idx]; 07210 float i1 = d[bot_idx+1]; 07211 float r2 = d[top_idx]; 07212 float i2 = d[top_idx+1]; 07213 float r = (r1 + r2)/2.0f; 07214 float i = (i1 + i2)/2.0f; 07215 d[bot_idx] = r; 07216 d[top_idx] = r; 07217 d[bot_idx+1] = i; 07218 d[top_idx+1] = -i; 07219 07220 bot_idx = (y+offset)*nx+nx-2; 07221 top_idx = (ny-1-y)*nx+nx-2; 07222 r1 = d[bot_idx]; 07223 i1 = d[bot_idx+1]; 07224 r2 = d[top_idx]; 07225 i2 = d[top_idx+1]; 07226 r = (r1 + r2)/2.0f; 07227 i = (i1 + i2)/2.0f; 07228 d[bot_idx] = r; 07229 d[top_idx] = r; 07230 d[bot_idx+1] = i; 07231 d[top_idx+1] = -i; 07232 } 07233 07234 d[1] = 0; // 0 phase for this componenet 07235 d[nx-1] = 0; // 0 phase for this component 07236 d[ny/2*nx+nx-1] = 0;// 0 phase for this component 07237 d[ny/2*nx+1] = 0;// 0 phase for this component 07238 } 07239 07240 if (image->get_ndim() != 1) image->process_inplace("xform.fourierorigin.tocorner"); 07241 image->do_ift_inplace(); 07242 image->depad(); 07243 }
const string TestImageFourierNoiseProfile::NAME = "testimage.noise.fourier.profile" [static] |