Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

EMAN::AddRandomNoiseProcessor Class Reference

add spectral noise to a complex image More...

#include <processor.h>

Inheritance diagram for EMAN::AddRandomNoiseProcessor:

[legend]
Collaboration diagram for EMAN::AddRandomNoiseProcessor:
[legend]
List of all members.

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

ProcessorNEW ()

Static Public Attributes

const string NAME = "addspectralnoise"

Detailed Description

add spectral noise to a complex image

Parameters:
n 
x0 
dx 
y 
interpolation 
seed seed for random number generator

Definition at line 4633 of file processor.h.


Member Function Documentation

virtual string EMAN::AddRandomNoiseProcessor::get_desc  )  const [inline, virtual]
 

Get the descrition of this specific processor.

This function must be overwritten by a subclass.

Returns:
The description of this processor.

Implements EMAN::Processor.

Definition at line 4660 of file processor.h.

04661                 {
04662                         return "add spectral noise to a complex image.";
04663                 }

virtual string EMAN::AddRandomNoiseProcessor::get_name  )  const [inline, virtual]
 

Get the processor's name.

Each processor is identified by a unique name.

Returns:
The processor's name.

Implements EMAN::Processor.

Definition at line 4638 of file processor.h.

04639                 {
04640                         return NAME;
04641                 }

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.

Returns:
A dictionary containing the parameter info.

Reimplemented from EMAN::Processor.

Definition at line 4648 of file processor.h.

References EMAN::TypeDict::put().

04649                 {
04650                         TypeDict d;
04651                         d.put("n", EMObject::INT);
04652                         d.put("x0", EMObject::FLOAT);
04653                         d.put("dx", EMObject::FLOAT);
04654                         d.put("y", EMObject::FLOATARRAY);
04655                         d.put("interpolation", EMObject::INT);
04656                         d.put("seed", EMObject::INT, "seed for random number generator");
04657                         return d;
04658                 }

Processor* EMAN::AddRandomNoiseProcessor::NEW  )  [inline, static]
 

Definition at line 4643 of file processor.h.

04644                 {
04645                         return new AddRandomNoiseProcessor();
04646                 }

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.

Parameters:
image The image to be processed.

Implements EMAN::Processor.

Definition at line 5324 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.

05325 {
05326         if (!image) {
05327                 LOGWARN("NULL Image");
05328                 return;
05329         }
05330 
05331         if (!image->is_complex()) {
05332                 LOGERR("AddRandomNoise Processor only works for complex image");
05333                 throw ImageFormatException("only work for complex image");
05334         }
05335 
05336         int n = params["n"];
05337         float x0 = params["x0"];
05338         float dx = params["dx"];
05339         vector < float >y = params["y"];
05340 
05341         int interpolation = 1;
05342         if (params.has_key("interpolation")) {
05343                 interpolation = params["interpolation"];
05344         }
05345 
05346         Randnum * randnum = Randnum::Instance();
05347         if(params.has_key("seed")) {
05348                 randnum->set_seed((int)params["seed"]);
05349         }
05350 
05351         int nx = image->get_xsize();
05352         int ny = image->get_ysize();
05353         int nz = image->get_zsize();
05354 
05355         image->ap2ri();
05356         float *rdata = image->get_data();
05357 
05358         size_t k = 0;
05359         float half_nz = 0;
05360         if (nz > 1) {
05361                 half_nz = nz / 2.0f;
05362         }
05363 
05364         const float sqrt_2 = sqrt((float) 2);
05365 
05366         float r;
05367         for (int h = 0; h < nz; h++) {
05368                 for (int j = 0; j < ny; j++) {
05369                         for (int i = 0; i < nx; i += 2, k += 2) {
05370                                 r = (Util::hypot3(i / 2.0f, j - ny / 2.0f, h - half_nz));
05371 //                              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
05372                                 r = (r - x0) / dx;
05373                                 int l = 0;
05374                                 if (interpolation) {
05375                                         l = Util::fast_floor(r);
05376                                 }
05377                                 else {
05378                                         l = Util::fast_floor(r + 0.5f);
05379                                 }
05380                                 r -= l;
05381                                 float f = 0;
05382                                 if (l >= n - 2) {
05383                                         f = y[n - 1];
05384                                 }
05385                                 else if (l < 0) {
05386                                         l = 0;
05387                                 }
05388                                 else {
05389                                         if (interpolation) {
05390                                                 f = (y[l] * (1 - r) + y[l + 1] * r);
05391                                         }
05392                                         else {
05393                                                 f = y[l];
05394                                         }
05395                                 }
05396                                 f = randnum->get_gauss_rand(sqrt(f), sqrt(f) / 3);
05397                                 float a = randnum->get_frand(0.0f, (float)(2 * M_PI));
05398                                 if (i == 0) {
05399                                         f *= sqrt_2;
05400                                 }
05401                                 rdata[k] += f * cos(a);
05402                                 rdata[k + 1] += f * sin(a);
05403                         }
05404                 }
05405         }
05406 
05407         image->update();
05408 }


Member Data Documentation

const string AddRandomNoiseProcessor::NAME = "addspectralnoise" [static]
 

Definition at line 160 of file processor.cpp.


The documentation for this class was generated from the following files:
Generated on Fri Apr 30 15:39:25 2010 for EMAN2 by  doxygen 1.3.9.1