#include <processor.h>


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 TypeDict | get_param_types () const |
| Get processor parameter information in a dictionary. | |
| virtual string | get_desc () const |
| Get the descrition of this specific processor. | |
Static Public Member Functions | |
| static Processor * | NEW () |
Static Public Attributes | |
| static const string | NAME = "addspectralnoise" |
| n | ||
| x0 | ||
| dx | ||
| y | ||
| interpolation | ||
| seed | seed for random number generator |
Definition at line 4573 of file processor.h.
| void AddRandomNoiseProcessor::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 5351 of file processor.cpp.
References EMAN::EMData::ap2ri(), EMAN::Util::fast_floor(), EMAN::EMData::get_data(), EMAN::Randnum::get_frand(), EMAN::Randnum::get_gauss_rand(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), EMAN::Dict::has_key(), EMAN::Util::hypot3(), ImageFormatException, EMAN::Randnum::Instance(), EMAN::EMData::is_complex(), LOGERR, LOGWARN, EMAN::Processor::params, rdata, EMAN::Randnum::set_seed(), sqrt(), and EMAN::EMData::update().
05352 { 05353 if (!image) { 05354 LOGWARN("NULL Image"); 05355 return; 05356 } 05357 05358 if (!image->is_complex()) { 05359 LOGERR("AddRandomNoise Processor only works for complex image"); 05360 throw ImageFormatException("only work for complex image"); 05361 } 05362 05363 int n = params["n"]; 05364 float x0 = params["x0"]; 05365 float dx = params["dx"]; 05366 vector < float >y = params["y"]; 05367 05368 int interpolation = 1; 05369 if (params.has_key("interpolation")) { 05370 interpolation = params["interpolation"]; 05371 } 05372 05373 Randnum * randnum = Randnum::Instance(); 05374 if(params.has_key("seed")) { 05375 randnum->set_seed((int)params["seed"]); 05376 } 05377 05378 int nx = image->get_xsize(); 05379 int ny = image->get_ysize(); 05380 int nz = image->get_zsize(); 05381 05382 image->ap2ri(); 05383 float *rdata = image->get_data(); 05384 05385 size_t k = 0; 05386 float half_nz = 0; 05387 if (nz > 1) { 05388 half_nz = nz / 2.0f; 05389 } 05390 05391 const float sqrt_2 = sqrt((float) 2); 05392 05393 float r; 05394 for (int h = 0; h < nz; h++) { 05395 for (int j = 0; j < ny; j++) { 05396 for (int i = 0; i < nx; i += 2, k += 2) { 05397 r = (Util::hypot3(i / 2.0f, j - ny / 2.0f, h - half_nz)); 05398 // r = sqrt(Util::hypot3(i / 2.0f, j - ny / 2.0f, h - half_nz)); // I don't think this sqrt was supposed to be here --steve 05399 r = (r - x0) / dx; 05400 int l = 0; 05401 if (interpolation) { 05402 l = Util::fast_floor(r); 05403 } 05404 else { 05405 l = Util::fast_floor(r + 0.5f); 05406 } 05407 r -= l; 05408 float f = 0; 05409 if (l >= n - 2) { 05410 f = y[n - 1]; 05411 } 05412 else if (l < 0) { 05413 l = 0; 05414 } 05415 else { 05416 if (interpolation) { 05417 f = (y[l] * (1 - r) + y[l + 1] * r); 05418 } 05419 else { 05420 f = y[l]; 05421 } 05422 } 05423 f = randnum->get_gauss_rand(sqrt(f), sqrt(f) / 3); 05424 float a = randnum->get_frand(0.0f, (float)(2 * M_PI)); 05425 if (i == 0) { 05426 f *= sqrt_2; 05427 } 05428 rdata[k] += f * cos(a); 05429 rdata[k + 1] += f * sin(a); 05430 } 05431 } 05432 } 05433 05434 image->update(); 05435 }
| virtual string EMAN::AddRandomNoiseProcessor::get_name | ( | ) | const [inline, virtual] |
Get the processor's name.
Each processor is identified by a unique name.
Implements EMAN::Processor.
Definition at line 4578 of file processor.h.
References EMAN::NormalizeUnitSumProcessor::NAME.
04579 { 04580 return NAME; 04581 }
| static Processor* EMAN::AddRandomNoiseProcessor::NEW | ( | ) | [inline, static] |
Definition at line 4583 of file processor.h.
04584 { 04585 return new AddRandomNoiseProcessor(); 04586 }
| virtual TypeDict EMAN::AddRandomNoiseProcessor::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 4588 of file processor.h.
References EMAN::EMObject::FLOAT, EMAN::EMObject::FLOATARRAY, EMAN::EMObject::INT, and EMAN::TypeDict::put().
04589 { 04590 TypeDict d; 04591 d.put("n", EMObject::INT); 04592 d.put("x0", EMObject::FLOAT); 04593 d.put("dx", EMObject::FLOAT); 04594 d.put("y", EMObject::FLOATARRAY); 04595 d.put("interpolation", EMObject::INT); 04596 d.put("seed", EMObject::INT, "seed for random number generator"); 04597 return d; 04598 }
| virtual string EMAN::AddRandomNoiseProcessor::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 4600 of file processor.h.
const string AddRandomNoiseProcessor::NAME = "addspectralnoise" [static] |
Definition at line 4605 of file processor.h.
1.5.6