EMAN2
Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
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]

Public Member Functions

virtual void process_inplace (EMData *image)
 To process an image in-place. More...
 
virtual string get_name () const
 Get the processor's name. More...
 
virtual TypeDict get_param_types () const
 Get processor parameter information in a dictionary. More...
 
virtual string get_desc () const
 Get the descrition of this specific processor. More...
 
- Public Member Functions inherited from EMAN::Processor
virtual ~Processor ()
 
virtual EMDataprocess (const EMData *const image)
 To proccess an image out-of-place. More...
 
virtual void process_list_inplace (vector< EMData * > &images)
 To process multiple images using the same algorithm. More...
 
virtual Dict get_params () const
 Get the processor parameters in a key/value dictionary. More...
 
virtual void set_params (const Dict &new_params)
 Set the processor parameters using a key/value dictionary. More...
 

Static Public Member Functions

static ProcessorNEW ()
 
- Static Public Member Functions inherited from EMAN::Processor
static string get_group_desc ()
 Get the description of this group of processors. More...
 
static void EMFourierFilterInPlace (EMData *fimage, Dict params)
 Compute a Fourier-filter processed image in place. More...
 
static EMDataEMFourierFilter (EMData *fimage, Dict params)
 Compute a Fourier-processor processed image without altering the original image. More...
 

Static Public Attributes

static const string NAME = "math.addspectralnoise"
 

Additional Inherited Members

- Public Types inherited from EMAN::Processor
enum  fourier_filter_types {
  TOP_HAT_LOW_PASS , TOP_HAT_HIGH_PASS , TOP_HAT_BAND_PASS , TOP_HOMOMORPHIC ,
  GAUSS_LOW_PASS , GAUSS_HIGH_PASS , GAUSS_BAND_PASS , GAUSS_INVERSE ,
  GAUSS_HOMOMORPHIC , BUTTERWORTH_LOW_PASS , BUTTERWORTH_HIGH_PASS , BUTTERWORTH_HOMOMORPHIC ,
  KAISER_I0 , KAISER_SINH , KAISER_I0_INVERSE , KAISER_SINH_INVERSE ,
  SHIFT , TANH_LOW_PASS , TANH_HIGH_PASS , TANH_HOMOMORPHIC ,
  TANH_BAND_PASS , RADIAL_TABLE , CTF_
}
 Fourier filter Processor type enum. More...
 
- Protected Attributes inherited from EMAN::Processor
Dict params
 

Detailed Description

add spectral noise to a complex image

Parameters
n
x0
dx
y
interpolation
seedseed for random number generator

Definition at line 6563 of file processor.h.

Member Function Documentation

◆ get_desc()

virtual string EMAN::AddRandomNoiseProcessor::get_desc ( ) const
inlinevirtual

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

6591 {
6592 return "add spectral noise to a complex image.";
6593 }

◆ get_name()

virtual string EMAN::AddRandomNoiseProcessor::get_name ( ) const
inlinevirtual

Get the processor's name.

Each processor is identified by a unique name.

Returns
The processor's name.

Implements EMAN::Processor.

Definition at line 6568 of file processor.h.

6569 {
6570 return NAME;
6571 }
static const string NAME
Definition: processor.h:6595

References NAME.

◆ get_param_types()

virtual TypeDict EMAN::AddRandomNoiseProcessor::get_param_types ( ) const
inlinevirtual

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

6579 {
6580 TypeDict d;
6581 d.put("n", EMObject::INT);
6582 d.put("x0", EMObject::FLOAT);
6583 d.put("dx", EMObject::FLOAT);
6584 d.put("y", EMObject::FLOATARRAY);
6585 d.put("interpolation", EMObject::INT);
6586 d.put("seed", EMObject::INT, "seed for random number generator");
6587 return d;
6588 }
TypeDict is a dictionary to store <string, EMObject::ObjectType> pair.
Definition: emobject.h:305
void put(const string &key, EMObject::ObjectType o, const string &desc="")
Definition: emobject.h:330

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

◆ NEW()

static Processor * EMAN::AddRandomNoiseProcessor::NEW ( )
inlinestatic

Definition at line 6573 of file processor.h.

6574 {
6575 return new AddRandomNoiseProcessor();
6576 }
add spectral noise to a complex image
Definition: processor.h:6564

◆ process_inplace()

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
imageThe image to be processed.

Implements EMAN::Processor.

