#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 = "addspectralnoise" |
| n | ||
| x0 | ||
| dx | ||
| y | ||
| interpolation | ||
| seed | seed for random number generator |
Definition at line 4599 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 4626 of file processor.h. 04627 {
04628 return "add spectral noise to a complex image.";
04629 }
|
|
|
Get the processor's name. Each processor is identified by a unique name.
Implements EMAN::Processor. Definition at line 4604 of file processor.h. 04605 {
04606 return NAME;
04607 }
|
|
|
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 4614 of file processor.h. References EMAN::TypeDict::put(). 04615 {
04616 TypeDict d;
04617 d.put("n", EMObject::INT);
04618 d.put("x0", EMObject::FLOAT);
04619 d.put("dx", EMObject::FLOAT);
04620 d.put("y", EMObject::FLOATARRAY);
04621 d.put("interpolation", EMObject::INT);
04622 d.put("seed", EMObject::INT, "seed for random number generator");
04623 return d;
04624 }
|
|
|
Definition at line 4609 of file processor.h. 04610 {
04611 return new AddRandomNoiseProcessor();
04612 }
|
|
|
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 5385 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. 05386 {
05387 if (!image) {
05388 LOGWARN("NULL Image");
05389 return;
05390 }
05391
05392 if (!image->is_complex()) {
05393 LOGERR("AddRandomNoise Processor only works for complex image");
05394 throw ImageFormatException("only work for complex image");
05395 }
05396
05397 int n = params["n"];
05398 float x0 = params["x0"];
05399 float dx = params["dx"];
05400 vector < float >y = params["y"];
05401
05402 int interpolation = 1;
05403 if (params.has_key("interpolation")) {
05404 interpolation = params["interpolation"];
05405 }
05406
05407 Randnum * randnum = Randnum::Instance();
05408 if(params.has_key("seed")) {
05409 randnum->set_seed((int)params["seed"]);
05410 }
05411
05412 int nx = image->get_xsize();
05413 int ny = image->get_ysize();
05414 int nz = image->get_zsize();
05415
05416 image->ap2ri();
05417 float *rdata = image->get_data();
05418
05419 size_t k = 0;
05420 float half_nz = 0;
05421 if (nz > 1) {
05422 half_nz = nz / 2.0f;
05423 }
05424
05425 const float sqrt_2 = sqrt((float) 2);
05426
05427 float r;
05428 for (int h = 0; h < nz; h++) {
05429 for (int j = 0; j < ny; j++) {
05430 for (int i = 0; i < nx; i += 2, k += 2) {
05431 r = (Util::hypot3(i / 2.0f, j - ny / 2.0f, h - half_nz));
05432 // 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
05433 r = (r - x0) / dx;
05434 int l = 0;
05435 if (interpolation) {
05436 l = Util::fast_floor(r);
05437 }
05438 else {
05439 l = Util::fast_floor(r + 0.5f);
05440 }
05441 r -= l;
05442 float f = 0;
05443 if (l >= n - 2) {
05444 f = y[n - 1];
05445 }
05446 else if (l < 0) {
05447 l = 0;
05448 }
05449 else {
05450 if (interpolation) {
05451 f = (y[l] * (1 - r) + y[l + 1] * r);
05452 }
05453 else {
05454 f = y[l];
05455 }
05456 }
05457 f = randnum->get_gauss_rand(sqrt(f), sqrt(f) / 3);
05458 float a = randnum->get_frand(0.0f, (float)(2 * M_PI));
05459 if (i == 0) {
05460 f *= sqrt_2;
05461 }
05462 rdata[k] += f * cos(a);
05463 rdata[k + 1] += f * sin(a);
05464 }
05465 }
05466 }
05467
05468 image->update();
05469 }
|
|
|
Definition at line 160 of file processor.cpp. |
1.3.9.1