#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 4458 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 4485 of file processor.h. 04486 { 04487 return "add spectral noise to a complex image."; 04488 }
|
|
Get the processor's name. Each processor is identified by a unique name.
Implements EMAN::Processor. Definition at line 4463 of file processor.h. 04464 {
04465 return NAME;
04466 }
|
|
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 4473 of file processor.h. References EMAN::TypeDict::put(). 04474 { 04475 TypeDict d; 04476 d.put("n", EMObject::INT); 04477 d.put("x0", EMObject::FLOAT); 04478 d.put("dx", EMObject::FLOAT); 04479 d.put("y", EMObject::FLOATARRAY); 04480 d.put("interpolation", EMObject::INT); 04481 d.put("seed", EMObject::INT, "seed for random number generator"); 04482 return d; 04483 }
|
|
Definition at line 4468 of file processor.h. 04469 { 04470 return new AddRandomNoiseProcessor(); 04471 }
|
|
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 5323 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. 05324 { 05325 if (!image) { 05326 LOGWARN("NULL Image"); 05327 return; 05328 } 05329 05330 if (!image->is_complex()) { 05331 LOGERR("AddRandomNoise Processor only works for complex image"); 05332 throw ImageFormatException("only work for complex image"); 05333 } 05334 05335 int n = params["n"]; 05336 float x0 = params["x0"]; 05337 float dx = params["dx"]; 05338 vector < float >y = params["y"]; 05339 05340 int interpolation = 1; 05341 if (params.has_key("interpolation")) { 05342 interpolation = params["interpolation"]; 05343 } 05344 05345 Randnum * randnum = Randnum::Instance(); 05346 if(params.has_key("seed")) { 05347 randnum->set_seed((int)params["seed"]); 05348 } 05349 05350 int nx = image->get_xsize(); 05351 int ny = image->get_ysize(); 05352 int nz = image->get_zsize(); 05353 05354 image->ap2ri(); 05355 float *rdata = image->get_data(); 05356 05357 size_t k = 0; 05358 float half_nz = 0; 05359 if (nz > 1) { 05360 half_nz = nz / 2.0f; 05361 } 05362 05363 const float sqrt_2 = sqrt((float) 2); 05364 05365 float r; 05366 for (int h = 0; h < nz; h++) { 05367 for (int j = 0; j < ny; j++) { 05368 for (int i = 0; i < nx; i += 2, k += 2) { 05369 r = (Util::hypot3(i / 2.0f, j - ny / 2.0f, h - half_nz)); 05370 // 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 05371 r = (r - x0) / dx; 05372 int l = 0; 05373 if (interpolation) { 05374 l = Util::fast_floor(r); 05375 } 05376 else { 05377 l = Util::fast_floor(r + 0.5f); 05378 } 05379 r -= l; 05380 float f = 0; 05381 if (l >= n - 2) { 05382 f = y[n - 1]; 05383 } 05384 else if (l < 0) { 05385 l = 0; 05386 } 05387 else { 05388 if (interpolation) { 05389 f = (y[l] * (1 - r) + y[l + 1] * r); 05390 } 05391 else { 05392 f = y[l]; 05393 } 05394 } 05395 f = randnum->get_gauss_rand(sqrt(f), sqrt(f) / 3); 05396 float a = randnum->get_frand(0.0f, (float)(2 * M_PI)); 05397 if (i == 0) { 05398 f *= sqrt_2; 05399 } 05400 rdata[k] += f * cos(a); 05401 rdata[k + 1] += f * sin(a); 05402 } 05403 } 05404 } 05405 05406 image->update(); 05407 }
|
|
Definition at line 155 of file processor.cpp. |