Definition at line 7010 of file processor.cpp.

7011{
7012 if (!image) {
7013 LOGWARN("NULL Image");
7014 return;
7015 }
7016
7017 if (!image->is_complex()) {
7018 LOGERR("AddRandomNoise Processor only works for complex image");
7019 throw ImageFormatException("only work for complex image");
7020 }
7021
7022 int n = params["n"];
7023 float x0 = params["x0"];
7024 float dx = params["dx"];
7025 vector < float >y = params["y"];
7026
7027 int interpolation = 1;
7028 if (params.has_key("interpolation")) {
7029 interpolation = params["interpolation"];
7030 }
7031
7032 Randnum * randnum = Randnum::Instance();
7033 if(params.has_key("seed")) {
7034 randnum->set_seed((int)params["seed"]);
7035 }
7036
7037 int nx = image->get_xsize();
7038 int ny = image->get_ysize();
7039 int nz = image->get_zsize();
7040
7041 image->ap2ri();
7042 float *rdata = image->get_data();
7043
7044 size_t k = 0;
7045 float half_nz = 0;
7046 if (nz > 1) {
7047 half_nz = nz / 2.0f;
7048 }
7049
7050 const float sqrt_2 = sqrt((float) 2);
7051
7052 float r;
7053 for (int h = 0; h < nz; h++) {
7054 for (int j = 0; j < ny; j++) {
7055 for (int i = 0; i < nx; i += 2, k += 2) {
7056 r = (Util::hypot3(i / 2.0f, j - ny / 2.0f, h - half_nz));
7057// 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
7058 r = (r - x0) / dx;
7059 int l = 0;
7060 if (interpolation) {
7061 l = Util::fast_floor(r);
7062 }
7063 else {
7064 l = Util::fast_floor(r + 0.5f);
7065 }
7066 r -= l;
7067 float f = 0;
7068 if (l >= n - 2) {
7069 f = y[n - 1];
7070 }
7071 else if (l < 0) {
7072 l = 0;
7073 }
7074 else {
7075 if (interpolation) {
7076 f = (y[l] * (1 - r) + y[l + 1] * r);
7077 }
7078 else {
7079 f = y[l];
7080 }
7081 }
7082 f = randnum->get_gauss_rand(sqrt(f), sqrt(f) / 3);
7083 float a = randnum->get_frand(0.0f, (float)(2 * M_PI));
7084 if (i == 0) {
7085 f *= sqrt_2;
7086 }
7087 rdata[k] += f * cos(a);
7088 rdata[k + 1] += f * sin(a);
7089 }
7090 }
7091 }
7092
7093 image->update();
7094}
#define rdata(i)
Definition: analyzer.cpp:592
bool has_key(const string &key) const
Ask the Dictionary if it as a particular key.
Definition: emobject.h:511
The wrapper class for gsl's random number generater.
Definition: randnum.h:86
void set_seed(unsigned long long seed)
Set the seed for the random number generator.
Definition: randnum.cpp:142
static Randnum * Instance()
Definition: randnum.cpp:104
float get_gauss_rand(float mean, float sigma) const
Return a Gaussian random number.
Definition: randnum.cpp:168
float get_frand(double lo=0.0, double hi=1.0) const
This function returns a random float from lo inclusive to hi.
Definition: randnum.cpp:158
static int fast_floor(float x)
A fast way to calculate a floor, which is largest integral value not greater than argument.
Definition: util.h:874
static float hypot3(int x, int y, int z)
Euclidean distance function in 3D: f(x,y,z) = sqrt(x*x + y*y + z*z);.
Definition: util.h:827
EMData * sqrt() const
return square root of current image
#define ImageFormatException(desc)
Definition: exception.h:147
#define LOGWARN
Definition: log.h:53
#define LOGERR
Definition: log.h:51
#define y(i, j)
Definition: projector.cpp:1516

References EMAN::Util::fast_floor(), EMAN::Randnum::get_frand(), EMAN::Randnum::get_gauss_rand(), EMAN::Dict::has_key(), EMAN::Util::hypot3(), ImageFormatException, EMAN::Randnum::Instance(), LOGERR, LOGWARN, EMAN::Processor::params, rdata, EMAN::Randnum::set_seed(), sqrt(), and y.

Member Data Documentation

◆ NAME

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

Definition at line 6595 of file processor.h.

Referenced by get_name().


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