#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 | |
Processor * | NEW () |
Static Public Attributes | |
const string | NAME = "math.addspectralnoise" |
n | ||
x0 | ||
dx | ||
y | ||
interpolation | ||
seed | seed for random number generator |
Definition at line 4715 of file processor.h.
|
Get the descrition of this specific processor. This function must be overwritten by a subclass.
Implements EMAN::Processor. Definition at line 4742 of file processor.h. 04743 { 04744 return "add spectral noise to a complex image."; 04745 }
|
|
Get the processor's name. Each processor is identified by a unique name.
Implements EMAN::Processor. Definition at line 4720 of file processor.h. 04721 {
04722 return NAME;
04723 }
|
|
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 4730 of file processor.h. References EMAN::TypeDict::put(). 04731 { 04732 TypeDict d; 04733 d.put("n", EMObject::INT); 04734 d.put("x0", EMObject::FLOAT); 04735 d.put("dx", EMObject::FLOAT); 04736 d.put("y", EMObject::FLOATARRAY); 04737 d.put("interpolation", EMObject::INT); 04738 d.put("seed", EMObject::INT, "seed for random number generator"); 04739 return d; 04740 }
|
|
Definition at line 4725 of file processor.h. 04726 { 04727 return new AddRandomNoiseProcessor(); 04728 }
|
|
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.
Implements EMAN::Processor. Definition at line 5577 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, nx, ny, rdata, EMAN::Randnum::set_seed(), sqrt(), EMAN::EMData::update(), and y. 05578 { 05579 if (!image) { 05580 LOGWARN("NULL Image"); 05581 return; 05582 } 05583 05584 if (!image->is_complex()) { 05585 LOGERR("AddRandomNoise Processor only works for complex image"); 05586 throw ImageFormatException("only work for complex image"); 05587 } 05588 05589 int n = params["n"]; 05590 float x0 = params["x0"]; 05591 float dx = params["dx"]; 05592 vector < float >y = params["y"]; 05593 05594 int interpolation = 1; 05595 if (params.has_key("interpolation")) { 05596 interpolation = params["interpolation"]; 05597 } 05598 05599 Randnum * randnum = Randnum::Instance(); 05600 if(params.has_key("seed")) { 05601 randnum->set_seed((int)params["seed"]); 05602 } 05603 05604 int nx = image->get_xsize(); 05605 int ny = image->get_ysize(); 05606 int nz = image->get_zsize(); 05607 05608 image->ap2ri(); 05609 float *rdata = image->get_data(); 05610 05611 size_t k = 0; 05612 float half_nz = 0; 05613 if (nz > 1) { 05614 half_nz = nz / 2.0f; 05615 } 05616 05617 const float sqrt_2 = sqrt((float) 2); 05618 05619 float r; 05620 for (int h = 0; h < nz; h++) { 05621 for (int j = 0; j < ny; j++) { 05622 for (int i = 0; i < nx; i += 2, k += 2) { 05623 r = (Util::hypot3(i / 2.0f, j - ny / 2.0f, h - half_nz)); 05624 // 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 05625 r = (r - x0) / dx; 05626 int l = 0; 05627 if (interpolation) { 05628 l = Util::fast_floor(r); 05629 } 05630 else { 05631 l = Util::fast_floor(r + 0.5f); 05632 } 05633 r -= l; 05634 float f = 0; 05635 if (l >= n - 2) { 05636 f = y[n - 1]; 05637 } 05638 else if (l < 0) { 05639 l = 0; 05640 } 05641 else { 05642 if (interpolation) { 05643 f = (y[l] * (1 - r) + y[l + 1] * r); 05644 } 05645 else { 05646 f = y[l]; 05647 } 05648 } 05649 f = randnum->get_gauss_rand(sqrt(f), sqrt(f) / 3); 05650 float a = randnum->get_frand(0.0f, (float)(2 * M_PI)); 05651 if (i == 0) { 05652 f *= sqrt_2; 05653 } 05654 rdata[k] += f * cos(a); 05655 rdata[k + 1] += f * sin(a); 05656 } 05657 } 05658 } 05659 05660 image->update(); 05661 }
|
|
Definition at line 161 of file processor.cpp. |