EMAN2
Public Member Functions | Static Public Member Functions | Static Public Attributes
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
seedseed for random number generator

Definition at line 4968 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 4995 of file processor.h.

                {
                        return "add spectral noise to a complex image.";
                }
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 4973 of file processor.h.

References NAME.

                {
                        return NAME;
                }
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 4983 of file processor.h.

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

                {
                        TypeDict d;
                        d.put("n", EMObject::INT);
                        d.put("x0", EMObject::FLOAT);
                        d.put("dx", EMObject::FLOAT);
                        d.put("y", EMObject::FLOATARRAY);
                        d.put("interpolation", EMObject::INT);
                        d.put("seed", EMObject::INT, "seed for random number generator");
                        return d;
                }
static Processor* EMAN::AddRandomNoiseProcessor::NEW ( ) [inline, static]

Definition at line 4978 of file processor.h.

                {
                        return new AddRandomNoiseProcessor();
                }
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 5791 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, EMAN::Processor::params, rdata, EMAN::Randnum::set_seed(), sqrt(), and EMAN::EMData::update().

{
        if (!image) {
                LOGWARN("NULL Image");
                return;
        }

        if (!image->is_complex()) {
                LOGERR("AddRandomNoise Processor only works for complex image");
                throw ImageFormatException("only work for complex image");
        }

        int n = params["n"];
        float x0 = params["x0"];
        float dx = params["dx"];
        vector < float >y = params["y"];

        int interpolation = 1;
        if (params.has_key("interpolation")) {
                interpolation = params["interpolation"];
        }

        Randnum * randnum = Randnum::Instance();
        if(params.has_key("seed")) {
                randnum->set_seed((int)params["seed"]);
        }

        int nx = image->get_xsize();
        int ny = image->get_ysize();
        int nz = image->get_zsize();

        image->ap2ri();
        float *rdata = image->get_data();

        size_t k = 0;
        float half_nz = 0;
        if (nz > 1) {
                half_nz = nz / 2.0f;
        }

        const float sqrt_2 = sqrt((float) 2);

        float r;
        for (int h = 0; h < nz; h++) {
                for (int j = 0; j < ny; j++) {
                        for (int i = 0; i < nx; i += 2, k += 2) {
                                r = (Util::hypot3(i / 2.0f, j - ny / 2.0f, h - half_nz));
//                              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
                                r = (r - x0) / dx;
                                int l = 0;
                                if (interpolation) {
                                        l = Util::fast_floor(r);
                                }
                                else {
                                        l = Util::fast_floor(r + 0.5f);
                                }
                                r -= l;
                                float f = 0;
                                if (l >= n - 2) {
                                        f = y[n - 1];
                                }
                                else if (l < 0) {
                                        l = 0;
                                }
                                else {
                                        if (interpolation) {
                                                f = (y[l] * (1 - r) + y[l + 1] * r);
                                        }
                                        else {
                                                f = y[l];
                                        }
                                }
                                f = randnum->get_gauss_rand(sqrt(f), sqrt(f) / 3);
                                float a = randnum->get_frand(0.0f, (float)(2 * M_PI));
                                if (i == 0) {
                                        f *= sqrt_2;
                                }
                                rdata[k] += f * cos(a);
                                rdata[k + 1] += f * sin(a);
                        }
                }
        }

        image->update();
}

Member Data Documentation

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

Definition at line 5000 of file processor.h.

Referenced by get_name().


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