#include <processor.h>
Inheritance diagram for EMAN::AddRandomNoiseProcessor:
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 = "math.addspectralnoise" |
n | ||
x0 | ||
dx | ||
y | ||
interpolation | ||
seed | seed for random number generator |
Definition at line 4668 of file processor.h.
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 4695 of file processor.h.
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 4673 of file processor.h.
References NAME.
04674 { 04675 return NAME; 04676 }
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 4683 of file processor.h.
References EMAN::EMObject::FLOAT, EMAN::EMObject::FLOATARRAY, EMAN::EMObject::INT, and EMAN::TypeDict::put().
04684 { 04685 TypeDict d; 04686 d.put("n", EMObject::INT); 04687 d.put("x0", EMObject::FLOAT); 04688 d.put("dx", EMObject::FLOAT); 04689 d.put("y", EMObject::FLOATARRAY); 04690 d.put("interpolation", EMObject::INT); 04691 d.put("seed", EMObject::INT, "seed for random number generator"); 04692 return d; 04693 }
static Processor* EMAN::AddRandomNoiseProcessor::NEW | ( | ) | [inline, static] |
Definition at line 4678 of file processor.h.
04679 { 04680 return new AddRandomNoiseProcessor(); 04681 }
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 5499 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().
05500 { 05501 if (!image) { 05502 LOGWARN("NULL Image"); 05503 return; 05504 } 05505 05506 if (!image->is_complex()) { 05507 LOGERR("AddRandomNoise Processor only works for complex image"); 05508 throw ImageFormatException("only work for complex image"); 05509 } 05510 05511 int n = params["n"]; 05512 float x0 = params["x0"]; 05513 float dx = params["dx"]; 05514 vector < float >y = params["y"]; 05515 05516 int interpolation = 1; 05517 if (params.has_key("interpolation")) { 05518 interpolation = params["interpolation"]; 05519 } 05520 05521 Randnum * randnum = Randnum::Instance(); 05522 if(params.has_key("seed")) { 05523 randnum->set_seed((int)params["seed"]); 05524 } 05525 05526 int nx = image->get_xsize(); 05527 int ny = image->get_ysize(); 05528 int nz = image->get_zsize(); 05529 05530 image->ap2ri(); 05531 float *rdata = image->get_data(); 05532 05533 size_t k = 0; 05534 float half_nz = 0; 05535 if (nz > 1) { 05536 half_nz = nz / 2.0f; 05537 } 05538 05539 const float sqrt_2 = sqrt((float) 2); 05540 05541 float r; 05542 for (int h = 0; h < nz; h++) { 05543 for (int j = 0; j < ny; j++) { 05544 for (int i = 0; i < nx; i += 2, k += 2) { 05545 r = (Util::hypot3(i / 2.0f, j - ny / 2.0f, h - half_nz)); 05546 // 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 05547 r = (r - x0) / dx; 05548 int l = 0; 05549 if (interpolation) { 05550 l = Util::fast_floor(r); 05551 } 05552 else { 05553 l = Util::fast_floor(r + 0.5f); 05554 } 05555 r -= l; 05556 float f = 0; 05557 if (l >= n - 2) { 05558 f = y[n - 1]; 05559 } 05560 else if (l < 0) { 05561 l = 0; 05562 } 05563 else { 05564 if (interpolation) { 05565 f = (y[l] * (1 - r) + y[l + 1] * r); 05566 } 05567 else { 05568 f = y[l]; 05569 } 05570 } 05571 f = randnum->get_gauss_rand(sqrt(f), sqrt(f) / 3); 05572 float a = randnum->get_frand(0.0f, (float)(2 * M_PI)); 05573 if (i == 0) { 05574 f *= sqrt_2; 05575 } 05576 rdata[k] += f * cos(a); 05577 rdata[k + 1] += f * sin(a); 05578 } 05579 } 05580 } 05581 05582 image->update(); 05583 }
const string AddRandomNoiseProcessor::NAME = "math.addspectralnoise" [static] |