EMAN::AddRandomNoiseProcessor Class Reference

add spectral noise to a complex image More...

#include <processor.h>

Inheritance diagram for EMAN::AddRandomNoiseProcessor:

Inheritance graph
[legend]
Collaboration diagram for EMAN::AddRandomNoiseProcessor:

Collaboration graph
[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

static ProcessorNEW ()


Detailed Description

add spectral noise to a complex image

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

Definition at line 4341 of file processor.h.


Member Function Documentation

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 4981 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, EMAN::Processor::params, rdata, EMAN::Randnum::set_seed(), sqrt(), and EMAN::EMData::update().

04982 {
04983         if (!image) {
04984                 LOGWARN("NULL Image");
04985                 return;
04986         }
04987 
04988         if (!image->is_complex()) {
04989                 LOGERR("AddRandomNoise Processor only works for complex image");
04990                 throw ImageFormatException("only work for complex image");
04991         }
04992 
04993         int n = params["n"];
04994         float x0 = params["x0"];
04995         float dx = params["dx"];
04996         vector < float >y = params["y"];
04997 
04998         int interpolation = 1;
04999         if (params.has_key("interpolation")) {
05000                 interpolation = params["interpolation"];
05001         }
05002 
05003         Randnum * randnum = Randnum::Instance();
05004         if(params.has_key("seed")) {
05005                 randnum->set_seed((int)params["seed"]);
05006         }
05007 
05008         int nx = image->get_xsize();
05009         int ny = image->get_ysize();
05010         int nz = image->get_zsize();
05011 
05012         image->ap2ri();
05013         float *rdata = image->get_data();
05014 
05015         size_t k = 0;
05016         float half_nz = 0;
05017         if (nz > 1) {
05018                 half_nz = nz / 2.0f;
05019         }
05020 
05021         const float sqrt_2 = sqrt((float) 2);
05022 
05023         float r;
05024         for (int h = 0; h < nz; h++) {
05025                 for (int j = 0; j < ny; j++) {
05026                         for (int i = 0; i < nx; i += 2, k += 2) {
05027                                 r = sqrt(Util::hypot3(i / 2.0f, j - ny / 2.0f, h - half_nz));
05028                                 r = (r - x0) / dx;
05029                                 int l = 0;
05030                                 if (interpolation) {
05031                                         l = Util::fast_floor(r);
05032                                 }
05033                                 else {
05034                                         l = Util::fast_floor(r + 0.5f);
05035                                 }
05036                                 r -= l;
05037                                 float f = 0;
05038                                 if (l >= n - 2) {
05039                                         f = y[n - 1];
05040                                 }
05041                                 else if (l < 0) {
05042                                         l = 0;
05043                                 }
05044                                 else {
05045                                         if (interpolation) {
05046                                                 f = (y[l] * (1 - r) + y[l + 1] * r);
05047                                         }
05048                                         else {
05049                                                 f = y[l];
05050                                         }
05051                                 }
05052                                 f = randnum->get_gauss_rand(sqrt(f), sqrt(f) / 3);
05053                                 float a = randnum->get_frand(0.0f, (float)(2 * M_PI));
05054                                 if (i == 0) {
05055                                         f *= sqrt_2;
05056                                 }
05057                                 rdata[k] += f * cos(a);
05058                                 rdata[k + 1] += f * sin(a);
05059                         }
05060                 }
05061         }
05062 
05063         image->update();
05064 }

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 4346 of file processor.h.

04347                 {
04348                         return "addspectralnoise";
04349                 }

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

Definition at line 4351 of file processor.h.

04352                 {
04353                         return new AddRandomNoiseProcessor();
04354                 }

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 4356 of file processor.h.

References EMAN::EMObject::FLOAT, EMAN::EMObject::FLOATARRAY, EMAN::EMObject::INT, and EMAN::TypeDict::put().

04357                 {
04358                         TypeDict d;
04359                         d.put("n", EMObject::INT);
04360                         d.put("x0", EMObject::FLOAT);
04361                         d.put("dx", EMObject::FLOAT);
04362                         d.put("y", EMObject::FLOATARRAY);
04363                         d.put("interpolation", EMObject::INT);
04364                         d.put("seed", EMObject::INT, "seed for random number generator");
04365                         return d;
04366                 }

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 4368 of file processor.h.

04369                 {
04370                         return "add spectral noise to a complex image.";
04371                 }


The documentation for this class was generated from the following files:

Generated on Sat Nov 21 02:20:33 2009 for EMAN2 by  doxygen 1.5.6