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

Try to eliminate beamstop in electron diffraction patterns. More...

#include <processor.h>

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

List of all members.

Public Member Functions

void process_inplace (EMData *image)
 To process an image in-place.
string get_name () const
 Get the processor's name.
string get_desc () const
 Get the descrition of this specific processor.
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 = "mask.beamstop"

Detailed Description

Try to eliminate beamstop in electron diffraction patterns.

If value1<0 also does radial subtract.

Parameters:
value1sig multiplier
value2x of center
value3y of center

Definition at line 4066 of file processor.h.


Member Function Documentation

string EMAN::BeamstopProcessor::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 4081 of file processor.h.

                {
                        return "Try to eliminate beamstop in electron diffraction patterns. value1=sig multiplier; value2,value3 are x,y of center, if value1<0 also does radial subtract.";
                }
string EMAN::BeamstopProcessor::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 4071 of file processor.h.

References NAME.

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

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

                {
                        TypeDict d;
                        d.put("value1", EMObject::FLOAT, "sig multiplier");
                        d.put("value2", EMObject::FLOAT, "x of center");
                        d.put("value3", EMObject::FLOAT, "y of center");
                        return d;
                }
static Processor* EMAN::BeamstopProcessor::NEW ( ) [inline, static]

Definition at line 4076 of file processor.h.

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

References EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), ImageDimensionException, LOGERR, LOGWARN, nx, ny, EMAN::Processor::params, EMAN::Util::round(), sqrt(), and EMAN::EMData::update().

{
        if (!image) {
                LOGWARN("NULL Image");
                return;
        }
        if (image->get_zsize() > 1) {
                LOGERR("BeamstopProcessor doesn't support 3D model");
                throw ImageDimensionException("3D model not supported");
        }

        float value1 = params["value1"];
        float value2 = params["value2"];
        float value3 = params["value3"];

        float thr = fabs(value1);
        float *data = image->get_data();
        int cenx = (int) value2;
        int ceny = (int) value3;

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

        if (cenx <= 0) {
                cenx = nx / 2;
        }

        if (ceny <= 0) {
                ceny = ny / 2;
        }

        int mxr = (int) floor(sqrt(2.0f) * nx / 2);

        float *mean_values = new float[mxr];
        float *sigma_values = new float[mxr];
        double sum = 0;
        int count = 0;
        double square_sum = 0;

        for (int i = 0; i < mxr; i++) {
                sum = 0;
                count = 0;
                square_sum = 0;
                int nitems = 6 * i + 2;

                for (int j = 0; j < nitems; j++) {
                        float ang = j * 2 * M_PI / nitems;
                        int x0 = (int) floor(cos(ang) * i + cenx);
                        int y0 = (int) floor(sin(ang) * i + ceny);

                        if (x0 < 0 || y0 < 0 || x0 >= nx || y0 >= ny) {
                                continue;
                        }

                        float f = data[x0 + y0 * nx];
                        sum += f;
                        square_sum += f * f;
                        count++;
                }

                mean_values[i] = (float)sum / count;
                sigma_values[i] = (float) sqrt(square_sum / count - mean_values[i] * mean_values[i]);
        }


        for (int k = 0; k < 5; k++) {
                for (int i = 0; i < mxr; i++) {
                        sum = 0;
                        count = 0;
                        square_sum = 0;
                        int nitems = 6 * i + 2;
                        double thr1 = mean_values[i] - sigma_values[i] * thr;
                        double thr2 = mean_values[i] + sigma_values[i];

                        for (int j = 0; j < nitems; j++) {
                                float ang = j * 2 * M_PI / nitems;
                                int x0 = (int) floor(cos(ang) * i + cenx);
                                int y0 = (int) floor(sin(ang) * i + ceny);

                                if (x0 < 0 || y0 < 0 || x0 >= nx || y0 >= ny ||
                                        data[x0 + y0 * nx] < thr1 || data[x0 + y0 * nx] > thr2) {
                                        continue;
                                }

                                sum += data[x0 + y0 * nx];
                                square_sum += data[x0 + y0 * nx] * data[x0 + y0 * nx];
                                count++;
                        }

                        mean_values[i] = (float) sum / count;
                        sigma_values[i] = (float) sqrt(square_sum / count - mean_values[i] * mean_values[i]);
                }
        }

        for (int i = 0; i < nx; i++) {
                for (int j = 0; j < ny; j++) {

#ifdef  _WIN32
                        int r = Util::round(_hypot((float) i - cenx, (float) j - ceny));
#else
                        int r = Util::round(hypot((float) i - cenx, (float) j - ceny));
#endif  //_WIN32

                        if (value1 < 0) {
                                if (data[i + j * nx] < (mean_values[r] - sigma_values[r] * thr)) {
                                        data[i + j * nx] = 0;
                                }
                                else {
                                        data[i + j * nx] -= mean_values[r];
                                }
                                continue;
                        }
                        if (data[i + j * nx] > (mean_values[r] - sigma_values[r] * thr)) {
                                continue;
                        }
                        data[i + j * nx] = mean_values[r];
                }
        }

        if( mean_values )
        {
                delete[]mean_values;
                mean_values = 0;
        }

        if( sigma_values )
        {
                delete[]sigma_values;
                sigma_values = 0;
        }

        image->update();
}

Member Data Documentation

const string BeamstopProcessor::NAME = "mask.beamstop" [static]

Definition at line 4095 of file processor.h.

Referenced by get_name().


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