EMAN2
Public Member Functions | Static Public Member Functions | Static Public Attributes
EMAN::TestImageFourierNoiseProfile Class Reference

#include <processor.h>

Inheritance diagram for EMAN::TestImageFourierNoiseProfile:
Inheritance graph
[legend]
Collaboration diagram for EMAN::TestImageFourierNoiseProfile:
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 string get_desc () const
 Get the descrition of this specific processor.
virtual TypeDict get_param_types () const
 Get processor parameter information in a dictionary.

Static Public Member Functions

static ProcessorNEW ()

Static Public Attributes

static const string NAME = "testimage.noise.fourier.profile"

Detailed Description

Author:
David Woolford
Date:
June 15th 2009

Definition at line 6352 of file processor.h.


Member Function Documentation

virtual string EMAN::TestImageFourierNoiseProfile::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 6362 of file processor.h.

                {
                        return "Replace a source image with Fourier noise using amplitude information that is stored in a profile.";
                }
virtual string EMAN::TestImageFourierNoiseProfile::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 6357 of file processor.h.

References NAME.

                {
                        return NAME;
                }
virtual TypeDict EMAN::TestImageFourierNoiseProfile::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 6372 of file processor.h.

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

                {
                        TypeDict d;
                        d.put("profile", EMObject::FLOATARRAY, "The noise profile, squared amplitude. As in, what is the EMAN2CTF.background attribute");
                        return d;
                }
static Processor* EMAN::TestImageFourierNoiseProfile::NEW ( ) [inline, static]

Definition at line 6367 of file processor.h.

                {
                        return new TestImageFourierNoiseProfile();
                }
void TestImageFourierNoiseProfile::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 7575 of file processor.cpp.

References EMAN::EMData::ap2ri(), EMAN::EMData::depad(), EMAN::EMData::do_ift_inplace(), EMAN::EMData::get_data(), EMAN::Util::get_frand(), EMAN::EMData::get_ndim(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), EMAN::Dict::has_key(), InvalidParameterException, EMAN::EMData::is_complex(), EMAN::length(), nx, EMAN::Processor::params, phase(), EMAN::EMData::process_inplace(), EMAN::EMData::ri2ap(), EMAN::EMData::set_complex(), EMAN::EMData::set_fftodd(), EMAN::EMData::set_fftpad(), EMAN::EMData::set_size(), sqrt(), EMAN::EMData::to_zero(), x, and y.

                                                                 {

        if (params.has_key("profile")==false) throw InvalidParameterException("You must supply the profile argument");

        if (!image->is_complex()) {
                int nx = image->get_xsize();
                int offset = 2 - nx%2;

                image->set_size(nx+offset,image->get_ysize(),image->get_zsize());
                image->set_complex(true);
                if (1 == offset) image->set_fftodd(true);
                else image->set_fftodd(false);
                image->set_fftpad(true);
        }
        image->to_zero();
        image->ri2ap();

        vector<float> profile = params["profile"];
        transform(profile.begin(),profile.end(),profile.begin(),sqrtf);

        int i = static_cast<int>(profile.size());

        float * d = image->get_data();
        int nx = image->get_xsize();
        int ny = image->get_ysize();
        int nxy = image->get_ysize()*nx;
        int nzon2 = image->get_zsize()/2;
        int nyon2 = image->get_ysize()/2;
        float rx, ry, rz, amp, phase;
        int length;
        int twox;
        for (int z = 0; z< image->get_zsize(); ++z) {
                for (int y = 0; y < image->get_ysize(); ++y) {
                        for (int x = 0; x < image->get_xsize()/2; ++x) {
                                rx = (float)x;
                                ry = (float)nyon2 - (float)y;
                                rz = (float)nzon2 - (float)z;
                                length = static_cast<int>(sqrt(rx*rx + ry*ry + rz*rz));

                                twox = 2*x;
                                size_t idx1 = twox + y*nx+(size_t)z*nxy;
                                size_t idx2 = idx1 + 1;


                                if (length >= i) {
                                        d[idx1] = 0;
                                        d[idx2] = 0;
                                        continue;
                                }
                                amp = profile[length];
                                phase = Util::get_frand(0,1)*2*M_PI;


                                d[idx1] = amp;
                                d[idx2] = phase;

                        }
                }
        }

        image->ap2ri();
        if (image->get_ndim() == 2) {
                bool yodd = image->get_ysize() % 2 == 1;

                int yit = image->get_ysize()/2-1;
                int offset = 1;
                if (yodd) {
                        offset = 0;
                }
                for (int y = 0; y < yit; ++y) {
                        int bot_idx = (y+offset)*nx;
                        int top_idx = (ny-1-y)*nx;
                        float r1 = d[bot_idx];
                        float i1 = d[bot_idx+1];
                        float r2 = d[top_idx];
                        float i2 = d[top_idx+1];
                        float r = (r1 + r2)/2.0f;
                        float i = (i1 + i2)/2.0f;
                        d[bot_idx] = r;
                        d[top_idx] = r;
                        d[bot_idx+1] = i;
                        d[top_idx+1] = -i;

                        bot_idx = (y+offset)*nx+nx-2;
                        top_idx = (ny-1-y)*nx+nx-2;
                        r1 = d[bot_idx];
                        i1 = d[bot_idx+1];
                        r2 = d[top_idx];
                        i2 = d[top_idx+1];
                        r = (r1 + r2)/2.0f;
                        i = (i1 + i2)/2.0f;
                        d[bot_idx] = r;
                        d[top_idx] = r;
                        d[bot_idx+1] = i;
                        d[top_idx+1] = -i;
                }

                d[1] = 0; // 0 phase for this componenet
                d[nx-1] = 0; // 0 phase for this component
                d[ny/2*nx+nx-1] = 0;// 0 phase for this component
                d[ny/2*nx+1] = 0;// 0 phase for this component
        }

        if (image->get_ndim() != 1) image->process_inplace("xform.fourierorigin.tocorner");
        image->do_ift_inplace();
        image->depad();
}

Member Data Documentation

const string TestImageFourierNoiseProfile::NAME = "testimage.noise.fourier.profile" [static]

Definition at line 6379 of file processor.h.

Referenced by get_name().


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