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 ()

Static Public Attributes

static const string NAME = "math.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 4713 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 4740 of file processor.h.

04741                 {
04742                         return "add spectral noise to a complex image.";
04743                 }

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

References NAME.

04719                 {
04720                         return NAME;
04721                 }

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

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

04729                 {
04730                         TypeDict d;
04731                         d.put("n", EMObject::INT);
04732                         d.put("x0", EMObject::FLOAT);
04733                         d.put("dx", EMObject::FLOAT);
04734                         d.put("y", EMObject::FLOATARRAY);
04735                         d.put("interpolation", EMObject::INT);
04736                         d.put("seed", EMObject::INT, "seed for random number generator");
04737                         return d;
04738                 }

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

Definition at line 4723 of file processor.h.

04724                 {
04725                         return new AddRandomNoiseProcessor();
04726                 }

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 5575 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().

05576 {
05577         if (!image) {
05578                 LOGWARN("NULL Image");
05579                 return;
05580         }
05581 
05582         if (!image->is_complex()) {
05583                 LOGERR("AddRandomNoise Processor only works for complex image");
05584                 throw ImageFormatException("only work for complex image");
05585         }
05586 
05587         int n = params["n"];
05588         float x0 = params["x0"];
05589         float dx = params["dx"];
05590         vector < float >y = params["y"];
05591 
05592         int interpolation = 1;
05593         if (params.has_key("interpolation")) {
05594                 interpolation = params["interpolation"];
05595         }
05596 
05597         Randnum * randnum = Randnum::Instance();
05598         if(params.has_key("seed")) {
05599                 randnum->set_seed((int)params["seed"]);
05600         }
05601 
05602         int nx = image->get_xsize();
05603         int ny = image->get_ysize();
05604         int nz = image->get_zsize();
05605 
05606         image->ap2ri();
05607         float *rdata = image->get_data();
05608 
05609         size_t k = 0;
05610         float half_nz = 0;
05611         if (nz > 1) {
05612                 half_nz = nz / 2.0f;
05613         }
05614 
05615         const float sqrt_2 = sqrt((float) 2);
05616 
05617         float r;
05618         for (int h = 0; h < nz; h++) {
05619                 for (int j = 0; j < ny; j++) {
05620                         for (int i = 0; i < nx; i += 2, k += 2) {
05621                                 r = (Util::hypot3(i / 2.0f, j - ny / 2.0f, h - half_nz));
05622 //                              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
05623                                 r = (r - x0) / dx;
05624                                 int l = 0;
05625                                 if (interpolation) {
05626                                         l = Util::fast_floor(r);
05627                                 }
05628                                 else {
05629                                         l = Util::fast_floor(r + 0.5f);
05630                                 }
05631                                 r -= l;
05632                                 float f = 0;
05633                                 if (l >= n - 2) {
05634                                         f = y[n - 1];
05635                                 }
05636                                 else if (l < 0) {
05637                                         l = 0;
05638                                 }
05639                                 else {
05640                                         if (interpolation) {
05641                                                 f = (y[l] * (1 - r) + y[l + 1] * r);
05642                                         }
05643                                         else {
05644                                                 f = y[l];
05645                                         }
05646                                 }
05647                                 f = randnum->get_gauss_rand(sqrt(f), sqrt(f) / 3);
05648                                 float a = randnum->get_frand(0.0f, (float)(2 * M_PI));
05649                                 if (i == 0) {
05650                                         f *= sqrt_2;
05651                                 }
05652                                 rdata[k] += f * cos(a);
05653                                 rdata[k + 1] += f * sin(a);
05654                         }
05655                 }
05656         }
05657 
05658         image->update();
05659 }


Member Data Documentation

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

Definition at line 4745 of file processor.h.

Referenced by get_name().


The documentation for this class was generated from the following files:
Generated on Fri Aug 10 16:36:25 2012 for EMAN2 by  doxygen 1.4.7