#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 4543 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 4570 of file processor.h. 04571 { 04572 return "add spectral noise to a complex image."; 04573 }
|
|
Get the processor's name. Each processor is identified by a unique name.
Implements EMAN::Processor. Definition at line 4548 of file processor.h. 04549 {
04550 return NAME;
04551 }
|
|
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 4558 of file processor.h. References EMAN::TypeDict::put(). 04559 { 04560 TypeDict d; 04561 d.put("n", EMObject::INT); 04562 d.put("x0", EMObject::FLOAT); 04563 d.put("dx", EMObject::FLOAT); 04564 d.put("y", EMObject::FLOATARRAY); 04565 d.put("interpolation", EMObject::INT); 04566 d.put("seed", EMObject::INT, "seed for random number generator"); 04567 return d; 04568 }
|
|
Definition at line 4553 of file processor.h. 04554 { 04555 return new AddRandomNoiseProcessor(); 04556 }
|
|
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 5387 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. 05388 { 05389 if (!image) { 05390 LOGWARN("NULL Image"); 05391 return; 05392 } 05393 05394 if (!image->is_complex()) { 05395 LOGERR("AddRandomNoise Processor only works for complex image"); 05396 throw ImageFormatException("only work for complex image"); 05397 } 05398 05399 int n = params["n"]; 05400 float x0 = params["x0"]; 05401 float dx = params["dx"]; 05402 vector < float >y = params["y"]; 05403 05404 int interpolation = 1; 05405 if (params.has_key("interpolation")) { 05406 interpolation = params["interpolation"]; 05407 } 05408 05409 Randnum * randnum = Randnum::Instance(); 05410 if(params.has_key("seed")) { 05411 randnum->set_seed((int)params["seed"]); 05412 } 05413 05414 int nx = image->get_xsize(); 05415 int ny = image->get_ysize(); 05416 int nz = image->get_zsize(); 05417 05418 image->ap2ri(); 05419 float *rdata = image->get_data(); 05420 05421 size_t k = 0; 05422 float half_nz = 0; 05423 if (nz > 1) { 05424 half_nz = nz / 2.0f; 05425 } 05426 05427 const float sqrt_2 = sqrt((float) 2); 05428 05429 float r; 05430 for (int h = 0; h < nz; h++) { 05431 for (int j = 0; j < ny; j++) { 05432 for (int i = 0; i < nx; i += 2, k += 2) { 05433 r = (Util::hypot3(i / 2.0f, j - ny / 2.0f, h - half_nz)); 05434 // 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 05435 r = (r - x0) / dx; 05436 int l = 0; 05437 if (interpolation) { 05438 l = Util::fast_floor(r); 05439 } 05440 else { 05441 l = Util::fast_floor(r + 0.5f); 05442 } 05443 r -= l; 05444 float f = 0; 05445 if (l >= n - 2) { 05446 f = y[n - 1]; 05447 } 05448 else if (l < 0) { 05449 l = 0; 05450 } 05451 else { 05452 if (interpolation) { 05453 f = (y[l] * (1 - r) + y[l + 1] * r); 05454 } 05455 else { 05456 f = y[l]; 05457 } 05458 } 05459 f = randnum->get_gauss_rand(sqrt(f), sqrt(f) / 3); 05460 float a = randnum->get_frand(0.0f, (float)(2 * M_PI)); 05461 if (i == 0) { 05462 f *= sqrt_2; 05463 } 05464 rdata[k] += f * cos(a); 05465 rdata[k + 1] += f * sin(a); 05466 } 05467 } 05468 } 05469 05470 image->update(); 05471 }
|
|
Definition at line 158 of file processor.cpp. |